diff --git a/app/service/service_manager.py b/app/service/service_manager.py index 00579e6..89017c6 100644 --- a/app/service/service_manager.py +++ b/app/service/service_manager.py @@ -10,6 +10,13 @@ from gevent import socket from gevent import select +def check_is_auth_client(client) -> bool: + if not client: + return False + + return client.is_active() + + class ServiceManager(IClientHandler): SUBSCRIBER_PORT = 6000 BANDWIDTH_PORT = 5000 @@ -104,12 +111,7 @@ class ServiceManager(IClientHandler): def on_client_state_changed(self, client, status: ClientStatus): pass - # protected - def _check_is_auth_client(self, client) -> bool: - if not client: - return False - - return client.is_active() + # protected def _handle_server_ping_command(self, client, resp: Response): pass @@ -155,7 +157,7 @@ class ServiceManager(IClientHandler): client.device = found_device def _handle_get_server_info(self, client, cid: str, params: dict): - if not self._check_is_auth_client(client): + if not check_is_auth_client(client): client.check_activate_fail(cid, 'User not active') client.disconnect() return @@ -166,15 +168,16 @@ class ServiceManager(IClientHandler): pass def _handle_get_channels(self, client, cid: str, params: dict): - if not self._check_is_auth_client(client): + if not check_is_auth_client(client): client.check_activate_fail(cid, 'User not active') client.disconnect() return - client.get_channels_success(cid) + channels = client.info.get_streams() + client.get_channels_success(cid, channels) def _handle_get_runtime_channel_info(self, client, cid: str, params: dict): - if not self._check_is_auth_client(client): + if not check_is_auth_client(client): client.check_activate_fail(cid, 'User not active') client.disconnect() return diff --git a/app/service/subscriber_client.py b/app/service/subscriber_client.py index e35cd00..be9799b 100644 --- a/app/service/subscriber_client.py +++ b/app/service/subscriber_client.py @@ -3,9 +3,9 @@ from pyfastocloud.subscriber_client import SubscriberClient from pyfastocloud.client import make_utc_timestamp -class SubscriberConnection(object): +class SubscriberConnection(SubscriberClient): def __init__(self, sock, addr, handler): - self._client = SubscriberClient(sock, addr, handler) + super(SubscriberConnection, self).__init__(sock, addr, handler) self._info = None self._current_stream_id = str() self._device = None @@ -45,44 +45,13 @@ class SubscriberConnection(object): self._last_ping_ts = value def recv_data(self) -> bool: - data = self._client.read_command() + data = self.read_command() if not data: return False - self._client.process_commands(data) + self.process_commands(data) return True - def socket(self): - return self._client.socket() - - def ping(self): - return self._client.ping(self._gen_request_id()) - - def disconnect(self): - return self._client.disconnect() - - def is_active(self): - return self._client.is_active() - - def activate_fail(self, cid: str, error: str): - return self._client.activate_fail(cid, error) - - def activate_success(self, cid: str): - return self._client.activate_success(cid) - - def check_activate_fail(self, command_id: str, error: str): - return self._client.check_activate_fail(command_id, error) - - def get_runtime_channel_info_success(self, command_id, sid: str, watchers: int): - return self._client.get_runtime_channel_info_success(command_id, sid, watchers) - - def get_channels_success(self, cid: str): - channels = self.info.get_streams() - return self._client.get_channels_success(cid, channels) - - def get_server_info_success(self, cid: str, bandwidth_host: str): - return self._client.get_server_info_success(cid, bandwidth_host) - # private def _gen_request_id(self) -> int: current_value = self._request_id