These are yor variables typically stored in environment variables.
.env
SERVER_REGION=us3
SERVER_PASSWORD=abc123
SERVER_ID=123987
On your client/page, add this code in order to receive events from the server.
The createClientStream function takes an object of arguments. The id and region values are used to identify the server and the token value is used to both authenticate the client and store the channel identifier.
import { createClientStream } from "streamthing";
const res = await fetch("/api/get-streamthing-token");
const data = await res.json();
const stream = createClientStream({
region: process.env.SERVER_REGION,
id: process.env.SERVER_ID,
token: data.token,
});
On your server/API endpoint, add this code in order to send events to the client.
The createServerStream function takes an object of arguments. The id and region values are used to identify the server. The channel is used to identify a certain group of messages all related to something e.g "chat-123". The password value is used to authenticate requests to make a server stream and send messages to the server.
import { createServerStream } from "streamthing";
const stream = createServerStream({
id: process.env.SERVER_ID,
region: process.env.SERVER_REGION,
password: process.env.SERVER_PASSWORD,
channel: "main",
});
region
Used to identify which cluster the server is in
token
Used to authenticate the client
id
Used to identify the server
id
Used to identify the server
region
Used to identify which cluster the server is in
password
Used to authenticate the server
channel
Used to store a group of messages all relating to each other