-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrealtime-session.mjs
More file actions
33 lines (29 loc) · 920 Bytes
/
Copy pathrealtime-session.mjs
File metadata and controls
33 lines (29 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { randomUUID } from "node:crypto";
import { BeatAPIClient, BeatAPIError } from "./lib/beatapi.mjs";
const client = new BeatAPIClient();
try {
const session = await client.createRealtimeSession(
{
max_duration_seconds: 60,
allowed_origins: ["https://app.example.com"],
metadata: { example: "node" },
},
{ idempotencyKey: randomUUID() },
);
console.log(JSON.stringify({
id: session.id,
status: session.status,
expires_at: session.expires_at,
client_secret_received: Boolean(session.client_secret),
}, null, 2));
console.log("Return client_secret only to the exact allowed browser origin; do not log it.");
} catch (error) {
if (error instanceof BeatAPIError) {
console.error(
`[${error.status}] ${error.code}: ${error.message} (${error.requestId || "no request id"})`,
);
} else {
console.error(error);
}
process.exitCode = 1;
}