Generating tokens
Creating tokens
To create a token use the createToken function
import { createToken } from "streamthing";
const token = await createToken({
id: process.env.SERVER_ID,
channel: "main",
password: process.env.SERVER_PASSWORD,
socketID,
});
return token;
Warning
Generating tokens should only ever happen on the server to avoid leaking sensitive information to the client
Full example
import { createToken } from "streamthing";
// api/get-streamthing-token
const token = await createToken({
id: process.env.SERVER_ID,
channel: "main",
password: process.env.SERVER_PASSWORD,
socketID,
});
return token;
// Somewhere on the client
const stream = await createClientStream(process.env.SERVER_REGION);
const res = await fetch("/api/get-streamthing-token?id=" + stream.id);
const data = await res.json();
createToken()
id
String. The server ID used to create the token
channel
String. The desired channel
socketID
String. The socket ID used to create the token
password
String. The server password used to create the token