def __init__(self, name, args): super(JamiTest, self).__init__(name, False) self.args = args self.testCalls = set() self.iterator = 0 self.failureCount = 0 self.failureRate = 0 self.callsCompleted = 0 ringAccounts = self.getAllAccounts('RING') if len(ringAccounts) < 1: callerDetails = { 'Account.type': 'RING', 'Account.alias': 'testringaccount3' } self.addAccount(callerDetails) self.setAccount(ringAccounts[0]) volatileCallerDetails = self.getVolatileAccountDetails(self.account) if volatileCallerDetails['Account.registrationStatus'] != 'REGISTERED': raise DRingCtrlError("Caller Account not registered") self.peer = args.peer volatilePeerDetails = self.getVolatileAccountDetails() if volatilePeerDetails['Account.registrationStatus'] != 'REGISTERED': raise DRingCtrlError("Peer Account not registered") print("Using local test account: ", self.account, volatileCallerDetails['Account.registrationStatus']) print("Using test peer: ", self.peer, volatilePeerDetails['Account.registrationStatus']) if self.testCall(): GLib.timeout_add_seconds(args.interval, self.testCall)
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 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 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 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 is not "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 sys import os import random import time import hashlib from threading import Thread from functools import partial from errorsDring import DRingCtrlAccountError, DRingCtrlError, DRingCtrlDBusError, DRingCtrlDeamonError from gi.repository import GLib try: import dbus from dbus.mainloop.glib import DBusGMainLoop 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__() self.activeCalls = {} # list of active calls (known by the client) self.activeConferences = {} # list of active conferences self.account = None # current active account