def init(self): """Initialize global pjsip library. General codec and device configuration should be done here. """ try: # Get log level from command line log_level = Settings().verbose nameserver = Settings().nameserver if nameserver: ua_cfg = pjsua.UAConfig() ua_cfg.nameserver = Settings().nameserver else: ua_cfg = None # Initializa PJSUA self.lib = pjsua.Lib() self.lib.init(log_cfg=pjsua.LogConfig(level=log_level, callback=self.pjlog_cb), ua_cfg=ua_cfg) if Settings().transport == 'tcp': self.transport_tcp = self.lib.create_transport(pjsua.TransportType.TCP) elif Settings().transport == 'tls': self.transport_tls = self.lib.create_transport(pjsua.TransportType.TLS) else: self.transport_udp = self.lib.create_transport(pjsua.TransportType.UDP) self.lib.set_null_snd_dev() self.lib.start() except pjsua.Error, e: self.lib.destroy() print "Exception: " + str(e)
def initLib(self): try: self.lib = pj.Lib() except: raise UnrecoverableFailure uaconfig = pj.UAConfig() #uaconfig.stun_host = STUN_SERVER if self.account: if self.account.has_key('useragent'): uaconfig.user_agent = self.account['useragent'] def log_cb(lvl, str, len): pass print str try: self.lib.init(ua_cfg=uaconfig, log_cfg=pj.LogConfig(level=5, callback=log_cb)) self.lib.create_transport(pj.TransportType.TCP) self.lib.start() except: raise UnrecoverableFailure self.broadcastStatus(CONNECTING) self.accountResolver = AccountResolver(self.callback_accountsRetrieved, clientid=None)
def __init__(self, user, log_level=6): ## Load config file self._config = ConfigParser.ConfigParser() self._config.read('./config.cfg') ## Initialize logger dispsip._user = user self._user = user self._user_code = user.user_code self.logger = logging.getLogger(self._user_code + '.dispsip') self.logger.info('Initializing SIP device for user: %s', self._user_code) ## Initializing SIP device if not pj.Lib.instance(): lib = pj.Lib() else: lib = pj.Lib.instance() my_ua_cfg = pj.UAConfig() my_media_cfg = pj.MediaConfig() try: self.logger.debug('Initializing PJSUA library') lib.init(log_cfg=pj.LogConfig(level=log_level, callback=log_cb), ua_cfg=my_ua_cfg, media_cfg=my_media_cfg) self.logger.debug('Setting null sound device in PJSUA library') lib.set_null_snd_dev() except pj.Error, e: self.logger.error('Lib Initialization error: %s', e)
def run(self, domain, user, password): try: mediaconfig = pj.MediaConfig() mediaconfig.quality = 10 self.lib.init(log_cfg=pj.LogConfig(level=4, callback=self.log_cb), media_cfg=mediaconfig) transport = self.lib.create_transport(pj.TransportType.UDP, pj.TransportConfig()) self.lib.start() # Put your sIP client credentials here acc = self.lib.create_account( pj.AccountConfig(domain=domain, username=user, password=password)) acc_cb = MyAccountCallback(app=self, account=acc) acc.set_callback(acc_cb) acc_cb.wait() print "\n" print "Registration complete, status=", acc.info().reg_status, \ "(" + acc.info().reg_reason + ")" if len(sys.argv) > 1: lck = self.lib.auto_lock() my_sip_uri = "sip:" + transport.info().host + \ ":" + str(transport.info().port) # Menu loop while True: print "My SIP URI is", my_sip_uri print "Menu: h=hangup call, q=quit" input = sys.stdin.readline().rstrip("\r\n") if input == "h": if not self.current_call: print "There is no call" continue self.current_call.hangup() self.reset_all() elif input == "q": break # shutdown the library transport = None self.lib.destroy() self.lib = None except pj.Error, e: print "Exception: " + str(e) self.lib.destroy() lib = None
def __init__(self): self.lib = pj.Lib() # Create library instance self.lib.init(log_cfg=pj.LogConfig( level=6, callback=log_cb, filename="/tmp/pjsip.log")) # Init library with default config self.lib.create_transport( pj.TransportType.UDP ) # Create UDP transport which listens to any available port self.lib.set_null_snd_dev() # disable the sound card
def _init_lib(self) -> None: self.lib = pjsua.Lib() self.lib.init(log_cfg=pjsua.LogConfig(level=logging.DEBUG)) pjsua_port = random.randint(5080, 6080) self.transports = dict( t1=self.lib.create_transport(pjsua.TransportType.UDP, pjsua.TransportConfig(pjsua_port)) ) self.lib.start() self.lib.handle_events()
def create_LogConfig(): logger.debug("create_LogConfig") # Doc: http://www.pjsip.org/python/pjsua.htm#LogConfig LogConfig = pj.LogConfig(callback=pj_log, level=conf.get_int(SIPPHONE_SECTION, 'log.level', 1), console_level=conf.get_int( SIPPHONE_SECTION, 'log.console_level', 1)) return LogConfig
def start_pj(): """Start PJSUA library, open a listening port""" global lib lib = pj.Lib() lib.init(log_cfg=pj.LogConfig( level=0, filename='', callback=None, console_level=0)) lib.set_null_snd_dev() # Choose any open port, rather than restricting to a particular port... lib.create_transport(pj.TransportType.UDP) lib.start() return lib
def init_lib(self): """Initiates and start a PJSUA library """ try: self.lib = pj.Lib() self.lib.init(log_cfg=pj.LogConfig(level=0, callback=log_cb)) self.lib.set_null_snd_dev() self.lib.start() # for user in self.users: print "new user @ batch:",self.id, ", user_id:", user except pj.Error, e: print "Exception while initiating pj.Lib()", str(e)
def __init__(self,filename=None,lib=None): self.player_id=-1 self.player_slot=-1 self.filename=filename self.created={} if lib: self.lib=lib elif pj.Lib.instance(): self.lib=pj.Lib.instance() else: self.lib = pj.Lib() self.lib.init(log_cfg = pj.LogConfig(level=2,callback=log_cb)) self.lib.start()
def call(URI): try: library = pj.Lib() library.init(log_cfg = pj.LogConfig(level=3, callback=log_cb)) transport = library.create_transport(pj.TransportType.UDP) library.start() acc = library.create_account_for_transport(transport) call = acc.make_call(URI[1], MyCallCallback()) library.destroy() library = None except pj.Error, e: print "Exception: " + str(e) library.destroy() library = None sys.exit(1)
def start(self): ua = pj.UAConfig() ua.nameserver = ['8.8.8.8', '8.8.4.4'] ua.user_agent = "PJSIP Python EasyPhone" media = pj.MediaConfig() media.enable_ice = True logger = pj.LogConfig(level=self.verbose, callback=logger_callback) self.pjsip.init(ua_cfg=ua, media_cfg=media, log_cfg=logger) self.pjsip.create_transport(pj.TransportType.TCP, pj.TransportConfig()) self.pjsip.set_null_snd_dev() self.pjsip.start() self.pjsip.handle_events()
def sip_registration(lib, conf_params): global acc, common_objects lib.init(log_cfg=pj.LogConfig(level=1, callback=log_cb)) transport = lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(0)) lib.start() acc = lib.create_account( pj.AccountConfig(conf_params['elx_host'], conf_params['sip_user'], conf_params['sip_pass'])) acc_cb = MyAccountCallback(acc) acc.set_callback(acc_cb) acc_cb.wait()
def __init__(self, caller, calling, log_level=3): self.verify = Verify() if not self.verify.setup(): sys.exit(1) self.lib = pj.Lib() self.lib.init( ua_cfg=self.ua_cfg, log_cfg=pj.LogConfig( level=7, callback=lambda level, str, len: logging.debug(str.strip())), media_cfg=self.media_cfg) self.lib.start(with_thread=True) self.caller_ddi, self.caller_account, self.caller_cb, self.caller_cfg = self.register( caller, default=True) self.calling_ddi, self.calling_account, self.calling_cb, self.calling_cfg = self.register( calling)
def __init__(self): #self.__account_cb=self.MyAccountCallback() #self.__call_cb=self.MyCallCallback self.__lib = pj.Lib() self.__lib.init(log_cfg=pj.LogConfig(3, callback=self.__log_cb)) self.__transport = self.__lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(0)) print "\nListening on", self.__transport.info().host, print "port", self.__transport.info().port, "\n" self.__lib.start(True) self.__acc = self.__lib.create_account_for_transport( self.__transport, cb=self.MyAccountCallback(self)) self.__self_uri = "sip:" + self.__transport.info().host + ":" + str( self.__transport.info().port)
def status_on(self): print("Call is :", self.call.info().state_text), print("last code :", self.call.info().last_code), print("(" + self.call.info().last_reason + ")") # Notifies when media is changed def status_medis_on(self): global lib if self.call.info().media_state == pj.MediaState.ACTIVE: # Connect the call to sound device call_slot = self.call.info().conf_slot lib.conf_connect(call_slot, 0) lib.conf_connect(0, call_slot) print("hi”) print (lib) # Lets start our main loop here try: # Start of the Main Class # Create library instance of Lib class lib = pj.Lib() # Uses default config to initiate library lib.init(log_cfg = pj.LogConfig(stage=3, callback=lg_calbck)) # Tells about the listening socket.It listen at 5060 port and UDP protocol config_trans= pj.TransportConfig() print "-------------------------LETS START PROCESS----------------------" print "\n\n" trans_conf.port = 50600 # 5060 is default port for SIP a=raw_input("Enter the IP address of the Client: ") print "Using the default port number for SIP: 5060" config_trans.bound_addr = a transport = lib.create_transport(pj.TransportType.UDP,trans_conf) # Instatiation of library class lib.start() lib.set_null_snd_dev() # Giving information to create header of REGISTER SIP message pq4=raw_input("Enter IP address of the Server: ") pq=raw_input("Enter Username: "******"Enter Password: "******"Do you want to display name as the username Y/N ??") if pq2=="y" or pq2=="Y": pq3=pq else:
def __init__(self,lib=None): if lib: self.lib=lib elif pj.Lib.instance(): self.lib=pj.Lib.instance() else: self.lib = pj.Lib() ua=pj.UAConfig() ua.max_calls=40 self.lib.init(log_cfg = pj.LogConfig(level=2,callback=log_cb),ua_cfg=ua) self._transport=self.lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(0)) self.lib.start() devs=self.lib.enum_snd_dev() if not len(devs): self.lib.set_null_snd_dev() self.player=Player() self.created={}
def init(self): self.status = States.init self.lib = pj.Lib() self.cfg_ua = pj.UAConfig() self.cfg_md = pj.MediaConfig() self.cfg_ua.max_calls, self.cfg_ua.user_agent = 32, "TrashTalker/1.0" self.cfg_md.no_vad, self.cfg_md.enable_ice = True, False self.cfg_lg = pj.LogConfig(level=self.LOG_LEVEL, callback=PJLog) self.lib.init(ua_cfg=cfg_ua, media_cfg=cfg_md, log_cfg=cfg_lg) self.lib.set_null_snd_dev() self.lib.start(with_thread=True) self.transport = self.lib.create_transport( pj.TransportType.UDP, pj.TransportConfig(self.port)) self.account = self.lib.create_account_for_transport(self.transport, cb=AccountCb()) self.uri = "sip:%s:%s" % (self.transport.info().host, self.transport.info().port) self.status &= States.done
def start_pjsip(self): self.domain = None self.account = None self.lib = pj.Lib() ua_cfg = pj.UAConfig() ua_cfg.max_calls = 3000 ua_cfg.user_agent = 'WebAutoDialer' self.lib.init(ua_cfg=ua_cfg, log_cfg=pj.LogConfig(level=5, callback=self._log_cb)) self.lib.start() log.info('Started PJSIP library with maximum calls number ' + str(ua_cfg.max_calls)) codecs = self.lib.enum_codecs() for codec in codecs: #adjust codecs priorities codec_priority = codec.priority if 'G729' in codec.name or 'PCMA' in codec.name: codec_priority = 255 self.lib.set_codec_priority(codec.name, codec_priority) log.info('Codec name ' + codec.name + ', priority ' + str(codec_priority))
def setUp(self): self.assertTrue(self.AH_Agent.isConnected(), "AH_Agent connection failure") if self.lib == None: self.lib = pjsua.Lib() self.lib.init(log_cfg=pjsua.LogConfig( level=0, filename='PJSUA.log', callback=None, console_level=0)) self.lib.set_null_snd_dev() self.lib.create_transport(pjsua.TransportType.UDP, pjsua.TransportConfig(5060)) self.lib.start() self.acc = self.lib.create_account( pjsua.AccountConfig(config.PBX_Host, "test1", "12345")) self.assertTrue(self.acc.is_valid(), "invalid account") acc_cb = MyAccountCallback(self.acc) self.acc.set_callback(acc_cb) acc_cb.wait() self.assertTrue(acc_cb.account.info().reg_status >= 200, "Could not register")
# Function to make call def make_call(uri): try: print "Making call to", uri return acc.make_call(uri, cb=MyCallCallback()) except pj.Error, e: print "Exception: " + str(e) return None # Create library instance lib = pj.Lib() try: # Initialize library lib.init(log_cfg=pj.LogConfig(level=LOG_LEVEL, callback=log_callback)) # Configuring one Transport Object tran_conf = pj.TransportConfig() tran_conf.bound_addr = "192.168.100.50" # IP address of PJSIP client transport = lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(0)) print "\nListening on", transport.info().host, "\n" # Start library lib.start() # Configuring Account class to register with Registrar server acc_conf = pj.AccountConfig(domain='192.168.100.50', username='******', password='******',
def Active_state(self): print("Call is :", self.call.info().state_text), print("last code :", self.call.info().last_code), print("(" + self.call.info().last_reason + ")") #Disconnection if (self.call.info().state_text == 'DISCONNCTD'): print 'Press anykey to Unregister.....' return try: #Instance creation sip_lib = sip.Lib() sip_lib.init(log_cfg = sip.LogConfig(level=3, callback=log_cb)) #creating Transport Object Instance... client_IP_address = raw_input('Enter Client IP address :') transport_socket = sip.TransportConfig() transport_socket.port = 5060 transport_socket.bound_addr = client_IP_address print('Binding IP ' + client_IP_address + 'to default port no 5060.....'), transport_bind =sip_lib.create_transport(sip.TransportType.UDP,transport_socket) print('OK') #Starting SIP libraries sip_lib.start() sip_lib.set_null_snd_dev() #Starting Registering Process r_IP=raw_input("Enter IP address of the Server: ") r_name=raw_input("Enter Username: "******"Enter Password: "******"sip:%s" % (r_name) conf_of_account.reg_uri ='sip:%s:%s' % (r_IP,transport_socket.port) account_callback = Calling_back_account(conf_of_account) acc = sip_lib.create_account(conf_of_account,cb=account_callback) #Setting value to Calling_back_account class acc.set_callback(account_callback) print('Status= ',acc.info().reg_status,'(' + acc.info().reg_reason + ')') time.sleep(5) print 'Registration is Complete....' Reg_unreg=raw_input("you want to unregister?...") if (Reg_unreg=="y"): acc.set_registration(False) else: #Cll c_ID = raw_input('Enter UID to make call : ') print 'Calling %s.....' % (c_ID) s_URI = 'sip:%s@%s:%s' % (c_ID,r_IP,transport_socket.port) call = acc.make_call(s_URI, SRCallCallback(acc)) #Unreg input = sys.stdin.readline().rstrip('\r\n') print 'Unregistering.....' time.sleep(2) sip_lib.destroy() time.sleep(2) sip_lib= None sys.exit(1) #Excpt except sip.Error, err: print 'Initializations Error', err sip_lib.destroy()
elif digits != 999: digitz[0] = digits else: digitz[0] = 999 return digitz try: # Create library instance lib = pj.Lib() # Init library with default config lib.init(log_cfg=pj.LogConfig(level=3, callback=log_cb)) # Create UDP transport which listens to any available port transport = lib.create_transport(pj.TransportType.UDP) # Start the library lib.start() # Create local/user-less account # This will start "class Account()" # || acc = lib.create_account_for_transport(transport) # Prepare the destination URI for SIP rx_dst_uri = 'sip:' + phone_number + '@' + domain uri_check = lib.verify_sip_url(rx_dst_uri)
# Create library instance lib = pj.Lib() # Init library with default config med_conf = pj.MediaConfig() med_conf.clock_rate = CALL_SAMPLING_RATE med_conf.ec_options = 0 med_conf.jb_max = 0 med_conf.jb_min = 0 med_conf.max_media_ports = 1020 ua_config = pj.UAConfig() ua_config.max_calls = 1000 lib.init(ua_cfg=ua_config, log_cfg=pj.LogConfig(level=7, callback=log_cb), media_cfg=med_conf) # Remedy the non availibility of sound device lib.set_null_snd_dev() # Create UDP transport which listens to any available port transport = lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(VOIP_SERVER_PORT)) RECORDING = True lib.start() # configure client account acc_cfg = pj.AccountConfig() acc_cfg.id = "sip:" + SIP_CALLER_ID + "@" + VOIP_SERVER acc_cfg.reg_uri = "sip:" + VOIP_SERVER
def make_call(uri): try: print "Making call to", uri return acc.make_call(uri, cb=MyCallCallback()) except pj.Error, e: print "Exception: " + str(e) return None # Create library instance lib = pj.Lib() try: # Init library with default config and some customized # logging config. lib.init(log_cfg=pj.LogConfig( level=4, console_level=0, filename="c1.log", callback=log_cb)) # Create UDP transport which listens to any available port transport = lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(0)) print "\nListening on", transport.info().host, print "port", transport.info().port, "\n" # Start the library lib.start() # Create local account acc = lib.create_account( pj.AccountConfig("phone.plivo.com", "cp7181737887811148893965692", "cp1@123")) acc_cb = MyAccountCallback(acc)
def make_call(uri): try: log("Making call to:" + uri) return acc.make_call(uri, cb=MyCallCallback()) except pj.Error, e: log("Exception: " + str(e)) return None lib = pj.Lib() try: ua_cfg = pj.UAConfig() loging_cfg = pj.LogConfig() loging_cfg.level = log_level loging_cfg.callback = log_cb media_cfg = pj.MediaConfig() if snd_clock_rate != -1: media_cfg.clock_rate = snd_clock_rate if ptime != -1: media_cfg.ptime = ptime if echo_cancel_type != -1: media_cfg.ec_options = echo_cancel_type if echo_cancel_tail != -1: media_cfg.ec_tail_len = echo_cancel_tail if quality != -1: media_cfg.quality = quality if channel_count != -1:
def __init__(self): super( Example,self ).__init__() self.initUI() lib = pj.Lib() current_call = None my_ua_cfg = pj.UAConfig() my_ua_cfg.nameserver = ['8.8.8.8', '8.8.4.4'] my_ua_cfg.user_agent = "hanxiaotian_bupt" # http://www.pjsip.org/python/pjsua.htm#MediaConfig my_media_cfg = pj.MediaConfig() my_media_cfg.enable_ice = True # # Procedure: Initialize > Create Transpot > Start > Handle calls > Shutdown # # https://trac.pjsip.org/repos/wiki/Python_SIP/Settings#StartupandShutdown # Initialize the Library lib.init(ua_cfg=my_ua_cfg, media_cfg=my_media_cfg, log_cfg = pj.LogConfig(level=3, callback=log_cb)) # Create One or More Transports transport = lib.create_transport(pj.TransportType.TCP, pj.TransportConfig()) #transport = lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(0)) #transport = lib.create_transport(pj.TransportType.TLS, pj.TransportConfig(port=5060)) # SSL lib.set_null_snd_dev() # Starting the Library lib.start() lib.handle_events() # # Registration # acc_cfg = pj.AccountConfig() succeed = 0 while (succeed == 0): print "---------------------------------------------------------------------" acc_cfg.id = "sip:[email protected]" # acc_cfg.reg_uri = "sip:10.103.241.142;transport=tcp" # acc_cfg.proxy = [] server = "10.103.241.142" acc_cfg.proxy = [ "sip:10.103.241.142;transport=tcp;lr" ] # realm = "han" # username = "******" # passwd = "101" print "---------------------------------------------------------------------" acc_cfg.auth_cred = [pj.AuthCred(realm, username ,passwd)] self.acc_cb = MyAccountCallback() self.acc = lib.create_account(acc_cfg, cb=self.acc_cb) self.acc_cb.wait() # Conditions are not correct, because when "IP address change detected for account", all other accounts is Forbidden if ((str(self.acc.info().reg_status) == "200") or (str(self.acc.info().reg_status) == "403")): succeed = 1 else: print "" print "Registration failed, status=", self.acc.info().reg_status, \ "(" + self.acc.info().reg_reason + ")" print "" print "Please try again !"
global current_call global recorderid global playerid global call_slot current_call = None recorderid = None playerid = None call_slot = None lib = pj.Lib() try: mediaconfig = pj.MediaConfig() mediaconfig.quality = 10 lib.init(log_cfg=pj.LogConfig( level=4, callback=log_cb), media_cfg=mediaconfig) transport = lib.create_transport( pj.TransportType.UDP, pj.TransportConfig()) lib.start() # Put your sIP client credentials here acc = lib.create_account(pj.AccountConfig( "10.208.209.59", "1000", "1000")) acc_cb = MyAccountCallback(acc) acc.set_callback(acc_cb) acc_cb.wait() print "\n" print "Registration complete, status=", acc.info().reg_status, \ "(" + acc.info().reg_reason + ")"
def main(argv): global broker global pj global lib global args app_name = "SIP2MQTT" parser = argparse.ArgumentParser( description= 'A SIP monitoring tool that publishes incoming calls with CallerID to an MQTT channel' ) requiredNamed = parser.add_argument_group('required named arguments') requiredNamed.add_argument("-a", "--mqtt_domain", type=str, required=True, help="the MQTT broker domain string", default=os.environ.get('MQTT_DOMAIN', None)) requiredNamed.add_argument("-t", "--mqtt_port", type=int, required=True, help="the MQTT broker port number", default=os.environ.get('MQTT_PORT', None)) parser.add_argument("--mqtt_keepalive", type=int, required=False, help="the MQTT broker keep alive in seconds", default=60) parser.add_argument("--mqtt_protocol", type=str, required=False, help="the MQTT broker protocol", default="MQTTv311", choices=['MQTTv31', 'MQTTv311']) requiredNamed.add_argument("-u", "--mqtt_username", type=str, required=True, help="the MQTT broker username", default=os.environ.get('MQTT_USERNAME', None)) requiredNamed.add_argument("-p", "--mqtt_password", type=str, required=False, help="the MQTT broker password", default=os.environ.get('MQTT_PASSWORD', None)) parser.add_argument("--mqtt_topic", type=str, required=False, help="the MQTT broker topic", default=os.environ.get('MQTT_TOPIC', "home/sip")) requiredNamed.add_argument("-d", "--sip_domain", type=str, required=True, help="the SIP domain", default=os.environ.get('SIP_DOMAIN', None)) parser.add_argument("--sip_port", type=int, required=False, help="the SIP transport port number", default=os.environ.get('SIP_PORT', 5060)) requiredNamed.add_argument("-n", "--sip_username", type=str, required=True, help="the SIP username", default=os.environ.get('SIP_USERNAME', None)) requiredNamed.add_argument("-s", "--sip_password", type=str, required=False, help="the SIP password", default=os.environ.get('SIP_PASSWORD', None)) parser.add_argument("--sip_display", type=str, required=False, help="the SIP user display name", default=app_name) parser.add_argument("--log_level", type=int, required=False, help="the application log level", default=3, choices=[0, 1, 2, 3]) parser.add_argument("-v", "--verbosity", action="count", help="increase output verbosity", default=3) args = parser.parse_args() log_level = logging.INFO #Deault logging level if args.verbosity == 1: log_level = logging.ERROR elif args.verbosity == 2: log_level = logging.WARN elif args.verbosity == 3: log_level = logging.INFO elif args.verbosity >= 4: log_level = logging.DEBUG # Configure logging # logging.basicConfig(filename="sip2mqtt.log", format="%(asctime)s - %(levelname)s - %(message)s", # datefmt="%m/%d/%Y %I:%M:%S %p", level=log_level) root = logging.getLogger() root.setLevel(log_level) # ch = logging.StreamHandler(sys.stdout) # ch.setLevel(log_level) # formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') # ch.setFormatter(formatter) # root.addHandler(ch) # A more docker-friendly approach is to output to stdout logging.basicConfig(stream=sys.stdout, format="%(asctime)s - %(levelname)s - %(message)s", datefmt="%m/%d/%Y %I:%M:%S %p", level=log_level) # Log startup messages and our configuration parameters logging.info("------------------------") logging.info("Starting up...") logging.info("--- MQTT Broker Configuration ---") logging.info("Domain: " + args.mqtt_domain) logging.info("Port: " + str(args.mqtt_port)) logging.info("Protocol: " + args.mqtt_protocol) logging.info("Username: "******"Keepalive Interval: " + str(args.mqtt_keepalive)) logging.info("Status Topic: " + args.mqtt_topic) logging.info("--- SIP Configuration ---") logging.info("Domain: " + args.sip_domain) logging.info("Username: "******"DisplayName: " + args.sip_display) try: # Handle mqtt connection and callbacks broker = mqtt.Client(client_id="", clean_session=True, userdata=None, protocol=eval("mqtt." + args.mqtt_protocol)) broker.username_pw_set(args.mqtt_username, password=args.mqtt_password) broker.on_connect = mqtt_connect #broker.on_message = mqtt_message #don't need this callback for now broker.connect(args.mqtt_domain, args.mqtt_port, args.mqtt_keepalive) # Create library instance of Lib class lib = pj.Lib() ua = pj.UAConfig() ua.user_agent = app_name mc = pj.MediaConfig() mc.clock_rate = 8000 lib.init(ua_cfg=ua, log_cfg=pj.LogConfig(level=args.verbosity, callback=None), media_cfg=mc) lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(args.sip_port)) lib.set_null_snd_dev() lib.start() acc_cfg = pj.AccountConfig() acc_cfg.id = "sip:" + args.sip_username + "@" + args.sip_domain acc_cfg.reg_uri = "sip:" + args.sip_domain acc_cfg.auth_cred = [ pj.AuthCred(args.sip_domain, args.sip_username, args.sip_password) ] acc_cfg.allow_contact_rewrite = False acc = lib.create_account(acc_cfg) acc_cb = SMAccountCallback(acc) acc.set_callback(acc_cb) logging.info("-- Registration Complete --") logging.info('SIP: Status = ' + str(acc.info().reg_status) + ' (' + acc.info().reg_reason + ')') except pj.Error, e: logging.critical(("Exception: " + str(e))) lib.destroy() sys.exit(1)
# Function to make call def connect_call(uri): try: print "call is connecting to", uri return account_C.connect_call(uri, cb=CallBackforCurrCall()) except pj.Error, e: print "Details of encountered exception in making call: " + str(e) return None #Main : Program starts here #Library instance is created for lib class lib = pj.Lib() try: lib.init(log_cfg=pj.LogConfig(level=Log_Value, callback=log_callback)) transport = lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(0)) lib.start() account_C = lib.create_account( pj.AccountConfig("192.168.137.1", "2020", "password")) acc_cb = CallbckforAccount(account_C) account_C.set_callback(acc_cb) print "\n" print "Status of the completed Registration =", account_C.info( ).reg_status, "(" + account_C.info().reg_reason + ")" if len(sys.argv) > 1: lck = lib.auto_lock() on_call = connect_call(sys.argv[1])