- Timestamp:
- Nov 29, 2013 12:16:43 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/pjsua2/pjsip-apps/src/pygui/application.py
r4664 r4665 35 35 import buddy 36 36 import endpoint 37 import settings 37 38 38 39 import os 39 40 import traceback 40 41 41 class SipTransportConfig:42 def __init__(self):43 #pj.PersistentObject.__init__(self)44 self.type = pj.PJSIP_TRANSPORT_UNSPECIFIED;45 self.cfg = pj.TransportConfig()46 47 def readObject(self, node):48 child_node = node.readContainer("SipTransportConfig")49 self.type = child_node.readInt("type")50 self.cfg.readObject(child_node)51 52 def writeObject(self, node):53 child_node = node.writeNewContainer("SipTransportConfig")54 child_node.writeInt("type", self.type)55 self.cfg.writeObject(child_node)56 57 42 58 43 class Application(ttk.Frame): … … 88 73 89 74 # Default config 90 self.epCfg = pj.EpConfig() 91 self.epCfg.uaConfig.threadCnt = 0; 92 self.epCfg.logConfig.writer = self.logger 93 self.epCfg.logConfig.filename = "pygui.log" 94 self.epCfg.logConfig.fileFlags = pj.PJ_O_APPEND 95 self.epCfg.logConfig.level = 5 96 self.epCfg.logConfig.consoleLevel = 5 97 98 self.transportCfgs = [] 99 t = SipTransportConfig() 100 t.type = pj.PJSIP_TRANSPORT_UDP 101 t.cfg.port = 0 102 self.transportCfgs.append(t) 103 t = SipTransportConfig() 104 t.type = pj.PJSIP_TRANSPORT_TCP 105 t.cfg.port = 0 106 self.transportCfgs.append(t) 107 108 75 self.appConfig = settings.AppConfig() 76 self.appConfig.epConfig.uaConfig.threadCnt = 0; 77 self.appConfig.epConfig.logConfig.writer = self.logger 78 self.appConfig.epConfig.logConfig.filename = "pygui.log" 79 self.appConfig.epConfig.logConfig.fileFlags = pj.PJ_O_APPEND 80 self.appConfig.epConfig.logConfig.level = 5 81 self.appConfig.epConfig.logConfig.consoleLevel = 5 82 109 83 def saveConfig(self, filename='pygui.js'): 110 json = pj.JsonDocument() 111 112 # Write endpoint config 113 json.writeObject(self.epCfg) 114 115 # Write transport config 116 node = json.writeNewArray("transports") 117 for t in self.transportCfgs: 118 t.writeObject(node); 119 120 # Write account configs 121 node = json.writeNewArray("accounts") 84 # Save disabled accounts since they are not listed in self.accList 85 disabled_accs = [ac for ac in self.appConfig.accounts if not ac.enabled] 86 self.appConfig.accounts = [] 87 88 # Get account configs from active accounts 122 89 for acc in self.accList: 123 acc_node = node.writeNewContainer("Account") 124 acc_node.writeObject(acc.cfg); 125 126 # Write buddy configs 127 buddy_node = acc_node.writeNewArray("buddies") 90 acfg = settings.AccConfig() 91 acfg.enabled = True 92 acfg.config = acc.cfg 128 93 for bud in acc.buddyList: 129 buddy_node.writeObject(bud.cfg) 130 131 json.saveFile(filename) 94 acfg.buddyConfigs.append(bud.cfg) 95 self.appConfig.accounts.append(acfg) 96 97 # Put back disabled accounts 98 self.appConfig.accounts.extend(disabled_accs) 99 # Save 100 self.appConfig.saveFile(filename) 132 101 133 102 def start(self, cfg_file='pygui.js'): 134 103 # Load config 135 acc_cfgs = []136 104 if cfg_file and os.path.exists(cfg_file): 137 json = pj.JsonDocument() 138 json.loadFile(cfg_file) 139 140 # Load endpoint config 141 json.readObject(self.epCfg) 142 143 # Load transport configs 144 node = json.readArray("transports") 145 if node.hasUnread(): 146 self.transportCfgs = [] 147 while node.hasUnread(): 148 t = SipTransportConfig() 149 t.readObject(node) 150 self.transportCfgs.append(t) 151 152 # Load account configs 153 node = json.readArray("accounts") 154 while node.hasUnread(): 155 acc_node = node.readContainer("Account") 156 acc_cfg = pj.AccountConfig() 157 acc_cfg.readObject(acc_node) 158 159 # Load buddy configs 160 buddy_cfgs = [] 161 buddy_node = acc_node.readArray("buddies") 162 while buddy_node.hasUnread(): 163 buddy_cfg = pj.BuddyConfig() 164 buddy_cfg.readObject(buddy_node) 165 buddy_cfgs.append(buddy_cfg) 166 167 acc_cfgs.append((acc_cfg, buddy_cfgs)) 168 105 self.appConfig.loadFile(cfg_file) 106 107 self.appConfig.epConfig.uaConfig.threadCnt = 0; 108 self.appConfig.epConfig.logConfig.writer = self.logger 109 self.appConfig.epConfig.logConfig.level = 5 110 self.appConfig.epConfig.logConfig.consoleLevel = 5 169 111 170 112 # Initialize library 171 self. epCfg.uaConfig.userAgent = "pygui-" + self.ep.libVersion().full;172 self.ep.libInit(self. epCfg)113 self.appConfig.epConfig.uaConfig.userAgent = "pygui-" + self.ep.libVersion().full; 114 self.ep.libInit(self.appConfig.epConfig) 173 115 self.master.title('pjsua2 Demo version ' + self.ep.libVersion().full) 174 116 175 117 # Create transports 176 for t in self.transportCfgs: 177 self.ep.transportCreate(t.type, t.cfg) 118 if self.appConfig.udp.enabled: 119 self.ep.transportCreate(self.appConfig.udp.type, self.appConfig.udp.config) 120 if self.appConfig.tcp.enabled: 121 self.ep.transportCreate(self.appConfig.tcp.type, self.appConfig.tcp.config) 122 if self.appConfig.tls.enabled: 123 self.ep.transportCreate(self.appConfig.tls.type, self.appConfig.tls.config) 178 124 179 125 # Add accounts 180 for cfg, buddy_cfgs in acc_cfgs: 181 self._createAcc(cfg) 182 acc = self.accList[-1] 183 for buddy_cfg in buddy_cfgs: 184 self._createBuddy(acc, buddy_cfg) 126 for cfg in self.appConfig.accounts: 127 if cfg.enabled: 128 self._createAcc(cfg.config) 129 acc = self.accList[-1] 130 for buddy_cfg in cfg.buddyConfigs: 131 self._createBuddy(acc, buddy_cfg) 185 132 186 133 # Start library … … 294 241 self.buddyMenu = tk.Menu(top, tearoff=False) 295 242 labels = ['Video call', 'Audio call', 'Send instant message', '-', 243 'Subscribe', 'Unsubscribe', '-', 296 244 'Settings...', '-', 297 245 'Delete...'] … … 420 368 elif label=='Send instant message': 421 369 pass 370 elif label=='Subscribe': 371 bud.subscribePresence(True) 372 elif label=='Unsubscribe': 373 bud.subscribePresence(False) 422 374 elif label=='Settings...': 423 375 subs = bud.cfg.subscribe … … 477 429 478 430 def _onMenuSettings(self): 479 msgbox.showinfo(self.master.title(), 'Settings') 431 dlg = settings.Dialog(self, self.appConfig) 432 if dlg.doModal(): 433 msgbox.showinfo(self.master.title(), 'You need to restart for new settings to take effect') 480 434 481 435 def _onMenuSaveSettings(self):
Note: See TracChangeset
for help on using the changeset viewer.