@profullstack/group-call 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -52,6 +52,9 @@ await line.handle(JSON.parse(rawBody).data);
52
52
  Telnyx bills this per minute per leg, so it's off unless you ask for it.
53
53
  - **Survives restarts.** Conference names carry a keyed hash of the room code. After a restart,
54
54
  the first caller into a room joins its running conference, not a new one.
55
+ - **Deploy-proof rooms.** Save `participants(code)` plus each room's conference id from `onJoin`/`onLeave`,
56
+ and pass them to `restore()` at boot. Each conference is checked against Telnyx, and the legs still in
57
+ it come back with their names, so a restart neither splits a room nor forgets who is in it.
55
58
  - `telnyxSms`, `verifyTelnyx`, `newRoomCode`, `sameSecret` helpers.
56
59
 
57
60
  MIT
package/dist/index.d.ts CHANGED
@@ -198,6 +198,21 @@ export declare class GroupCall {
198
198
  callers: number;
199
199
  startedAt: number;
200
200
  }[];
201
+ /**
202
+ * Put back rooms a previous process knew about: a deploy or a crash must not
203
+ * split a room. Each saved conference is checked against Telnyx, and only the
204
+ * legs still in it come back, with their names. A leg Telnyx has that the save
205
+ * missed comes back unnamed. Returns how many rooms and legs were restored.
206
+ */
207
+ restore(saved: {
208
+ code: string;
209
+ conferenceId: string;
210
+ startedAt: number;
211
+ participants: Participant[];
212
+ }[]): Promise<{
213
+ rooms: number;
214
+ legs: number;
215
+ }>;
201
216
  /** Who is on the line in a room, earliest first. */
202
217
  participants(code: string): Participant[];
203
218
  /**
package/dist/index.js CHANGED
@@ -199,6 +199,42 @@ export class GroupCall {
199
199
  .map(({ code, callers, startedAt }) => ({ code, callers, startedAt }))
200
200
  .sort((a, b) => b.callers - a.callers || a.startedAt - b.startedAt);
201
201
  }
202
+ /**
203
+ * Put back rooms a previous process knew about: a deploy or a crash must not
204
+ * split a room. Each saved conference is checked against Telnyx, and only the
205
+ * legs still in it come back, with their names. A leg Telnyx has that the save
206
+ * missed comes back unnamed. Returns how many rooms and legs were restored.
207
+ */
208
+ async restore(saved) {
209
+ let rooms = 0;
210
+ let legs = 0;
211
+ for (const r of saved) {
212
+ const conf = (await this.get(`/conferences/${encodeURIComponent(r.conferenceId)}`));
213
+ if (!conf?.data || (conf.data.status && conf.data.status !== "in_progress"))
214
+ continue;
215
+ const list = (await this.get(`/conferences/${encodeURIComponent(r.conferenceId)}/participants?page[size]=100`));
216
+ const present = new Set((list?.data ?? []).filter((p) => p.status !== "left" && typeof p.call_control_id === "string").map((p) => p.call_control_id));
217
+ if (present.size === 0)
218
+ continue;
219
+ const room = this.room(r.code);
220
+ room.conferenceId = r.conferenceId;
221
+ room.startedAt = r.startedAt;
222
+ const known = new Map(r.participants.map((p) => [p.leg, p]));
223
+ for (const leg of present) {
224
+ const who = known.get(leg) ?? { leg, from: "", name: "", joinedAt: r.startedAt };
225
+ room.legs.set(leg, who);
226
+ this.legRoom.set(leg, r.code);
227
+ if (who.from)
228
+ this.legFrom.set(leg, who.from);
229
+ legs += 1;
230
+ }
231
+ room.callers = room.legs.size;
232
+ rooms += 1;
233
+ }
234
+ if (rooms)
235
+ this.options.onEvent?.(` restored ${rooms} room(s) with ${legs} on the line.`);
236
+ return { rooms, legs };
237
+ }
202
238
  /** Who is on the line in a room, earliest first. */
203
239
  participants(code) {
204
240
  const room = this.rooms.get(code);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@profullstack/group-call",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "A group call on a phone number: dial in, key a room code, talk with everyone else who did, people and AI agents alike. Telnyx Call Control state machine extracted from nixamp's party line; the engine behind nixamp live joins and group.call.pit.world.",
5
5
  "license": "MIT",
6
6
  "type": "module",