- Timestamp:
- Dec 4, 2013 2:46:42 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/pjsua2/pjsip-apps/src/pygui/account.py
r4663 r4671 35 35 import application 36 36 import call 37 import chat as ch 37 38 38 39 # Account class … … 48 49 self.cfgChanged = False 49 50 self.buddyList = [] 50 self.callList = [] 51 51 self.chatList = [] 52 53 def findBuddy(self, uri): 54 # TODO: proper URI comparison 55 for bud in self.buddyList: 56 if bud.cfg.uri in uri or uri in bud.cfg.uri: 57 return bud 58 return None 59 60 def findChat(self, buddy, call_inst = None): 61 for chat in self.chatList: 62 if chat.isBuddyParticipant(buddy): 63 if call_inst and chat.isCallRegistered(call_inst): 64 return chat 65 elif not call_inst and chat.isPrivate(): 66 return chat 67 return None 68 69 def newChat(self, buddy): 70 chat = ch.Chat(self, buddy) 71 self.chatList.append(chat) 72 return chat 73 52 74 def statusText(self): 53 75 status = '?' … … 75 97 status = '- not created -' 76 98 return status 77 78 def makeCall(self): 79 mycall = call.Call(self.app, self, pj.PJSUA_INVALID_ID) 80 callPrm = pj.CallOpParam() 81 callPrm.opt.audioCount = 1 82 callPrm.opt.videoCount = 0 83 mycall.uri = "sip:test1@pjsip.org" 84 self.callList.append(mycall) 85 mycall.makeCall(mycall.uri, callPrm) 86 99 87 100 def onRegState(self, prm): 88 101 self.app.updateAccount(self) 89 102 90 103 def onIncomingCall(self, prm): 91 mycall = call.Call(self.app, self, prm.callId) 92 self.callList.append(mycall) 93 self.app.updateCall(self) 94 callPrm = pj.CallOpParam() 95 msg = "Incoming call for account '%s'" % self.cfg.idUri 96 if msgbox.askquestion(msg, 'Accept call?', default=msgbox.YES) == u'yes': 97 callPrm.statusCode = 200 98 mycall.answer(callPrm) 99 else: 100 mycall.hangup(callPrm) 101 102 104 c = call.Call(self, call_id=prm.callId) 105 call_prm = pj.CallOpParam() 106 call_prm.statusCode = 180 107 c.answer(call_prm) 108 ci = c.getInfo() 109 msg = "Incoming call for account '%s'" % self.cfg.idUri 110 if msgbox.askquestion(msg, "Accept call from '%s'?" % (ci.remoteURI), default=msgbox.YES) == u'yes': 111 call_prm.statusCode = 200 112 c.answer(call_prm) 113 114 # create chat instance 115 bud = self.findBuddy(ci.remoteURI) 116 if not bud: return 117 chat = self.findChat(bud) 118 if not chat: chat = self.newChat(bud, c) 119 120 chat.registerCall(bud, c) 121 chat.showWindow() 122 else: 123 c.hangup(call_prm) 124 125 def onInstantMessage(self, prm): 126 bud = self.findBuddy(prm.fromUri) 127 if not bud: return 128 chat = self.findChat(bud) 129 if not chat: chat = self.newChat(bud) 130 131 chat.addMessage(bud.cfg.uri, prm.msgBody) 132 chat.showWindow() 133 134 def onInstantMessageStatus(self, prm): 135 if prm.code/100 == 2: return 136 137 bud = self.findBuddy(prm.toUri) 138 if not bud: return 139 chat = self.findChat(bud) 140 if not chat: return 141 142 chat.addMessage(None, "Failed sending message to '%s': %s" % (bud.cfg.uri, prm.reason)) 143 144 def onTypingIndication(self, prm): 145 bud = self.findBuddy(prm.fromUri) 146 if not bud: return 147 chat = self.findChat(bud) 148 if not chat: return 149 150 chat.setTypingIndication(bud.cfg.uri, prm.isTyping) 151 152 103 153 # Account frame, to list accounts 104 154 class AccountListFrame(ttk.Frame):
Note: See TracChangeset
for help on using the changeset viewer.