Changeset 5638 for pjproject/trunk/pjsip-apps/src/pygui/call.py
- Timestamp:
- Aug 2, 2017 9:45:09 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/pygui/call.py
r4757 r5638 21 21 import sys 22 22 if sys.version_info[0] >= 3: # Python 3 23 24 25 23 import tkinter as tk 24 from tkinter import ttk 25 from tkinter import messagebox as msgbox 26 26 else: 27 28 29 27 import Tkinter as tk 28 import tkMessageBox as msgbox 29 import ttk 30 30 31 31 import random … … 36 36 # Call class 37 37 class Call(pj.Call): 38 39 40 41 42 43 44 45 46 47 38 """ 39 High level Python Call object, derived from pjsua2's Call object. 40 """ 41 def __init__(self, acc, peer_uri='', chat=None, call_id = pj.PJSUA_INVALID_ID): 42 pj.Call.__init__(self, acc, call_id) 43 self.acc = acc 44 self.peerUri = peer_uri 45 self.chat = chat 46 self.connected = False 47 self.onhold = False 48 48 49 def onCallState(self, prm): 50 ci = self.getInfo() 51 self.connected = ci.state == pj.PJSIP_INV_STATE_CONFIRMED 52 if self.chat: 53 self.chat.updateCallState(self, ci) 54 55 def onCallMediaState(self, prm): 56 ci = self.getInfo() 57 for mi in ci.media: 58 if mi.type == pj.PJMEDIA_TYPE_AUDIO and \ 59 (mi.status == pj.PJSUA_CALL_MEDIA_ACTIVE or \ 60 mi.status == pj.PJSUA_CALL_MEDIA_REMOTE_HOLD): 61 m = self.getMedia(mi.index) 62 am = pj.AudioMedia.typecastFromMedia(m) 63 # connect ports 64 ep.Endpoint.instance.audDevManager().getCaptureDevMedia().startTransmit(am) 65 am.startTransmit(ep.Endpoint.instance.audDevManager().getPlaybackDevMedia()) 49 def onCallState(self, prm): 50 ci = self.getInfo() 51 self.connected = ci.state == pj.PJSIP_INV_STATE_CONFIRMED 52 if self.chat: 53 self.chat.updateCallState(self, ci) 66 54 67 if mi.status == pj.PJSUA_CALL_MEDIA_REMOTE_HOLD and not self.onhold: 68 self.chat.addMessage(None, "'%s' sets call onhold" % (self.peerUri)) 69 self.onhold = True 70 elif mi.status == pj.PJSUA_CALL_MEDIA_ACTIVE and self.onhold: 71 self.chat.addMessage(None, "'%s' sets call active" % (self.peerUri)) 72 self.onhold = False 73 if self.chat: 74 self.chat.updateCallMediaState(self, ci) 75 76 def onInstantMessage(self, prm): 77 # chat instance should have been initalized 78 if not self.chat: return 79 80 self.chat.addMessage(self.peerUri, prm.msgBody) 81 self.chat.showWindow() 82 83 def onInstantMessageStatus(self, prm): 84 if prm.code/100 == 2: return 85 # chat instance should have been initalized 86 if not self.chat: return 87 88 self.chat.addMessage(None, "Failed sending message to '%s' (%d): %s" % (self.peerUri, prm.code, prm.reason)) 89 90 def onTypingIndication(self, prm): 91 # chat instance should have been initalized 92 if not self.chat: return 93 94 self.chat.setTypingIndication(self.peerUri, prm.isTyping) 95 96 def onDtmfDigit(self, prm): 97 #msgbox.showinfo("pygui", 'Got DTMF:' + prm.digit) 98 pass 99 100 def onCallMediaTransportState(self, prm): 101 #msgbox.showinfo("pygui", "Media transport state") 102 pass 103 104 55 def onCallMediaState(self, prm): 56 ci = self.getInfo() 57 for mi in ci.media: 58 if mi.type == pj.PJMEDIA_TYPE_AUDIO and \ 59 (mi.status == pj.PJSUA_CALL_MEDIA_ACTIVE or \ 60 mi.status == pj.PJSUA_CALL_MEDIA_REMOTE_HOLD): 61 m = self.getMedia(mi.index) 62 am = pj.AudioMedia.typecastFromMedia(m) 63 # connect ports 64 ep.Endpoint.instance.audDevManager().getCaptureDevMedia().startTransmit(am) 65 am.startTransmit(ep.Endpoint.instance.audDevManager().getPlaybackDevMedia()) 66 67 if mi.status == pj.PJSUA_CALL_MEDIA_REMOTE_HOLD and not self.onhold: 68 self.chat.addMessage(None, "'%s' sets call onhold" % (self.peerUri)) 69 self.onhold = True 70 elif mi.status == pj.PJSUA_CALL_MEDIA_ACTIVE and self.onhold: 71 self.chat.addMessage(None, "'%s' sets call active" % (self.peerUri)) 72 self.onhold = False 73 if self.chat: 74 self.chat.updateCallMediaState(self, ci) 75 76 def onInstantMessage(self, prm): 77 # chat instance should have been initalized 78 if not self.chat: return 79 80 self.chat.addMessage(self.peerUri, prm.msgBody) 81 self.chat.showWindow() 82 83 def onInstantMessageStatus(self, prm): 84 if prm.code/100 == 2: return 85 # chat instance should have been initalized 86 if not self.chat: return 87 88 self.chat.addMessage(None, "Failed sending message to '%s' (%d): %s" % (self.peerUri, prm.code, prm.reason)) 89 90 def onTypingIndication(self, prm): 91 # chat instance should have been initalized 92 if not self.chat: return 93 94 self.chat.setTypingIndication(self.peerUri, prm.isTyping) 95 96 def onDtmfDigit(self, prm): 97 #msgbox.showinfo("pygui", 'Got DTMF:' + prm.digit) 98 pass 99 100 def onCallMediaTransportState(self, prm): 101 #msgbox.showinfo("pygui", "Media transport state") 102 pass 103 104 105 105 if __name__ == '__main__': 106 106 application.main()
Note: See TracChangeset
for help on using the changeset viewer.