Exemplo n.º 1
0
    def create_new_session(self, session_id=0, transport=None):
        if session_id == 0:
            session_id = random_uint64()
            while session_id in self._sessions:
                session_id = random_uint64()
        if session_id in self._sessions:
            raise JanusCloudError('Session ID already in use',
                                  JANUS_ERROR_SESSION_CONFLICT)
        session = FrontendSession(session_id, transport)
        self._sessions[session_id] = session
        if transport:
            transport.session_created(session_id)

        log.info('Creating new session: {} '.format(session_id))

        return session
Exemplo n.º 2
0
    def __init__(self, server_name, server_ip, ws_port, admin_ws_port=0,
                 pingpong_interval=5, statistic_interval=10, request_timeout=10,
                 hwm_threshold=0, admin_secret=''):
        self.server_name = server_name
        if self.server_name is None or self.server_name == '':
            self.server_name = 'server_{}'.format(random_uint64())
        self.server_local_ip = server_ip
        self.server_public_ip = server_ip
        if server_ip == '127.0.0.1':
            self.server_public_ip = get_host_ip()
        self.ws_port = ws_port
        self.session_num = -1
        self.handle_num = -1
        self.start_time = 0
        self.status = JANUS_SERVER_STATUS_ABNORMAL
        self._in_maintenance = False
        self._admin_ws_port = admin_ws_port
        self._hwm_threshold = hwm_threshold
        self._admin_secret = admin_secret

        self._ws_client = None
        self._admin_ws_client = None
        self._transactions = {}
        self._has_destroy = False
        self._poll_greenlet = gevent.spawn(self._poll_routine)
        self._poll_interval = pingpong_interval
        self._statistic_greenlet = None
        if self._admin_ws_port:
            self._statistic_greenlet = gevent.spawn(self._statistic_routine)
        self._statistic_interval = statistic_interval
        self._request_timeout = request_timeout
        self._state_change_cbs = []
        self._listeners = []
Exemplo n.º 3
0
 def attach_handle(self, plugin, opaque_id=None):
     if self._has_destroyed:
         raise JanusCloudError(
             'session {} has been destroy'.format(self.session_id),
             JANUS_ERROR_PLUGIN_ATTACH)
     plugin = get_plugin(plugin)
     if plugin is None:
         raise JanusCloudError("No such plugin '%s'".format(plugin),
                               JANUS_ERROR_PLUGIN_NOT_FOUND)
     handle_id = random_uint64()
     while handle_id in self._handles:
         handle_id = random_uint64()
     handle = plugin.create_handle(handle_id, self, opaque_id)
     self._handles[handle_id] = handle
     log.info(
         'a new handle {} on session {} is attached for plugin {}'.format(
             handle_id, self.session_id, plugin))
     return handle
Exemplo n.º 4
0
 def _genrate_new_tid(self):
     tid = str(random_uint64())
     while tid in self._transactions:
         tid = str(random_uint64())
     return tid