Skip to content

PirateTok/live-cs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PirateTok

PirateTok.Live

Connect to any TikTok Live stream and receive real-time events in C#. No signing server, no API keys, no authentication required.

// Connect to a live stream — auth and room resolution handled internally
var client = new TikTokLiveClient("username_here");

// Subscribe to events — each carries fully decoded protobuf data
client.OnChat += msg =>
    Console.WriteLine($"[chat] {msg.User?.Nickname}: {msg.Content}");

client.OnGift += msg =>
    Console.WriteLine($"[gift] {msg.User?.Nickname} sent {msg.Gift?.Name} x{msg.RepeatCount} ({msg.Gift?.DiamondCount} diamonds)");

client.OnLike += msg =>
    Console.WriteLine($"[like] {msg.User?.Nickname} ({msg.TotalLikes} total)");

// Blocks until disconnected — handles heartbeat and reconnection automatically
await client.RunAsync();

Install

dotnet add package PirateTok.Live

Targets netstandard2.0 — works with .NET 6+, .NET Framework 4.6.1+, Unity 2021+.

Other languages

Language Install Repo
Rust cargo add piratetok-live-rs live-rs
Go go get github.com/PirateTok/live-go live-go
Python pip install piratetok-live-py live-py
JavaScript npm install piratetok-live-js live-js
Java com.piratetok:live live-java
Lua luarocks install piratetok-live-lua live-lua
Elixir {:piratetok_live, "~> 0.1"} live-ex
Dart dart pub add piratetok_live live-dart
C #include "piratetok.h" live-c
PowerShell Install-Module PirateTok.Live live-ps1
Shell bpkg install PirateTok/live-sh live-sh

Features

  • Zero signing dependency — no API keys, no signing server, no external auth
  • 64 decoded event types — chat, gifts, likes, joins, follows, shares, battles, polls, and more
  • Auto-reconnection — stale detection, exponential backoff, self-healing auth
  • Enriched User data — badges, gifter level, moderator status, follow info, fan club
  • Sub-routed convenience eventsOnFollow, OnShare, OnJoin, OnLiveEnded

Configuration

var client = new TikTokLiveClient("username_here")
    .CdnEU()
    .Timeout(TimeSpan.FromSeconds(15))
    .MaxRetries(10)
    .StaleTimeout(TimeSpan.FromSeconds(90));

Room info (optional, separate call)

// Normal rooms
var info = await TikTokLiveClient.FetchRoomInfoAsync(
    "ROOM_ID",
    TimeSpan.FromSeconds(10));

// 18+ rooms — pass session cookies from browser DevTools
var info = await TikTokLiveClient.FetchRoomInfoAsync(
    "ROOM_ID",
    TimeSpan.FromSeconds(10),
    cookies: "sessionid=abc; sid_tt=abc");

How it works

  1. Resolves username to room ID via TikTok JSON API
  2. Authenticates and opens a direct WSS connection
  3. Protobuf heartbeats every 10s
  4. Decodes protobuf stream into typed C# objects via protobuf-net
  5. Auto-reconnects on stale/dropped connections with fresh credentials

Examples

dotnet run --project examples/BasicChat -- <username>       # connect + print chat events
dotnet run --project examples/OnlineCheck -- <username>     # check if user is live
dotnet run --project examples/StreamInfo -- <username>      # fetch room metadata + stream URLs
dotnet run --project examples/GiftTracker -- <username>     # track gifts with diamond totals

Known gaps

  • Proxy(...) exists on the client surface, but proxy transport plumbing is not wired into HttpClient or ClientWebSocket yet.
  • Explicit DEVICE_BLOCKED handshake handling is not implemented yet.

License

0BSD

About

TikTok Live WebSocket connector for C#/.NET — real-time chat, gifts, likes, viewer events. No API keys required.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages