Quickstart
From an account to a live phone camera
Install the SDK, create a session, scan a QR code.
Install the example, start it, and scan the QR code with a phone. The API key stays on the server. The phone and the viewer use hosted PeerKit pages. Record, Chat, Share, Voice, and Call, including Voice Core and Call Core, are available as JavaScript, Web Components, and React on the components page.
npm package
@peerkit-dev/sdk version 0.1.6 is on the npm registry. The example pins that version in package-lock.json.
Prerequisites
Node.js 22 or newer, a phone with a camera, and a browser on this computer. No Docker, database, or media server is required.
Account and organization
- Create an account at peerkit.dev/sign-up.
- Open the dashboard and create or select an organization. PeerKit rejects a signed-in user who has none.
- Opening the dashboard creates that organization's project.
New organizations start on Free: 60 streaming minutes each UTC month, one open session, and at most 15 minutes per session. See pricing for Starter and Pro.
API key
- Open API keys.
- Name the key and create it. Copy the secret when it appears. PeerKit stores only a hash, so it cannot be shown again.
- Put that secret in the example
.envasPEERKIT_API_KEY. Send it only from your server, asAuthorization: Bearer pk_live_….
API keys and participant tokens
A server API key authorizes the Node process. It starts with pk_live_. It never belongs in a browser, a phone page, or a client bundle.
A participant token is short-lived. The phone and the hosted viewer receive it by opening https://peerkit.dev/s with the invitation secret in the URL fragment. That token is not an API key. The example page does not join the session.
Download and configure
- Unzip it into an empty folder.
- Copy
.env.exampleto.env. - Set
PEERKIT_API_KEY. LeavePEERKIT_API_URL=https://api.peerkit.dev. Invitation pages are hosted athttps://peerkit.dev/s.
Start
From the example folder:
npm ci npm start
Open http://127.0.0.1:4010 on this computer. The phone opens the hosted invitation from the QR code.
Phone
- Enter an optional session name, up to 100 characters. It is a label, not part of the invitation.
- Leave one-way microphone audio unchecked for video only. Check it to allow the phone to publish its microphone. The phone asks for permission only after Enable microphone. The viewer does not send audio back.
- Click Create session.
- Scan the QR code, allow the camera, and tap Start. If the session includes audio, tap Enable microphone and allow it.
- Click Open viewer on this computer.
- Click End session when you are done so the open-session slot is free.
Restarting the example reuses an open session. After End session, or after the session expires, Create session replaces the QR code and the viewer link. A missing API key stops the process before it listens.
Server code
This is the whole server call. Omit name to leave the session unnamed. Omit audio for video only. The example lets PeerKit choose the duration, so a Free session stays within 15 minutes.
import { PeerKit } from "@peerkit-dev/sdk/server";
const apiKey = process.env.PEERKIT_API_KEY;
if (!apiKey) throw new Error("Missing PEERKIT_API_KEY");
const peerkit = new PeerKit({
apiKey,
apiUrl: "https://api.peerkit.dev",
});
const session = await peerkit.createSession({
name: "Loading dock",
audio: true,
});
const camera = await peerkit.createInvitation(session.id, "publisher");
const viewer = await peerkit.createInvitation(session.id, "viewer");Data — Messaging & File Transfer
The downloaded example stays on the camera path. A data session uses the same server client with media: "data". It does not request a camera or microphone. Both people can send text messages, binary data, and files. Call acceptFile only after the person chooses to receive the file.
import { PeerKitSession } from "@peerkit-dev/sdk";
const session = await peerkit.createSession({ media: "data", name: "File Transfer" });
const first = await peerkit.createInvitation(session.id, "publisher");
const second = await peerkit.createInvitation(session.id, "viewer");
const data = new PeerKitSession({
signalingUrl: access.signalingUrl,
token: access.participantToken,
media: "data",
});
data.on((event) => {
if (event.type === "dataMessage" && typeof event.data === "string") console.log(event.data);
if (event.type === "fileTransfer" && event.transfer.status === "incoming") showIncoming(event.transfer);
if (event.type === "fileTransfer" && event.transfer.status === "complete" && event.transfer.direction === "receive") {
const blob = data.receivedFile(event.transfer.id);
console.log(blob?.size, event.transfer.name);
}
});
await data.connect();
data.sendText("ready");
data.sendFile(file);
data.acceptFile(incomingId);Voice Core
@peerkit-dev/voice-core is Voice Core: VoiceController for vanilla JavaScript and the <peerkit-voice> element. @peerkit-dev/voice is the React component and depends on that core. Create the session with media: "audio". Call start() from a click so the browser can request the microphone and play remote audio. A session you pass in stays connected on end unless you set disconnectOnEnd. Full examples are on the Voice component page.
import { VoiceController } from "@peerkit-dev/voice-core";
const call = new VoiceController(() => ({
invitationUrl: "https://peerkit.dev/s#inv_…",
}));
call.attachAudio(document.querySelector("audio"));
call.sync();
document.querySelector("#start")?.addEventListener("click", () => {
void call.start();
});Call Core
@peerkit-dev/call-core is Call Core: CallController for vanilla JavaScript and the <peerkit-call> element. @peerkit-dev/call is the React component and depends on that core. Create the session with media: "call". Call start() from a click so the browser can request the camera and microphone. A session you pass in stays connected on end unless you set disconnectOnEnd. Screen sharing does not send system audio. Full examples are on the Call component page.
import { CallController } from "@peerkit-dev/call-core";
const call = new CallController(() => ({
invitationUrl: "https://peerkit.dev/s#inv_…",
}));
call.attachPreview(document.querySelector("#preview"));
call.attachRemoteVideo(document.querySelector("#remote"));
call.attachAudio(document.querySelector("audio"));
call.sync();
document.querySelector("#start")?.addEventListener("click", () => {
void call.start();
});