Example #1
0
    def __init__(self, cookies):
        """Create new client.

        cookies is a dictionary of authentication cookies.
        """

        # Event fired when the client connects for the first time with
        # arguments ().
        self.on_connect = event.Event('Client.on_connect')
        # Event fired when the client reconnects after being disconnected with
        # arguments ().
        self.on_reconnect = event.Event('Client.on_reconnect')
        # Event fired when the client is disconnected with arguments ().
        self.on_disconnect = event.Event('Client.on_disconnect')
        # Event fired when a StateUpdate arrives with arguments (state_update).
        self.on_state_update = event.Event('Client.on_state_update')

        self._cookies = cookies
        proxy = os.environ.get('HTTP_PROXY')
        if proxy:
            self._connector = aiohttp.ProxyConnector(proxy)
        else:
            self._connector = aiohttp.TCPConnector()

        self._channel = channel.Channel(self._cookies, self._connector)
        # Future for Channel.listen
        self._listen_future = None

        self._request_header = hangouts_pb2.RequestHeader(
            # Ignore most of the RequestHeader fields since they aren't
            # required. Sending a recognized client_id is important because it
            # changes the behaviour of some APIs (eg. get_conversation will
            # filter out EVENT_TYPE_GROUP_LINK_SHARING_MODIFICATION without
            # it).
            client_version=hangouts_pb2.ClientVersion(
                client_id=hangouts_pb2.CLIENT_ID_WEB_HANGOUTS,
                major_version='hangups-{}'.format(version.__version__),
            ),
            language_code='en',
        )

        # String identifying this client (populated later):
        self._client_id = None

        # String email address for this account (populated later):
        self._email = None

        # Active client management parameters:
        # Time in seconds that the client as last set as active:
        self._last_active_secs = 0.0
        # ActiveClientState enum int value or None:
        self._active_client_state = None
Example #2
0
    def __init__(self, cookies):
        """Create new client.

        cookies is a dictionary of authentication cookies.
        """

        # Event fired when the client connects for the first time with
        # arguments ().
        self.on_connect = event.Event('Client.on_connect')
        # Event fired when the client reconnects after being disconnected with
        # arguments ().
        self.on_reconnect = event.Event('Client.on_reconnect')
        # Event fired when the client is disconnected with arguments ().
        self.on_disconnect = event.Event('Client.on_disconnect')
        # Event fired when a StateUpdate arrives with arguments (state_update).
        self.on_state_update = event.Event('Client.on_state_update')

        self._cookies = cookies
        proxy = os.environ.get('HTTP_PROXY')
        if proxy:
            self._connector = aiohttp.ProxyConnector(proxy)
        else:
            self._connector = aiohttp.TCPConnector()

        self._channel = channel.Channel(self._cookies, self._connector)
        # Future for Channel.listen
        self._listen_future = None

        self._request_header = hangouts_pb2.RequestHeader(
            # Ignore most of the RequestHeader fields since they aren't
            # required.
            client_version=hangouts_pb2.ClientVersion(
                major_version='hangups-{}'.format(__version__),
            ),
            language_code='en',
        )

        # String identifying this client (populated later):
        self._client_id = None

        # String email address for this account (populated later):
        self._email = None

        # Active client management parameters:
        # Time in seconds that the client as last set as active:
        self._last_active_secs = 0.0
        # ActiveClientState enum int value or None:
        self._active_client_state = None
Example #3
0
    def __init__(self, cookies, max_retries=5, retry_backoff_base=2):
        self._max_retries = max_retries
        self._retry_backoff_base = retry_backoff_base

        self.on_connect = event.Event('Client.on_connect')
        """
        :class:`~hangups.event.Event` fired when the client connects for the
        first time.
        """

        self.on_reconnect = event.Event('Client.on_reconnect')
        """
        :class:`~hangups.event.Event` fired when the client reconnects after
        being disconnected.
        """

        self.on_disconnect = event.Event('Client.on_disconnect')
        """
        :class:`~hangups.event.Event` fired when the client is disconnected.
        """

        self.on_state_update = event.Event('Client.on_state_update')
        """
        :class:`~hangups.event.Event` fired when an update arrives from the
        server.

        Args:
            state_update: A ``StateUpdate`` message.
        """
        # Google session cookies:
        self._cookies = cookies

        # aiohttp.ClientSession instance (populated by connect method):
        self._session = None

        # Channel instance (populated by connect method):
        self._channel = None

        # Future for Channel.listen (populated by connect method):
        self._listen_future = None

        self._request_header = hangouts_pb2.RequestHeader(
            # Ignore most of the RequestHeader fields since they aren't
            # required. Sending a recognized client_id is important because it
            # changes the behaviour of some APIs (eg. get_conversation will
            # filter out EVENT_TYPE_GROUP_LINK_SHARING_MODIFICATION without
            # it).
            client_version=hangouts_pb2.ClientVersion(
                client_id=hangouts_pb2.CLIENT_ID_WEB_HANGOUTS,
                major_version='hangups-{}'.format(version.__version__),
            ),
            language_code='en',
        )

        # String identifying this client (populated later):
        self._client_id = None

        # String email address for this account (populated later):
        self._email = None

        # Active client management parameters:
        # Time in seconds that the client as last set as active:
        self._last_active_secs = 0.0
        # ActiveClientState enum int value or None:
        self._active_client_state = None