({ name, sessionId, isHost })
| 90 | const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); |
| 91 | |
| 92 | async function getToken({ name, sessionId, isHost }) { |
| 93 | const resp = await fetch(NEXT_API, { |
| 94 | method: "POST", |
| 95 | headers: { |
| 96 | "content-type": "application/json", |
| 97 | "x-sfu-client": CLIENT_ID, |
| 98 | }, |
| 99 | body: JSON.stringify({ |
| 100 | roomId: ROOM_ID, |
| 101 | sessionId, |
| 102 | user: { name }, |
| 103 | clientId: CLIENT_ID, |
| 104 | isHost: Boolean(isHost), |
| 105 | allowRoomCreation: Boolean(isHost), |
| 106 | }), |
| 107 | }); |
| 108 | if (!resp.ok) { |
| 109 | const text = await resp.text().catch(() => ""); |
| 110 | throw new Error(`token ${resp.status}: ${text.slice(0, 120)}`); |
| 111 | } |
| 112 | const payload = await resp.json().catch(() => null); |
| 113 | if ( |
| 114 | !payload || |
| 115 | typeof payload !== "object" || |
| 116 | typeof payload.token !== "string" || |
| 117 | typeof payload.sfuUrl !== "string" |
| 118 | ) { |
| 119 | throw new Error("token response missing token or sfuUrl"); |
| 120 | } |
| 121 | return payload; |
| 122 | } |
| 123 | |
| 124 | const state = { |
| 125 | attempted: 0, |
no test coverage detected