Pirate Tok
Docs/TikTok protocol/Connection & authentication/Webcast WSS ws_reuse_supplement
WSS/webcast/im/ws_proxy/ws_reuse_supplement/

Webcast WSS ws_reuse_supplement

Purpose

Direct live websocket stream for web TikTok LIVE clients.

Endpoint

  • hosts:
    • webcast-ws.eu.tiktok.com
    • webcast-ws.us.tiktok.com
    • webcast-ws.tiktok.com
  • method: websocket upgrade
  • path: /webcast/im/ws_proxy/ws_reuse_supplement/

Observed Query Parameters

  • version_code=180800
  • device_platform=web
  • cookie_enabled=true
  • screen_width=1920
  • screen_height=1080
  • browser_language=en-US
  • browser_platform=Linux x86_64
  • browser_name=Mozilla
  • browser_version=5.0 (X11)
  • browser_online=true
  • tz_name=Europe/Bucharest or runtime timezone
  • app_name=tiktok_web
  • sup_ws_ds_opt=1
  • update_version_code=2.0.0
  • compress=gzip
  • webcast_language=en
  • ws_direct=1
  • aid=1988
  • live_id=12
  • second observed version_code=270000
  • app_language=en
  • client_enter=1
  • room_id={room_id}
  • identity=audience
  • history_comment_count=6
  • last_rtt={100-200ish}
  • heartbeat_duration=10000
  • resp_content_type=protobuf
  • did_rule=3

Observed but not currently canonical as required:

  • X-Bogus

Handshake Headers

  • Host
  • Upgrade: websocket
  • Connection: Upgrade
  • Sec-WebSocket-Key
  • Sec-WebSocket-Version: 13
  • User-Agent
  • Referer: https://www.tiktok.com/
  • Origin: https://www.tiktok.com
  • Accept-Language
  • Accept-Encoding
  • Cookie: ttwid=... optionally with extra session cookies appended

Three successful cookie tiers are documented :

  • documented minimum: ttwid alone
  • older successful reduced browser subset: ttwid, tt_chain_token, msToken, sessionid, sid_tt
  • full browser jar in Firefox capture: 26 to 27 cookies

The canonical minimum for current direct web WSS is still ttwid alone.

Confirmed Handshake Outcomes

  • success: HTTP 101 Switching Protocols
  • missing cookie: Handshake-Msg: named cookie not present, Handshake-Status: 417
  • blocked cookie: Handshake-Msg: DEVICE_BLOCKED, Handshake-Status: 415
  • missing aid: Handshake-Msg: illegal app_id, Handshake-Status: 417
  • missing ws_direct=1 or sup_ws_ds_opt=1: Handshake-Msg: illegal secret key, Handshake-Status: 417
  • wrong path such as /webcast/im/fetch/: 404 Not Found

Additional Observations

  • page-captured direct WSS uses no cursor
  • page-captured direct WSS uses no internal_ext
  • page-captured direct WSS uses no msToken in the websocket URL
  • push-server responses are documented with Server: nginx
  • curl-based upgrade testing must use HTTP/1.1; HTTP/2 can obscure valid-upgrade behavior

Initial Client Frames

  • hb
    • payload: HeartbeatMessage { room_id }
    • full builders set outer frame defaults seq_id=0, log_id=0, service=0, method=0, headers={}, payload_encoding="pb"
  • im_enter_room
    • payload: WebcastImEnterRoomMessage { room_id, live_id=12, identity="audience", cursor="", account_type=0, enter_unique_id=0, filter_welcome_msg="0", is_anchor_continue_keep_msg=false }
    • full builders use the same outer defaults as hb
  • ack
    • sent only after server msg frames that carry needs_ack=true and non-empty internal_ext
    • reuses the server frame log_id
    • payload is raw internal_ext bytes

Server Payload Types

  • im_enter_room_resp
  • msg
  • hb

When msg payloads are gzip-compressed protobuf:

  • decode outer WebcastPushFrame
  • decompress payload if gzip magic bytes are present
  • decode WebcastResponse or a closely related lite fetch container
  • if needs_ack and internal_ext exist, send ack

Observed direct-WSS WebcastResponse fields:

  • messages
  • cursor
  • fetch_interval
  • now
  • internal_ext
  • fetch_type
  • route_params_map
  • heart_beat_duration
  • needs_ack
  • push_server
  • is_first
  • history_comment_cursor
  • history_no_more

Stable inner message families already decoded successfully :

  • chat
  • like
  • gift
  • member
  • room viewer sequence
  • social/share
  • live intro
  • control
  • envelope/treasure