@relaymessenger/sdk 0.3.6-staging.9 → 0.3.7-staging.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.
Files changed (80) hide show
  1. package/README.md +516 -29
  2. package/dist/a2ui.d.ts +111 -0
  3. package/dist/a2ui.d.ts.map +1 -0
  4. package/dist/a2ui.js +137 -0
  5. package/dist/a2ui.js.map +1 -0
  6. package/dist/calls/call-room.d.ts +110 -0
  7. package/dist/calls/call-room.d.ts.map +1 -0
  8. package/dist/calls/call-room.js +616 -0
  9. package/dist/calls/call-room.js.map +1 -0
  10. package/dist/calls/engine-werift-video.d.ts +83 -0
  11. package/dist/calls/engine-werift-video.d.ts.map +1 -0
  12. package/dist/calls/engine-werift-video.js +607 -0
  13. package/dist/calls/engine-werift-video.js.map +1 -0
  14. package/dist/calls/engine-werift.d.ts +48 -0
  15. package/dist/calls/engine-werift.d.ts.map +1 -0
  16. package/dist/calls/engine-werift.js +462 -0
  17. package/dist/calls/engine-werift.js.map +1 -0
  18. package/dist/calls/index.d.ts +11 -0
  19. package/dist/calls/index.d.ts.map +1 -0
  20. package/dist/calls/index.js +11 -0
  21. package/dist/calls/index.js.map +1 -0
  22. package/dist/calls/transport.d.ts +466 -0
  23. package/dist/calls/transport.d.ts.map +1 -0
  24. package/dist/calls/transport.js +1409 -0
  25. package/dist/calls/transport.js.map +1 -0
  26. package/dist/calls/video-frame.d.ts +56 -0
  27. package/dist/calls/video-frame.d.ts.map +1 -0
  28. package/dist/calls/video-frame.js +245 -0
  29. package/dist/calls/video-frame.js.map +1 -0
  30. package/dist/calls/video-presets.d.ts +39 -0
  31. package/dist/calls/video-presets.d.ts.map +1 -0
  32. package/dist/calls/video-presets.js +40 -0
  33. package/dist/calls/video-presets.js.map +1 -0
  34. package/dist/calls/video-rtp.d.ts +51 -0
  35. package/dist/calls/video-rtp.d.ts.map +1 -0
  36. package/dist/calls/video-rtp.js +294 -0
  37. package/dist/calls/video-rtp.js.map +1 -0
  38. package/dist/calls/video.d.ts +195 -0
  39. package/dist/calls/video.d.ts.map +1 -0
  40. package/dist/calls/video.js +228 -0
  41. package/dist/calls/video.js.map +1 -0
  42. package/dist/client.d.ts +199 -1
  43. package/dist/client.d.ts.map +1 -1
  44. package/dist/client.js +444 -0
  45. package/dist/client.js.map +1 -1
  46. package/dist/errors.d.ts +11 -0
  47. package/dist/errors.d.ts.map +1 -1
  48. package/dist/errors.js +16 -0
  49. package/dist/errors.js.map +1 -1
  50. package/dist/index.d.ts +7 -2
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +7 -2
  53. package/dist/index.js.map +1 -1
  54. package/dist/links.d.ts +17 -6
  55. package/dist/links.d.ts.map +1 -1
  56. package/dist/links.js +35 -4
  57. package/dist/links.js.map +1 -1
  58. package/dist/operations.d.ts +97 -1
  59. package/dist/operations.d.ts.map +1 -1
  60. package/dist/operations.js +129 -0
  61. package/dist/operations.js.map +1 -1
  62. package/dist/payment.d.ts +67 -0
  63. package/dist/payment.d.ts.map +1 -0
  64. package/dist/payment.js +147 -0
  65. package/dist/payment.js.map +1 -0
  66. package/dist/reply-target.d.ts +26 -0
  67. package/dist/reply-target.d.ts.map +1 -0
  68. package/dist/reply-target.js +59 -0
  69. package/dist/reply-target.js.map +1 -0
  70. package/dist/selection.d.ts +46 -0
  71. package/dist/selection.d.ts.map +1 -0
  72. package/dist/selection.js +142 -0
  73. package/dist/selection.js.map +1 -0
  74. package/dist/types.d.ts +1113 -22
  75. package/dist/types.d.ts.map +1 -1
  76. package/dist/websocket.d.ts +6 -0
  77. package/dist/websocket.d.ts.map +1 -1
  78. package/dist/websocket.js +36 -10
  79. package/dist/websocket.js.map +1 -1
  80. package/package.json +37 -2
package/dist/a2ui.d.ts ADDED
@@ -0,0 +1,111 @@
1
+ import type { Relay } from "./client.js";
2
+ import type { A2uiAction, A2uiBrowserActionName, A2uiBrowserComponent, A2uiComponent, A2uiCreateSurfaceMessage, A2uiMessage, A2uiServerToClientMessage, DataPart, MessageContent, MessageSendResponse, MessageWebhookData, RelayWebhookEvent, RequestOptions } from "./types.js";
3
+ /** The `media_type` of a data part that carries A2UI messages. */
4
+ export declare const A2UI_MEDIA_TYPE = "application/a2ui+json";
5
+ /** The A2UI version every message these helpers write carries. */
6
+ export declare const A2UI_VERSION = "v0.9.1";
7
+ /** A2UI v0.9.1's basic catalog, by the `catalogId` its catalog file declares. */
8
+ export declare const A2UI_BASIC_CATALOG_ID = "https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json";
9
+ /** Relay's catalog: every basic catalog component and function, plus `PaymentRequest` and `Browser`. */
10
+ export declare const RELAY_A2UI_CATALOG_ID = "https://relayapp.im/a2ui/catalog/v1";
11
+ /**
12
+ * The taps a Browser card sends to the agent that created it, as an A2UI
13
+ * `action` whose `sourceComponentId` is the Browser's id and whose `context`
14
+ * is empty: "Take control of the browser", "Finish up" and "Stop the task".
15
+ * Pause your browser work from `takeControl` until `returnControl`; end the
16
+ * task on `stop`.
17
+ */
18
+ export declare const A2UI_BROWSER_ACTIONS: {
19
+ readonly takeControl: "browser.takeControl";
20
+ readonly returnControl: "browser.returnControl";
21
+ readonly stop: "browser.stop";
22
+ };
23
+ /** Whether a tap's `name` is one of a Browser card's taps. */
24
+ export declare const isA2uiBrowserAction: (name: string) => name is A2uiBrowserActionName;
25
+ /** A Browser card's properties: everything but `id` and `component`. */
26
+ export type A2uiBrowserCard = Omit<A2uiBrowserComponent, "id" | "component">;
27
+ /** The Browser component a card draws, with the id `root` unless another is given. */
28
+ export declare const a2uiBrowserComponent: (card: A2uiBrowserCard, id?: string) => A2uiBrowserComponent;
29
+ /**
30
+ * The A2UI message that changes a Browser card in place: `updateComponents`
31
+ * replaces the whole component by id, so `card` is the card as it should now
32
+ * be drawn, for example `{ ...card, state: "needs_you", status: "Blocked ·
33
+ * Waiting for confirmation" }`. A bound property changes with
34
+ * `updateA2uiSurface`'s `dataModel` instead.
35
+ */
36
+ export declare const a2uiBrowserCardUpdate: (surfaceId: string, card: A2uiBrowserCard) => A2uiServerToClientMessage;
37
+ /**
38
+ * The A2UI messages of a new Browser card in Relay's catalog: `createSurface`,
39
+ * then `updateComponents` with the Browser as `root`, then, when `dataModel`
40
+ * is given (for bound properties), `updateDataModel` for the whole model.
41
+ */
42
+ export declare const a2uiBrowserCardMessages: (surfaceId: string, card: A2uiBrowserCard, dataModel?: Record<string, unknown>) => A2uiServerToClientMessage[];
43
+ /** A card: the surface to create, its components, and, optionally, its first data model. */
44
+ export interface A2uiSurface {
45
+ surfaceId: string;
46
+ /** A catalog Relay draws: `A2UI_BASIC_CATALOG_ID` or `RELAY_A2UI_CATALOG_ID`. */
47
+ catalogId: string;
48
+ /** Every component of the card; one has the id `root`. The catalog defines each component and property. */
49
+ components: A2uiComponent[];
50
+ /** The whole data model, sent as an `updateDataModel` with no `path`. */
51
+ dataModel?: Record<string, unknown>;
52
+ theme?: A2uiCreateSurfaceMessage["createSurface"]["theme"];
53
+ sendDataModel?: boolean;
54
+ }
55
+ /**
56
+ * A change to a card that is already in the chat: components to add or
57
+ * replace by id, and a data model value to set at `path` (a JSON Pointer; no
58
+ * `path` is the whole data model; no `value` removes the key at `path`).
59
+ */
60
+ export interface A2uiSurfaceUpdate {
61
+ components?: A2uiComponent[];
62
+ dataModel?: {
63
+ path?: string;
64
+ value?: unknown;
65
+ };
66
+ }
67
+ /**
68
+ * The rest of the Message beside the data part. `text` becomes a text part
69
+ * before it; the chat list and notification show it. With no text, they show
70
+ * the card's first `Text` component. A text beside an update is a new Message,
71
+ * and the update still changes the card in place.
72
+ */
73
+ export type A2uiSendOptions = Omit<MessageContent, "parts"> & {
74
+ text?: string;
75
+ };
76
+ /** A tap read out of `message.received`. */
77
+ export interface A2uiTap {
78
+ action: A2uiAction;
79
+ /** The tapped surface's data model, present when the surface set `sendDataModel`. */
80
+ dataModel?: Record<string, unknown>;
81
+ }
82
+ /** Wraps A2UI messages in the data part Relay carries them in. */
83
+ export declare const a2uiPart: (messages: A2uiMessage[]) => DataPart;
84
+ /**
85
+ * Sends a new card into a chat: `createSurface`, `updateComponents` and, when
86
+ * `dataModel` is given, `updateDataModel`, in one data part. Messages Relay
87
+ * could not apply come back in `a2ui_errors` (`A2uiFailure`); a send it could
88
+ * not apply at all throws a `RelayAPIError` whose `body.a2ui_errors` lists each.
89
+ */
90
+ export declare const sendA2uiSurface: (client: Pick<Relay, "chats">, chatID: string, surface: A2uiSurface, message?: A2uiSendOptions, options?: RequestOptions) => Promise<MessageSendResponse>;
91
+ /**
92
+ * Changes a card already in the chat, in place, for every member. With no
93
+ * `text`, the send adds no Message and returns the card's own Message. Any
94
+ * agent in the chat may update any surface in it.
95
+ */
96
+ export declare const updateA2uiSurface: (client: Pick<Relay, "chats">, chatID: string, surfaceId: string, update: A2uiSurfaceUpdate, message?: A2uiSendOptions, options?: RequestOptions) => Promise<MessageSendResponse>;
97
+ /**
98
+ * Removes a card for everyone. When every surface a Message draws is deleted,
99
+ * the Message reads back with no parts and a non-null `unsent_at`. The
100
+ * `surfaceId` may be created again afterwards.
101
+ */
102
+ export declare const deleteA2uiSurface: (client: Pick<Relay, "chats">, chatID: string, surfaceId: string, message?: A2uiSendOptions, options?: RequestOptions) => Promise<MessageSendResponse>;
103
+ /**
104
+ * Reads the first A2UI `action` out of a `message.received` event (a signed
105
+ * webhook or a WebSocket event), or out of its `data`. Returns null for any
106
+ * other event and for a Message that carries no tap. When the surface set
107
+ * `sendDataModel`, `dataModel` is that surface's model from
108
+ * `metadata.a2uiClientDataModel`.
109
+ */
110
+ export declare const readA2uiAction: (event: RelayWebhookEvent | MessageWebhookData) => A2uiTap | null;
111
+ //# sourceMappingURL=a2ui.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"a2ui.d.ts","sourceRoot":"","sources":["../src/a2ui.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EACV,UAAU,EACV,qBAAqB,EAC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EACd,WAAW,MAAM,EACjB,UAAU,eAAe,EACzB,UAAU,cAAc,KACvB,OAAO,CAAC,mBAAmB,CACqE,CAAC;AAEpG;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,GACzB,OAAO,iBAAiB,GAAG,kBAAkB,KAC5C,OAAO,GAAG,IAkBZ,CAAC"}
package/dist/a2ui.js ADDED
@@ -0,0 +1,137 @@
1
+ /** The `media_type` of a data part that carries A2UI messages. */
2
+ export const A2UI_MEDIA_TYPE = "application/a2ui+json";
3
+ /** The A2UI version every message these helpers write carries. */
4
+ export const A2UI_VERSION = "v0.9.1";
5
+ /** A2UI v0.9.1's basic catalog, by the `catalogId` its catalog file declares. */
6
+ export const A2UI_BASIC_CATALOG_ID = "https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json";
7
+ /** Relay's catalog: every basic catalog component and function, plus `PaymentRequest` and `Browser`. */
8
+ export const RELAY_A2UI_CATALOG_ID = "https://relayapp.im/a2ui/catalog/v1";
9
+ /**
10
+ * The taps a Browser card sends to the agent that created it, as an A2UI
11
+ * `action` whose `sourceComponentId` is the Browser's id and whose `context`
12
+ * is empty: "Take control of the browser", "Finish up" and "Stop the task".
13
+ * Pause your browser work from `takeControl` until `returnControl`; end the
14
+ * task on `stop`.
15
+ */
16
+ export const A2UI_BROWSER_ACTIONS = {
17
+ takeControl: "browser.takeControl",
18
+ returnControl: "browser.returnControl",
19
+ stop: "browser.stop",
20
+ };
21
+ /** Whether a tap's `name` is one of a Browser card's taps. */
22
+ export const isA2uiBrowserAction = (name) => Object.values(A2UI_BROWSER_ACTIONS).includes(name);
23
+ /** The Browser component a card draws, with the id `root` unless another is given. */
24
+ export const a2uiBrowserComponent = (card, id = "root") => ({ id, component: "Browser", ...card });
25
+ /**
26
+ * The A2UI message that changes a Browser card in place: `updateComponents`
27
+ * replaces the whole component by id, so `card` is the card as it should now
28
+ * be drawn, for example `{ ...card, state: "needs_you", status: "Blocked ·
29
+ * Waiting for confirmation" }`. A bound property changes with
30
+ * `updateA2uiSurface`'s `dataModel` instead.
31
+ */
32
+ export const a2uiBrowserCardUpdate = (surfaceId, card) => ({ version: A2UI_VERSION, updateComponents: { surfaceId, components: [a2uiBrowserComponent(card)] } });
33
+ /**
34
+ * The A2UI messages of a new Browser card in Relay's catalog: `createSurface`,
35
+ * then `updateComponents` with the Browser as `root`, then, when `dataModel`
36
+ * is given (for bound properties), `updateDataModel` for the whole model.
37
+ */
38
+ export const a2uiBrowserCardMessages = (surfaceId, card, dataModel) => {
39
+ const messages = [
40
+ { version: A2UI_VERSION, createSurface: { surfaceId, catalogId: RELAY_A2UI_CATALOG_ID } },
41
+ a2uiBrowserCardUpdate(surfaceId, card),
42
+ ];
43
+ if (dataModel !== undefined)
44
+ messages.push({ version: A2UI_VERSION, updateDataModel: { surfaceId, value: dataModel } });
45
+ return messages;
46
+ };
47
+ /** Wraps A2UI messages in the data part Relay carries them in. */
48
+ export const a2uiPart = (messages) => ({
49
+ type: "data",
50
+ media_type: A2UI_MEDIA_TYPE,
51
+ data: messages,
52
+ });
53
+ const send = (client, chatID, messages, { text, ...message } = {}, options) => {
54
+ const parts = text === undefined
55
+ ? [a2uiPart(messages)]
56
+ : [{ type: "text", value: text }, a2uiPart(messages)];
57
+ return client.chats.messages.send(chatID, { message: { ...message, parts } }, options);
58
+ };
59
+ /**
60
+ * Sends a new card into a chat: `createSurface`, `updateComponents` and, when
61
+ * `dataModel` is given, `updateDataModel`, in one data part. Messages Relay
62
+ * could not apply come back in `a2ui_errors` (`A2uiFailure`); a send it could
63
+ * not apply at all throws a `RelayAPIError` whose `body.a2ui_errors` lists each.
64
+ */
65
+ export const sendA2uiSurface = (client, chatID, surface, message, options) => {
66
+ const { surfaceId, catalogId, components, dataModel, theme, sendDataModel } = surface;
67
+ const messages = [
68
+ {
69
+ version: A2UI_VERSION,
70
+ createSurface: {
71
+ surfaceId,
72
+ catalogId,
73
+ ...(theme === undefined ? {} : { theme }),
74
+ ...(sendDataModel === undefined ? {} : { sendDataModel }),
75
+ },
76
+ },
77
+ { version: A2UI_VERSION, updateComponents: { surfaceId, components } },
78
+ ];
79
+ if (dataModel !== undefined) {
80
+ messages.push({ version: A2UI_VERSION, updateDataModel: { surfaceId, value: dataModel } });
81
+ }
82
+ return send(client, chatID, messages, message, options);
83
+ };
84
+ /**
85
+ * Changes a card already in the chat, in place, for every member. With no
86
+ * `text`, the send adds no Message and returns the card's own Message. Any
87
+ * agent in the chat may update any surface in it.
88
+ */
89
+ export const updateA2uiSurface = (client, chatID, surfaceId, update, message, options) => {
90
+ const messages = [];
91
+ if (update.components !== undefined) {
92
+ messages.push({ version: A2UI_VERSION, updateComponents: { surfaceId, components: update.components } });
93
+ }
94
+ if (update.dataModel !== undefined) {
95
+ messages.push({ version: A2UI_VERSION, updateDataModel: { surfaceId, ...update.dataModel } });
96
+ }
97
+ if (!messages.length)
98
+ throw new Error("an update needs components or a dataModel");
99
+ return send(client, chatID, messages, message, options);
100
+ };
101
+ /**
102
+ * Removes a card for everyone. When every surface a Message draws is deleted,
103
+ * the Message reads back with no parts and a non-null `unsent_at`. The
104
+ * `surfaceId` may be created again afterwards.
105
+ */
106
+ export const deleteA2uiSurface = (client, chatID, surfaceId, message, options) => send(client, chatID, [{ version: A2UI_VERSION, deleteSurface: { surfaceId } }], message, options);
107
+ /**
108
+ * Reads the first A2UI `action` out of a `message.received` event (a signed
109
+ * webhook or a WebSocket event), or out of its `data`. Returns null for any
110
+ * other event and for a Message that carries no tap. When the surface set
111
+ * `sendDataModel`, `dataModel` is that surface's model from
112
+ * `metadata.a2uiClientDataModel`.
113
+ */
114
+ export const readA2uiAction = (event) => {
115
+ let data;
116
+ if ("event_type" in event) {
117
+ if (event.event_type !== "message.received")
118
+ return null;
119
+ data = event.data;
120
+ }
121
+ else {
122
+ data = event;
123
+ }
124
+ for (const part of data.parts ?? []) {
125
+ if (part.type !== "data" || part.media_type !== A2UI_MEDIA_TYPE)
126
+ continue;
127
+ for (const message of part.data) {
128
+ if (typeof message !== "object" || message === null || !("action" in message))
129
+ continue;
130
+ const { action } = message;
131
+ const dataModel = data.metadata?.a2uiClientDataModel?.surfaces[action.surfaceId];
132
+ return dataModel === undefined ? { action } : { action, dataModel };
133
+ }
134
+ }
135
+ return null;
136
+ };
137
+ //# sourceMappingURL=a2ui.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"a2ui.js","sourceRoot":"","sources":["../src/a2ui.ts"],"names":[],"mappings":"AAkBA,kEAAkE;AAClE,MAAM,CAAC,MAAM,eAAe,GAAG,uBAAuB,CAAC;AAEvD,kEAAkE;AAClE,MAAM,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC;AAErC,iFAAiF;AACjF,MAAM,CAAC,MAAM,qBAAqB,GAAG,iEAAiE,CAAC;AAEvG,wGAAwG;AACxG,MAAM,CAAC,MAAM,qBAAqB,GAAG,qCAAqC,CAAC;AAE3E;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,WAAW,EAAE,qBAAqB;IAClC,aAAa,EAAE,uBAAuB;IACtC,IAAI,EAAE,cAAc;CACoC,CAAC;AAE3D,8DAA8D;AAC9D,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,IAAY,EAAiC,EAAE,CAChF,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAc,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAKnE,sFAAsF;AACtF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,IAAqB,EAAE,EAAE,GAAG,MAAM,EAAwB,EAAE,CAC/F,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;AAE1C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,SAAiB,EAAE,IAAqB,EAA6B,EAAE,CAC3G,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,oBAA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QACpC,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,UAAU,KAAK,eAAe;YAAE,SAAS;QAC1E,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YAChC,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,IAAI,CAAC,CAAC,QAAQ,IAAI,OAAO,CAAC;gBAAE,SAAS;YACxF,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;YAC3B,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,EAAE,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YACjF,OAAO,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;QACtE,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
@@ -0,0 +1,110 @@
1
+ import type { CallRoomClientFrame, CallRoomEndedFrame, CallRoomErrorFrame, CallRoomIceServer, CallRoomIceServersFrame, CallRoomServerAnswerFrame, CallRoomServerFrame, CallRoomStateFrame, CallRoomSubscriptionOfferFrame } from "../types.js";
2
+ import type { WebSocketConstructor } from "../websocket.js";
3
+ export interface CallRoomOptions {
4
+ /** Abort closes the signaling socket without ending the Call. */
5
+ signal?: AbortSignal;
6
+ /** Override the Node WebSocket implementation, primarily for tests. */
7
+ WebSocket?: WebSocketConstructor;
8
+ /** Client heartbeat cadence. Relay's room heartbeat frame has no payload. */
9
+ heartbeatIntervalMs?: number;
10
+ /**
11
+ * Called once per unknown server frame type, which the room ignores.
12
+ * Defaults to `console.warn`.
13
+ */
14
+ onWarning?: (message: string) => void;
15
+ }
16
+ export interface CallRoomCloseEvent {
17
+ code: number;
18
+ reason: string;
19
+ wasClean: boolean;
20
+ }
21
+ /**
22
+ * The room socket dropped, or an attempt to open one failed, and the room
23
+ * opens a new one after `delayMs`. Media rides the SFU, not this socket, so the
24
+ * Call and its WebRTC session continue; nothing is re-offered.
25
+ */
26
+ export interface CallRoomReconnectingEvent {
27
+ /** 1 for the first retry; the count resets once a socket stays open 5 s. */
28
+ attempt: number;
29
+ delayMs: number;
30
+ /** The close that caused the retry; absent when an attempt failed before opening. */
31
+ close?: CallRoomCloseEvent;
32
+ /** Why the failed attempt did not open (connect timeout, handshake error). */
33
+ error?: Error;
34
+ }
35
+ export type CallRoomConnectionState = "idle" | "connecting" | "open" | "reconnecting" | "closed";
36
+ export type CallRoomEventMap = {
37
+ open: [];
38
+ reconnecting: [CallRoomReconnectingEvent];
39
+ /** The room's STUN/TURN servers, sent after every accepted `join`, before its `roomState`. */
40
+ iceServers: [CallRoomIceServersFrame];
41
+ roomState: [CallRoomStateFrame];
42
+ offer: [CallRoomSubscriptionOfferFrame];
43
+ answer: [CallRoomServerAnswerFrame];
44
+ ended: [CallRoomEndedFrame];
45
+ error: [CallRoomErrorFrame | Error];
46
+ /** The room socket closed and the room will not reopen it by itself. */
47
+ close: [CallRoomCloseEvent];
48
+ };
49
+ type CallRoomEvent = keyof CallRoomEventMap;
50
+ type Listener<K extends CallRoomEvent> = (...args: CallRoomEventMap[K]) => void;
51
+ /**
52
+ * Validate one server frame before exposing it to application code. Returns
53
+ * `null` for Relay's echoed heartbeat (not part of the public server-frame
54
+ * union) and for a frame type this client does not know (a newer Relay's
55
+ * frame, ignored). Throws for a known frame type whose shape is invalid.
56
+ */
57
+ export declare const parseCallRoomServerFrame: (value: unknown) => CallRoomServerFrame | null;
58
+ /**
59
+ * Authenticated JSON signaling socket for one Relay Call participant.
60
+ *
61
+ * The room reopens its socket after any close that neither this client nor the
62
+ * server asked for, with PartySocket's numbers (PROTOCOL.md section 5): first
63
+ * retry after 3000 ms, then x1.3, capped at 10000 ms, a 4000 ms connect
64
+ * timeout, the retry count reset once a socket stays open 5000 ms, and no
65
+ * retry limit. On every open it sends `join`, then `userUpdate` with the last
66
+ * muted/video state, then the frames queued while closed. Media is never
67
+ * re-offered by a socket-only reconnect.
68
+ */
69
+ export declare class CallRoom {
70
+ #private;
71
+ readonly callID: string;
72
+ readonly url: string;
73
+ state: CallRoomStateFrame | null;
74
+ /**
75
+ * The STUN/TURN servers from the room's latest `iceServers` frame, or `null`
76
+ * before the first one. Relay sends fresh ones on every join, reconnects
77
+ * included, so read this again before building each new peer connection.
78
+ */
79
+ iceServers: CallRoomIceServer[] | null;
80
+ constructor(callID: string, baseURL: string, apiKey: string, options?: CallRoomOptions);
81
+ /** `reconnecting` while the room waits to reopen a dropped socket. */
82
+ get connectionState(): CallRoomConnectionState;
83
+ on<K extends CallRoomEvent>(event: K, listener: Listener<K>): this;
84
+ off<K extends CallRoomEvent>(event: K, listener: Listener<K>): this;
85
+ /** Resolves on the first open; a failed attempt is retried, not thrown. */
86
+ connect(): Promise<void>;
87
+ /**
88
+ * Open a new signaling socket now, keeping application/WebRTC state alive.
89
+ * Relay accepts the new authenticated socket before the previous one closes,
90
+ * so an active Call is not interpreted as having lost its participant. Same
91
+ * path as the automatic reconnect (PartySocket `reconnect()`: retry count
92
+ * reset, no delay); if the new socket fails while the old one is still open,
93
+ * the old one stays and this rejects.
94
+ */
95
+ reconnect(): Promise<void>;
96
+ /**
97
+ * Send one frame. While the socket is reopening the frame is queued and sent
98
+ * after `join` on the next open (PartySocket's queue); heartbeats are dropped.
99
+ */
100
+ send(frame: CallRoomClientFrame): void;
101
+ connected(): void;
102
+ userUpdate(update: {
103
+ muted: boolean;
104
+ video?: boolean;
105
+ }): void;
106
+ end(): void;
107
+ close(code?: number, reason?: string): void;
108
+ }
109
+ export {};
110
+ //# sourceMappingURL=call-room.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"call-room.d.ts","sourceRoot":"","sources":["../../src/calls/call-room.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,mBAAmB,EACnB,kBAAkB,EAElB,kBAAkB,EAClB,iBAAiB,EACjB,uBAA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