Docs
WebSocket Server

WebSocket Server

Use our dead-simple WebSocket server instead of creating your own.

We offer a production-grade WebSocket server at wss:/ws.eulerstream.com. This is the most scalable, stable, and simple way to connect to a TikTok LIVE. Scaling TikTok LIVE connections is hard, so let us do it for you.

Embed a WebSocket client anywhere in 2 minutes tops. No library needed. Combine with JWTs and embed directly into your frontend.

Backend Connections

On a secure backend, use your API Key directly. In Node.JS it's literally 2 lines:

import WebSocket from 'ws';
const ws = new WebSocket(`wss://ws.eulerstream.com?uniqueId=tv_asahi_news&apiKey=${process.env.EULER_API_KEY}`);

There's...nothing else to it. Tutorial over.

Frontend Connections

If you have a client-facing app, you shouldn't be exposing your API Key. Instead, you should use a JSON Web Token to authenticate the connection.

From your backend API, create a JWT for your user, return it to them on the front-end, and they can connect to the WebSocket server with it.

Step 1: Provision a JWT in your backend

For simplicity, I've installed the Euler API SDK so it's even easier to integrate.

  public async createJwt(
      uniqueId: string
  ) {
 
    const createJwtResponse = await this.sdk.authentication.createJWT(Config.SignServer.ACCOUNT_ID, {
      expireAfter: 60, // Short lifetimes are preferred. Users should provision a JWT for each connection, ideally
      websockets: {
        allowedCreators: [uniqueId as string], // Limit the user to the uniqueId they provided so they can't use your JWT to connect to other users
        maxWebSockets: 1 // Limit the user to 1 connection so that they don't eat up your account's concurrent connections
      }
    });
 
    return createJwtResponse.data.token;
  }

Return that to the client from your backend API.

Step 2: Connect to the WebSocket server

const jwtKey = "JWT_KEY"
const uniqueId = "tv_asahi_news";
const ws = new WebSocket(`wss://ws.eulerstream.com?uniqueId=${uniqueId}&jwtKey=${jwtKey}`);

Again, that's it. You can implement this in 2 minutes.

Bonus: TypeScript Types in browser

If you're working with a TypeScript, you can install tiktok-live-connector as a dev-dependency for the TikTok LIVE types. The WebSocket server is 1:1 with the library's types, so you can just drop them in.

Bonus 1: Out-of-the-box Room Info

Room info is sent in the first message of the WebSocket connection. Use this to get info like the user's profile picture, room ID, and more. This comes out-of-the-box with no extra work.

Bonus 2: Access Stream Video

If you want to serve the TikTok LIVE stream video, you can do so with our video endpoint.

Just call /webcast/room_video with the uniqueId of the user, and it will return stream video data.