Debian Codegraph @

Xpjproject/pjsip-apps/src/pygui/call.py

raw symbols SCIP
1 #
2 # pjsua Python GUI Demo
3 #
4 # Copyright (C)2013 Teluu Inc. (http://www.teluu.com)
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #
20 import sys
21 if sys.version_info[0] >= 3: # Python 3
22 import tkinter as tk
23 from tkinter import ttk
24 from tkinter import messagebox as msgbox
25 else:
26 import Tkinter as tk
27 import tkMessageBox as msgbox
28 import ttk
29
30 import random
31 import pjsua2 as pj
32 import application
33 import endpoint as ep
34
35 # Call class
36 class Call(pj.Call):
37 """
38 High level Python Call object, derived from pjsua2's Call object.
39 """
40 def __init__(self, acc, peer_uri='', chat=None, call_id = pj.PJSUA_INVALID_ID):
41 pj.Call.__init__(self, acc, call_id)
42 self.acc = acc
43 self.peerUri = peer_uri
44 self.chat = chat
45 self.connected = False
46 self.onhold = False
47
48 def onCallState(self, prm):
49 ci = self.getInfo()
50 self.connected = ci.state == pj.PJSIP_INV_STATE_CONFIRMED
51 if self.chat:
52 self.chat.updateCallState(self, ci)
53
54 def onCallMediaState(self, prm):
55 ci = self.getInfo()
56 for mi in ci.media:
57 if mi.type == pj.PJMEDIA_TYPE_AUDIO and \
58 (mi.status == pj.PJSUA_CALL_MEDIA_ACTIVE or \
59 mi.status == pj.PJSUA_CALL_MEDIA_REMOTE_HOLD):
60 m = self.getMedia(mi.index)
61 am = pj.AudioMedia.typecastFromMedia(m)
62 # connect ports
63 ep.Endpoint.instance.audDevManager().getCaptureDevMedia().startTransmit(am)
64 am.startTransmit(ep.Endpoint.instance.audDevManager().getPlaybackDevMedia())
65
66 if mi.status == pj.PJSUA_CALL_MEDIA_REMOTE_HOLD and not self.onhold:
67 self.chat.addMessage(None, "'%s' sets call onhold" % (self.peerUri))
68 self.onhold = True
69 elif mi.status == pj.PJSUA_CALL_MEDIA_ACTIVE and self.onhold:
70 self.chat.addMessage(None, "'%s' sets call active" % (self.peerUri))
71 self.onhold = False
72 if self.chat:
73 self.chat.updateCallMediaState(self, ci)
74
75 def onInstantMessage(self, prm):
76 # chat instance should have been initalized
77 if not self.chat: return
78
79 self.chat.addMessage(self.peerUri, prm.msgBody)
80 self.chat.showWindow()
81
82 def onInstantMessageStatus(self, prm):
83 if prm.code/100 == 2: return
84 # chat instance should have been initalized
85 if not self.chat: return
86
87 self.chat.addMessage(None, "Failed sending message to '%s' (%d): %s" % (self.peerUri, prm.code, prm.reason))
88
89 def onTypingIndication(self, prm):
90 # chat instance should have been initalized
91 if not self.chat: return
92
93 self.chat.setTypingIndication(self.peerUri, prm.isTyping)
94
95 def onDtmfDigit(self, prm):
96 #msgbox.showinfo("pygui", 'Got DTMF:' + prm.digit)
97 pass
98
99 def onCallMediaTransportState(self, prm):
100 #msgbox.showinfo("pygui", "Media transport state")
101 pass
102
103
104 if __name__ == '__main__':
105 application.main()