Skip to content

How a viewer connection flows ​

What happens between a viewer pressing play in TiviMate and the picture showing up.

Both sides of this flow are built and tested end to end on a real server. The URLs and error codes are in the client API reference.

Step by step ​

1. The app logs in. player_api.php answers from a cache built per set of bouquets, already gzipped. Thousands of lines with the same package share one cached answer. When you change the catalog, a revision number goes up and the old cache simply stops being used.

2. The app asks for a channel. The URL carries the line's username and password, because that is how the Xtream protocol works. The control checks the line, the global blocks (IP, country, ASN, user agent), the line's own limits, whether the channel is in its bouquets, and whether the output (TS or HLS) is allowed.

A HEAD request stops here with 200 and no slot. Some apps probe before they play, and that should not cost the viewer a connection.

3. The control reserves a slot. A Lua script in Redis does it in one atomic step. The slot starts as pending and lives 15 seconds. If the same line asks again from the same IP for the same content (a VOD seek, a reconnect), it reuses the slot. If all slots are taken, the line's policy decides: kick_oldest (the default) drops the oldest connection, preferring one from the same IP, so channel zapping works. reject answers 429.

4. The control picks a node and signs a token. It follows the channel's server tree, the node load, weights and limits. The token has the session id, line, channel, format, client IP and a 30 second deadline to open. It is signed with that node's own secret.

5. The control redirects. By default, a 302 to the node, keeping the scheme of the request. ExoPlayer, the player inside most Android IPTV apps, does not follow a redirect from http to https. For a node on the same machine, the control can stream through itself instead (proxy mode). If the channel is on-demand and stopped, the control tells the node to start it at the same moment, so the start and the redirect happen in parallel.

6. The node checks the token alone. No database, no call to the control. It checks the signature, the deadline and the IP (by default the same /24 for IPv4 or /64 for IPv6, skipped when the IP family changes, which is common with dual stack).

7. The viewer gets a clean start. The node sends the latest PAT/PMT and starts at the latest keyframe in memory, so the player never shows a grey or green picture. For HLS, the playlist waits up to 10 seconds for the first segment instead of answering 404.

8. The node reports. It tells the control when sessions start and end, and every 10 seconds sends the full list of live sessions. That list is idempotent: if Redis lost a slot (a restart, say), the control recreates it if there is room, or tells the node to drop the viewer.

Reconnects ​

Players reconnect after a network hiccup, and some reuse the node URL instead of going back to the control. The token's deadline only applies to opening the session. After that, the node accepts the same token while the session is active, plus a 5 minute resume window. One session has at most one TS connection, so a shared link cannot be watched twice: the new connection drops the old one.

When things fail ​

What failsWhat happens
The sourceThe node moves to the next source within seconds. Viewers stay connected. See fallback sources.
A parent node in the treeThe child relays from the grandparent, or the source. See server tree.
RedisNew connections fail closed. Viewers already watching keep watching.
The controlSame: current viewers keep watching. New connections wait for the control.

Bitstream documentation