コード例 #1
0
class TestLinphoneSession(TestCase):
    def setUp(self):
        self._name, self._passwd, self._hostname = 'abc', 'secret', '127.0.0.1'
        self._s = Session(self._name, self._passwd, self._hostname,
                          sentinel.sip_port, sentinel.rtp_port)
        self._shell = self._s._linphone_shell = Mock(_Shell)

    def test_answer(self):
        self._s.answer()

        self._shell.execute.assert_called_once_with(AnswerCommand())

    def test_call(self):
        self._s.call(sentinel.exten)

        self._shell.execute.assert_called_once_with(CallCommand(
            sentinel.exten))

    def test_hangup(self):
        self._s.hangup()

        self._shell.execute.assert_called_once_with(HangupCommand())

    def test_hook_status(self):
        self._s.hook_status()

        self._shell.execute.assert_called_once_with(HookStatusCommand())

    def test_register(self):
        self._s.register()

        self._shell.execute.assert_called_once_with(
            RegisterCommand(self._name, self._passwd, self._hostname))

    def test_unregister(self):
        self._s.unregister()

        self._shell.execute.assert_called_once_with(UnregisterCommand())
コード例 #2
0
class SIPPhone:
    def __init__(self, config, logfile=None):
        self._session = Session(
            config.sip_name,
            config.sip_passwd,
            config.sip_host,
            config.sip_port,
            config.rtp_port,
            logfile,
        )
        self._name = config.sip_name
        self.sip_port = config.sip_port
        self.rtp_port = config.rtp_port

    def answer(self, timeout=5):
        start = time.time()
        exception = None
        while time.time() - start < timeout:
            try:
                self._session.answer()
            except LinphoneException as e:
                exception = e
            else:
                return
        if exception:
            raise exception

    def call(self, exten):
        self._session.call(exten)

    def hangup(self):
        self._session.hangup()

    def hold(self):
        self._session.hold()

    def register(self):
        self._session.register()

    def resume(self):
        self._session.resume()

    def send_dtmf(self, digit):
        self._session.send_dtmf(digit)
        # NOTE(fblackburn): linphone DTMF length is 100ms
        time.sleep(0.150)

    def transfer(self, exten):
        self._session.transfer(exten)

    def unregister(self):
        self._session.unregister()

    def is_talking(self):
        return self._session.call_status() == CallStatus.ANSWERED

    def is_talking_to(self, name):
        return self._session.is_talking_to(name)

    def is_ringing(self):
        return self._session.call_status() == CallStatus.RINGING

    def is_ringing_showing(self, name):
        return self._session.is_ringing_showing(name)

    def is_hungup(self):
        return self._session.call_status() == CallStatus.OFF

    def is_registered(self):
        return self._session.register_status() == RegisterStatus.REGISTERED

    def is_holding(self, context):
        response = context.amid_client.action('DeviceStateList')
        device_name = 'PJSIP/{}'.format(self._name)
        return any(
            device.get('Device') == device_name
            and device.get('State') == 'ONHOLD' for device in response)

    @property
    def sip_username(self):
        return self._name
コード例 #3
0
ファイル: sip_phone.py プロジェクト: jaunis/xivo-acceptance
class SipPhone(object):

    def __init__(self, config):
        if world.config.linphone_debug:
            logfile = sys.stdout
        else:
            logfile = None
        self._session = Session(config.sip_name,
                                config.sip_passwd,
                                config.sip_host,
                                config.sip_port,
                                config.rtp_port,
                                logfile)
        self._call_result = None
        self.sip_port = config.sip_port
        self.rtp_port = config.rtp_port

    def answer(self, timeout=2):
        start = time.time()
        exception = None
        while time.time() - start < timeout:
            try:
                self._session.answer()
            except LinphoneException as e:
                exception = e
            else:
                return
        if exception:
            raise exception

    def call(self, exten):
        try:
            self._session.call(exten)
            self._call_result = None
        except ExtensionNotFoundException as e:
            self._call_result = e
        except LinphoneException:
            print 'Not the good exception'

    def hangup(self):
        self._session.hangup()

    def register(self):
        self._session.register()

    def unregister(self):
        self._session.unregister()

    def last_call_result(self):
        if self._call_result:
            raise self._call_result

    def is_ringback_tone(self):
        return self._session.hook_status() == HookStatus.RINGBACK_TONE

    def is_talking(self):
        return self._session.hook_status() == HookStatus.ANSWERED

    def is_ringing(self):
        return self._session.hook_status() == HookStatus.RINGING

    def is_hungup(self):
        return self._session.hook_status() == HookStatus.OFFHOOK

    def remote_caller_id(self):
        return self._session.remote_caller_id()
コード例 #4
0
class SipPhone(object):

    def __init__(self, config):
        if world.config['debug']['linphone']:
            logfile = LinphoneLogWrapper(sys.stdout, prefix='[sip:{}]'.format(config.sip_name))
        else:
            logfile = None
        self._session = Session(config.sip_name,
                                config.sip_passwd,
                                config.sip_host,
                                config.sip_port,
                                config.rtp_port,
                                logfile)
        self._call_result = None
        self.sip_port = config.sip_port
        self.rtp_port = config.rtp_port

    def answer(self, timeout=2):
        start = time.time()
        exception = None
        while time.time() - start < timeout:
            try:
                self._session.answer()
            except LinphoneException as e:
                exception = e
            else:
                return
        if exception:
            raise exception

    def call(self, exten):
        try:
            self._session.call(exten)
            self._call_result = None
        except ExtensionNotFoundException as e:
            self._call_result = e
        except LinphoneException as e:
            logger.exception(e)

    def hangup(self):
        self._session.hangup()

    def hold(self):
        self._session.hold()

    def register(self):
        self._session.register()

    def resume(self):
        self._session.resume()

    def transfer(self, exten):
        self._session.transfer(exten)

    def unregister(self):
        self._session.unregister()

    def last_call_result(self):
        if self._call_result:
            raise self._call_result

    def is_ringback_tone(self):
        return self._session.hook_status() == HookStatus.RINGBACK_TONE

    def is_talking(self):
        return self._session.hook_status() == HookStatus.ANSWERED

    def is_ringing(self):
        return self._session.hook_status() == HookStatus.RINGING

    def is_hungup(self):
        return self._session.hook_status() == HookStatus.OFFHOOK