connect
Connect to the Webcast server & iterate over response messages.
Method of WebcastWSClient.
Connect to the Webcast server & iterate over response messages.
--- Message 1 ---
The iterator exits normally when the connection is closed with close code
1000 (OK) or 1001 (going away) or without a close code. It raises
a ~websockets.exceptions.ConnectionClosedError when the connection
is closed with any other code.
--- Message 2 ---
DEVELOP SANITY NOTE:
When ping_timeout is set (i.e. not None), the client waits for a pong for N seconds. TikTok DO NOT SEND pongs back. Unfortunately the websockets client after N seconds assumes the server is dead. It then throws the following infamous exception:
websockets.exceptions.ConnectionClosedError: sent 1011 (unexpected error) keepalive ping timeout; no close frame received
If you set ping_timeout to None, it doesn’t wait for a pong. Perfect, since TikTok don’t send them.
--- Parameters —
Signature
Section titled “Signature”async def connect( room_id: int, cookies: httpx.Cookies, user_agent: str, initial_webcast_response: ProtoMessageFetchResult, process_connect_events: bool = True, compress_ws_events: bool = True,) -> AsyncIterator[ProtoMessageFetchResult]Parameters
Section titled “Parameters”room_id(int) — The room ID to connect tocookies(httpx.Cookies) — The cookies to pass to the WebSocket connectionuser_agent(str) — The user agent to pass to the WebSocket connectioninitial_webcast_response(ProtoMessageFetchResult) — The Initial ProtoMessageFetchResult from the sign server - NOT a PushFrameprocess_connect_events(bool, defaultTrue) — Whether to process the initial events sent in the first fetchcompress_ws_events(bool, defaultTrue) — Whether to ask TikTok to gzip the WebSocket events
Returns
Section titled “Returns”AsyncIterator[ProtoMessageFetchResult] — Yields ProtoMessageFetchResultMessage, the messages within ProtoMessageFetchResult.messages
Import
Section titled “Import”from TikTokLive.client.ws.ws_client import WebcastWSClient