コード例 #1
0
ファイル: backend.py プロジェクト: madhawa/sylkserver
class JanusBackend(object):
    __metaclass__ = Singleton
    implements(IObserver)

    def __init__(self):
        self.janus_logger = JanusLogger()
        self.factory = JanusClientFactory(url=JanusConfig.api_url,
                                          protocols=['janus-protocol'],
                                          useragent='SylkServer/%s' % SYLK_VERSION)
        self.factory.janus_logger = self.janus_logger
        self.connector = None
        self.connection = Null
        self._stopped = False

    def __getattr__(self, attr):
        if attr.startswith('janus_'):
            return getattr(self.connection, attr)
        return self.attr

    @property
    def ready(self):
        return self.connection is not Null

    def start(self):
        self.janus_logger.start()
        notification_center = NotificationCenter()
        notification_center.add_observer(self, name='JanusBackendConnected')
        notification_center.add_observer(self, name='JanusBackendDisconnected')
        self.connector = connectWS(self.factory)

    def stop(self):
        if self._stopped:
            return
        self._stopped = True
        self.janus_logger.stop()
        self.factory.stopTrying()
        notification_center = NotificationCenter()
        notification_center.discard_observer(self, name='JanusBackendConnected')
        notification_center.discard_observer(self, name='JanusBackendDisconnected')
        if self.connector is not None:
            self.connector.disconnect()
            self.connector = None
        if self.connection is not None:
            self.connection.disconnect()
            self.connection = Null

    def handle_notification(self, notification):
        handler = getattr(self, '_NH_%s' % notification.name, Null)
        handler(notification)

    def _NH_JanusBackendConnected(self, notification):
        assert self.connection is Null
        self.connection = notification.sender
        log.msg('Janus backend connection up')
        self.factory.resetDelay()

    def _NH_JanusBackendDisconnected(self, notification):
        log.msg('Janus backend connection down: %s' % notification.data.reason)
        self.connection = Null
コード例 #2
0
ファイル: backend.py プロジェクト: madhawa/sylkserver
 def __init__(self):
     self.janus_logger = JanusLogger()
     self.factory = JanusClientFactory(url=JanusConfig.api_url,
                                       protocols=['janus-protocol'],
                                       useragent='SylkServer/%s' % SYLK_VERSION)
     self.factory.janus_logger = self.janus_logger
     self.connector = None
     self.connection = Null
     self._stopped = False
コード例 #3
0
 def __init__(self):
     self.janus_logger = JanusLogger()
     self.factory = JanusClientFactory(url=JanusConfig.api_url,
                                       protocols=['janus-protocol'],
                                       useragent='SylkServer/%s' %
                                       SYLK_VERSION)
     self.factory.janus_logger = self.janus_logger
     self.connector = None
     self.connection = Null
     self._stopped = False
コード例 #4
0
class JanusBackend(object):
    __metaclass__ = Singleton
    implements(IObserver)

    def __init__(self):
        self.janus_logger = JanusLogger()
        self.factory = JanusClientFactory(url=JanusConfig.api_url,
                                          protocols=['janus-protocol'],
                                          useragent='SylkServer/%s' %
                                          SYLK_VERSION)
        self.factory.janus_logger = self.janus_logger
        self.connector = None
        self.connection = Null
        self._stopped = False

    def __getattr__(self, attr):
        if attr.startswith('janus_'):
            return getattr(self.connection, attr)
        return self.attr

    @property
    def ready(self):
        return self.connection is not Null

    def start(self):
        self.janus_logger.start()
        notification_center = NotificationCenter()
        notification_center.add_observer(self, name='JanusBackendConnected')
        notification_center.add_observer(self, name='JanusBackendDisconnected')
        self.connector = connectWS(self.factory)

    def stop(self):
        if self._stopped:
            return
        self._stopped = True
        self.janus_logger.stop()
        self.factory.stopTrying()
        notification_center = NotificationCenter()
        notification_center.discard_observer(self,
                                             name='JanusBackendConnected')
        notification_center.discard_observer(self,
                                             name='JanusBackendDisconnected')
        if self.connector is not None:
            self.connector.disconnect()
            self.connector = None
        if self.connection is not None:
            self.connection.disconnect()
            self.connection = Null

    def handle_notification(self, notification):
        handler = getattr(self, '_NH_%s' % notification.name, Null)
        handler(notification)

    def _NH_JanusBackendConnected(self, notification):
        assert self.connection is Null
        self.connection = notification.sender
        log.msg('Janus backend connection up')
        self.factory.resetDelay()

    def _NH_JanusBackendDisconnected(self, notification):
        log.msg('Janus backend connection down: %s' % notification.data.reason)
        self.connection = Null