def UnHold(self, callid): """Unhold an incoming call identified by a CallID""" if callid is None or callid == "": raise DRingCtrlError("Invalid callID") self.callmanager.unhold(callid)
def __init__(self, name="", accountnum=0, a2way=False): super(JamiHandler, self).__init__(name, False) self.accountnum = accountnum self.jname = name self.initialized = False self.operational = False self.sessid = random.randrange(1, 1000000) self.lastring = 0 self.lastcall = 0 self.last_msg = "" self.cb_ring = None self.cb_call = None self.cb_text = None self.cb_ring2 = None self.uservar = [-1, -1, -1, -1] try: ringAccounts = self.getAllAccounts('RING') except: ringAccounts = [] if len(ringAccounts) > self.accountnum: self.initialized = True self.setAccount(ringAccounts[self.accountnum]) # use first address volatileCallerDetails = self.getVolatileAccountDetails(self.account) if volatileCallerDetails['Account.registrationStatus'] != 'REGISTERED': self.initialized = False raise DRingCtrlError("Caller Account not registered") print("Using local account: ", self.account, volatileCallerDetails['Account.registrationStatus']) self.operational = self.initialized
def Transfer(self, callid, to): """Transfert a call identified by a CallID""" if callid is None or callid == "": raise DRingCtrlError("Invalid callID") self.callmanager.transfert(callid, to)
def Hold(self, callid): """Hold a call identified by a CallID""" if callid is None or callid == "": raise DRingCtrlError("Invalid callID") self.callmanager.hold(callid)
def Call(self, dest, account=None): """Start a call and return a CallID Use the current account previously set using setAccount(). If no account specified, first registered one in account list is used. return callID Newly generated callidentifier for this call """ if dest is None or dest == "": raise DRingCtrlError("Invalid call destination") # Set the account to be used for this call if not self.account: self.setFirstRegisteredAccount() if self.account != "IP2IP" and not self.isAccountRegistered(): raise DRingCtrlAccountError( "Can't place a call without a registered account") # Send the request to the CallManager callid = self.callmanager.placeCall(self.account, dest) if callid: # Add the call to the list of active calls and set status to SENT self.activeCalls[callid] = { 'Account': self.account, 'To': dest, 'State': 'SENT' } return callid
def Refuse(self, callid): """Refuse an incoming call identified by a CallID""" print("Refuse call " + callid) if callid is None or callid == "": raise DRingCtrlError("Invalid callID") self.callmanager.refuse(callid)
def Accept(self, callid): """Accept an incoming call identified by a CallID""" print("Accept call " + callid) if not self.account: self.setFirstRegisteredAccount() if not self.isAccountRegistered(): raise DRingCtrlAccountError( "Can't accept a call without a registered account") if callid is None or callid == "": raise DRingCtrlError("Invalid callID") self.callmanager.accept(callid)
def _valid_account(self, account): account = account or self.account if account is None: raise DRingCtrlError("No provided or current account!") return account
import random import time import hashlib import threading from threading import Thread from functools import partial from lib.dringctrl.errorsDring import DRingCtrlAccountError, DRingCtrlError, DRingCtrlDBusError, DRingCtrlDeamonError from gi.repository import GLib, GObject # pip3 install PyGObject try: import dbus # apt install dbus-x11 import dbus.mainloop.glib from dbus.mainloop.glib import DBusGMainLoop # pip3 install dbus-python except ImportError as e: raise DRingCtrlError(str(e)) DBUS_DEAMON_OBJECT = 'cx.ring.Ring' DBUS_DEAMON_PATH = '/cx/ring/Ring' class DRingCtrl(Thread): def __init__(self, name, autoAnswer): if sys.version_info[0] < 3: super(DRingCtrl, self).__init__() else: super().__init__() global nmainloop self.registered = False self.activeCalls = {} # list of active calls (known by the client) self.activeConferences = {} # list of active conferences