def account_config() -> pj.AccountConfig: """Creates the PJSUA2 AccountConfig object.""" LOGGER.trace("Creating account config") acfg = pj.AccountConfig() identity = doorpi.INSTANCE.config["sipphone.server.identity"] sip_server = sipphone_server() sip_user = doorpi.INSTANCE.config["sipphone.server.username"] sip_pass = doorpi.INSTANCE.config["sipphone.server.password"] sip_realm = doorpi.INSTANCE.config["sipphone.server.realm"] or sip_server if identity: identity = identity.replace("\\", "\\\\").replace('"', '\\"') acfg.idUri = f'"{identity}" <sip:{sip_user}@{sip_server}>' else: acfg.idUri = f"sip:{sip_user}@{sip_server}" acfg.regConfig.registrarUri = f"sip:{sip_server}" acfg.regConfig.registerOnAdd = True authCred = pj.AuthCredInfo() authCred.scheme = "digest" authCred.realm = sip_realm authCred.username = sip_user authCred.dataType = 0 # plain text password authCred.data = sip_pass acfg.sipConfig.authCreds.append(authCred) acfg.presConfig.publishEnabled = True return acfg
def account_config() -> pj.AccountConfig: logger.trace("Creating account config") acfg = pj.AccountConfig() identity = conf.get_string(SIPPHONE_SECTION, "identity", "DoorPi") sip_server = Config.sipphone_server() sip_user = conf.get_string(SIPPHONE_SECTION, "sipserver_username") sip_pass = conf.get_string(SIPPHONE_SECTION, "sipserver_password", password=True) sip_realm = conf.get_string(SIPPHONE_SECTION, "sipserver_realm", sip_server) if not sip_user: raise ValueError(f"No username given in [{SIPPHONE_SECTION}]") if not sip_server: raise ValueError(f"No server given in [{SIPPHONE_SECTION}]") if identity: identity = identity.replace("\\", "\\\\").replace("\"", "\\\"") acfg.idUri = f"\"{identity}\" <sip:{sip_user}@{sip_server}>" else: acfg.idUri = f"sip:{sip_user}@{sip_server}" acfg.regConfig.registrarUri = f"sip:{sip_server}" acfg.regConfig.registerOnAdd = True authCred = pj.AuthCredInfo() authCred.scheme = "digest" authCred.realm = sip_realm authCred.username = sip_user authCred.dataType = 0 # plain text password authCred.data = sip_pass acfg.sipConfig.authCreds.append(authCred) acfg.presConfig.publishEnabled = True return acfg
def _login(self): # Initialize configuration of account acc_cfg = pj.AccountConfig() # Create LoginDialog dlg = Login(self, acc_cfg) # Wait for response if dlg.do_modal(): # Initialize account self.acc = Account(self) # Set configuration self.acc.cfg = acc_cfg self.acc.create(self.acc.cfg) # Set online status ps = pj.PresenceStatus() ps.status = pj.PJSUA_BUDDY_STATUS_ONLINE self.acc.setOnlineStatus(ps) # Update title self.title(self.acc.cfg.idUri) # Get the uri of server self.domain = self.acc.cfg.regConfig.registrarUri.split(':')[1] # Reset all self.buddy_list = {} self.chat_list = {} for key in self.buddy_view.get_children(): self.buddy_view.delete(key) # If never login if not self.acc: # Then exit self._exit()
def __init__(self, app): pj.Account.__init__(self) self.app = app self.randId = random.randint(1, 9999) self.cfg = pj.AccountConfig() self.cfgChanged = False self.buddyList = [] self.chatList = [] self.deleting = False
def _onBtnAdd(self): cfg = pj.AccountConfig() dlg = accountsetting.Dialog(self.master, cfg) if dlg.doModal(): acc = Account(self.app) acc.cfg = cfg self._showAcc(acc) self.accList.append(acc) self.cfgChanged = True
def pjsua2_test(): # Create and initialize the library global ep ep_cfg = pj.EpConfig() ep_cfg.uaConfig.threadCnt = 0 ep_cfg.uaConfig.mainThreadOnly = False ep = pj.Endpoint() ep.libCreate() ep.libInit(ep_cfg) # Create SIP transport. Error handling sample is shown sipTpConfig = pj.TransportConfig() sipTpConfig.port = 12345 tp = ep.transportCreate(pj.PJSIP_TRANSPORT_UDP, sipTpConfig) # Start the library ep.libStart() acfg = pj.AccountConfig() acfg.idUri = "sip:192.168.1.11:12345" # Create the account acc = Account(ep) acc.create(acfg) #Get device list and collect device IDs of two virtual devices created ep.audDevManager().refreshDevs() devList = ep.audDevManager().enumDev() fullRecorderDeviceID = 0 devID = 0 for dev in devList: print(dev.name) if (dev.name == "FullRecorder"): acc.fullRecorderDeviceID = devID if (dev.name == "CallerVoice"): acc.callerVoiceRecorderDeviceID = devID ep.audDevManager().setPlaybackDev(acc.callerVoiceRecorderDeviceID) #acc.amr=ep.audDevManager().getPlaybackDevMedia() acc.amr = pj.AudioMediaRecorder.typecastFromAudioMedia( ep.audDevManager().getPlaybackDevMedia()) acc.amr.createRecorder(file_name="123.wav") ep.mediaAdd(acc.amr) devID = devID + 1 ep.audDevManager().setPlaybackDev(acc.fullRecorderDeviceID) while True: ep.libHandleEvents(10) if (acc.acceptCall == True): acc.acceptCall = False call_prm = pj.CallOpParam() call_prm.statusCode = 200 acc.c.answer(call_prm) if (acc.c.canConnectPlayer == True and acc.c.am != None): acc.c.canConnectPlayer = False player = pj.AudioMediaPlayer() #Play welcome message fn = u'/PJSUA2/example/welcomeFull.wav' player.createPlayer(fn, pj.PJMEDIA_FILE_NO_LOOP) # This will connect the sound device/mic to the call audio media player.startTransmit(acc.c.am) #player.startTransmit( ep.audDevManager().getPlaybackDevMedia()); #ep.audDevManager().setPlaybackDev(self.acc.callerVoiceRecorderDeviceID); #player.startTransmit(acc.amr) """ ep.audDevManager().refreshDevs(); devList=ep.audDevManager().enumDev() devID=0 for dev in devList: print(dev.name) """ ep.libDestroy()
def __init__(self): self.enabled = True self.config = pj.AccountConfig() self.buddyConfigs = []
def __init__(self, enabled=False): self.enabled = enabled self.config = pj.AccountConfig()
def _onMenuAddAccount(self): cfg = pj.AccountConfig() dlg = accountsetting.Dialog(self.master, cfg) if dlg.doModal(): self._createAcc(cfg)
def __init__(self, app): pj.Account.__init__(self) self.app = app self.cfg = pj.AccountConfig()
def pjsua2_test(): global ep # Create and initialize the library ep_cfg = pj.EpConfig() ep_cfg.logConfig.level = 5; ep = pj.Endpoint() ep.libCreate() ep.libInit(ep_cfg) ep.audDevManager().setNullDev() for codec in ep.codecEnum2(): priority = 0 if 'PCMA/8000' in codec.codecId: priority = 255 ep.codecSetPriority(codec.codecId, priority) # Create SIP transport. Error handling sample is shown sipTpConfig = pj.TransportConfig(); sipTpConfig.port = 15060; ep.transportCreate(pj.PJSIP_TRANSPORT_UDP, sipTpConfig); # Start the library ep.libStart(); acfg = pj.AccountConfig(); acfg.idUri = "sip:1002@asterisk"; acfg.regConfig.registrarUri = "sip:asterisk"; cred = pj.AuthCredInfo("digest", "*", "1002", 0, "12345"); acfg.sipConfig.authCreds.append( cred ) # Create the account acc = pj.Account() acc.create(acfg) # Here we don't have anything else to do.. while not acc.getInfo().regIsActive: print('========== registering') time.sleep(0.1) if acc.getInfo().regStatus != 200: print('++++++++++++++++++') print('no registration') return call = Call(acc) prm = pj.CallOpParam(True) prm.opt.audioCount = 1 prm.opt.videoCount = 0 call.makeCall("sip:8080@asterisk", prm) while call.getInfo().state != pj.PJSIP_INV_STATE_CONFIRMED: print(call.getInfo().stateText) time.sleep(0.1) f = open('output.lpcm', 'wb') f2 = open('hw.raw', 'rb') hwraw = f2.read() n = 320 [call.putFrame(hwraw[i:i+320]) for i in range(0, len(hwraw), n)] for i in range(10): time.sleep(1) data = call.getFrames() if data: f.write(data) f.close() prm = pj.CallOpParam() call.hangup(prm) # Destroy the library ep.hangupAllCalls() print('unregistering') acc.delete()
def startup(self): self._logger.debug("entered startup()") ep_cfg = pjsua2.EpConfig() ep_cfg.uaConfig.mainThreadOnly = True ep_cfg.uaConfig.threadCnt = 0 version = pkg_resources.require("gtkapplication")[0].version ep_cfg.uaConfig.userAgent = "pyphone-{0}".format(version) self._logger.debug('ep_cfg.uaConfig.userAgent = %s', ep_cfg.uaConfig.userAgent) ep_cfg.logConfig.msgLogging = 1 ep_cfg.logConfig.level = 5 ep_cfg.logConfig.consoleLevel = 5 decor = pjsua2.PJ_LOG_HAS_YEAR | pjsua2.PJ_LOG_HAS_MONTH | pjsua2.PJ_LOG_HAS_DAY_OF_MON | pjsua2.PJ_LOG_HAS_TIME | pjsua2.PJ_LOG_HAS_MICRO_SEC | pjsua2.PJ_LOG_HAS_SENDER | pjsua2.PJ_LOG_HAS_NEWLINE | pjsua2.PJ_LOG_HAS_SPACE | pjsua2.PJ_LOG_HAS_THREAD_SWC | pjsua2.PJ_LOG_HAS_INDENT self._logger.debug('decor = %s', decor) ep_cfg.logConfig.decor = decor ep_cfg.logConfig.filename = "logs/pjsip.log" ep_cfg.logConfig.fileFlags = pjsua2.PJ_O_APPEND pjsip_log_writer = gtkapplication.api.sip.logger.PjLogger() ep_cfg.logConfig.writer = pjsip_log_writer sip_container = gtkapplication.api.sip.pjsip_container.sip_container sip_container.pjsip_log_writer = pjsip_log_writer sip_container.ep = pjsua2.Endpoint() ep = sip_container.ep ep.libCreate() ep.libInit(ep_cfg) pjsip_version = ep.libVersion().full self._logger.debug('pjsip_version = %s', pjsip_version) sip_udp_tranport_config = pjsua2.TransportConfig() sip_udp_tranport_config.port = 5060 sip_udp_tranport_config.enabled = 1 ep.transportCreate(pjsua2.PJSIP_TRANSPORT_UDP, sip_udp_tranport_config) self._logger.debug("transport created") acfg = pjsua2.AccountConfig() acfg.idUri = gtkapplication.data.config_data.PROFILE_DATA['sip_uri'] acfg.regConfig.registrarUri = gtkapplication.data.config_data.PROFILE_DATA[ 'sip_registrar_uri'] acfg.regConfig.registerOnAdd = True acfg.regConfig.timeoutSec = 60 acfg.regConfig.retryIntervalSec = 60 aci = pjsua2.AuthCredInfo() aci.scheme = "digest" aci.realm = "*" aci.username = gtkapplication.data.config_data.PROFILE_DATA[ 'sip_username'] aci.dataType = 0 aci.data = gtkapplication.data.config_data.PROFILE_DATA['sip_password'] aciv = pjsua2.AuthCredInfoVector() aciv.append(aci) acfg.sipConfig.authCreds = aciv sip_container.sip_account_list.append( gtkapplication.api.sip.account.Account(acfg)) sip_account = sip_container.sip_account_list[0] sip_account.cfg = acfg sip_account.create(acfg, True) presence_status = pjsua2.PresenceStatus() presence_status.status = pjsua2.PJSUA_BUDDY_STATUS_ONLINE sip_account.setOnlineStatus(presence_status) self._logger.debug("sip account created: %r", sip_account) bcfg = pjsua2.BuddyConfig() bcfg.uri = gtkapplication.data.config_data.PROFILE_DATA[ 'sip_buddy_uri'] bcfg.subscribe = True buddy = gtkapplication.api.sip.buddy.Buddy(sip_account) buddy.create(sip_account, bcfg) sip_account.server_buddy = buddy contact_manager = gtkapplication.api.contacts.contact_manager.ContactManager( ) contact_manager.create_free_buddy_contacts(sip_account) acfg = pjsua2.AccountConfig() acfg.idUri = gtkapplication.data.config_data.PROFILE_DATA[ 'twilio_sip_uri'] acfg.regConfig.registrarUri = gtkapplication.data.config_data.PROFILE_DATA[ 'twilio_sip_registrar_uri'] self._logger.debug("twilio sip_uri = '%s', registrar = %s", acfg.idUri, acfg.regConfig.registrarUri) acfg.regConfig.registerOnAdd = True acfg.regConfig.timeoutSec = 60 acfg.regConfig.retryIntervalSec = 60 aci = pjsua2.AuthCredInfo() aci.scheme = "digest" aci.realm = "*" aci.username = gtkapplication.data.config_data.PROFILE_DATA[ 'twilio_sip_username'] aci.dataType = 0 aci.data = gtkapplication.data.config_data.PROFILE_DATA[ 'twilio_sip_password'] aciv = pjsua2.AuthCredInfoVector() aciv.append(aci) acfg.sipConfig.authCreds = aciv sip_container.sip_account_list.append( gtkapplication.api.sip.account.Account(acfg)) twilio_sip_account = sip_container.sip_account_list[1] twilio_sip_account.cfg = acfg twilio_sip_account.create(acfg, True) presence_status = pjsua2.PresenceStatus() presence_status.status = pjsua2.PJSUA_BUDDY_STATUS_ONLINE twilio_sip_account.setOnlineStatus(presence_status) ep.libStart() self._logger.debug("after libStart()") tone_generator = pjsua2.ToneGenerator() tone_generator.createToneGenerator(16000, 1) sip_container.tone_generator = tone_generator self._logger.debug("tone generator created") self._source_tag = GObject.timeout_add(50, self.poll_pjsip_events_timer, False) self._logger.debug("timer started source_tag is %s", self._source_tag) self._logger.info("timer started")