| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
import sys |
| 21 |
if sys.version_info[0] >= 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 91 |
if not self.chat: return |
| 92 |
|
| 93 |
self.chat.setTypingIndication(self.peerUri, prm.isTyping) |
| 94 |
|
| 95 |
def onDtmfDigit(self, prm): |
| 96 |
|
| 97 |
pass |
| 98 |
|
| 99 |
def onCallMediaTransportState(self, prm): |
| 100 |
|
| 101 |
pass |
| 102 |
|
| 103 |
|
| 104 |
if __name__ == '__main__': |
| 105 |
application.main() |