@poolse/native 3.10.0 → 3.10.2

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/src/index.ts CHANGED
@@ -15,6 +15,15 @@ import { requireNativeViewManager, requireOptionalNativeModule } from 'expo-modu
15
15
  * ends the snapshot stays `phase: 'ended'` (with `reason`) for ~2.5 s,
16
16
  * then becomes `null`.
17
17
  */
18
+ /** `Snapshot.screenShare`: a remote participant's shared screen. */
19
+ export interface ScreenShareInfo {
20
+ /** The sharer's LiveKit identity (their `participants[].userId`). */
21
+ userId: string;
22
+ externalId: string;
23
+ width: number | null;
24
+ height: number | null;
25
+ }
26
+
18
27
  export interface Snapshot {
19
28
  cv: 1;
20
29
  callId: string;
@@ -63,6 +72,12 @@ export interface Snapshot {
63
72
  * large and with `fit="contain"`. Absent before 3.2.
64
73
  */
65
74
  screenSharing?: boolean;
75
+ /**
76
+ * The shared screen's size in pixels as its publisher announced it;
77
+ * present only while `screenSharing` and once known. Absent before 3.11.
78
+ */
79
+ screenWidth?: number;
80
+ screenHeight?: number;
66
81
  /**
67
82
  * Their link to the call: `lost` while they have dropped and are
68
83
  * coming back (show "Reconnecting…"), `poor` for a weak signal.
@@ -119,6 +134,14 @@ export interface Snapshot {
119
134
  videoPaused?: boolean;
120
135
  /** You are sharing your screen. Absent before 3.2. */
121
136
  screenSharing?: boolean;
137
+ /**
138
+ * Who else shares a screen (the first remote sharer) and its size in
139
+ * pixels, so screen drawings line up with what is shown (CL4): fit the
140
+ * overlay to a `width`:`height` box inside the `fit="contain"` view.
141
+ * `width`/`height` are null until the sharer's size is known. null when
142
+ * nobody else shares (yours is `screenSharing`); absent before 3.11.
143
+ */
144
+ screenShare?: ScreenShareInfo | null;
122
145
  /**
123
146
  * The server (workspace) this call runs on — the `id` given to
124
147
  * `addServer`, or `DEFAULT_SERVER_ID` for the one `configure` set.
@@ -167,6 +190,17 @@ export interface Snapshot {
167
190
  * there); the end that follows has `reason: 'moved'`. Absent before 3.10.
168
191
  */
169
192
  movedElsewhere?: boolean;
193
+ /**
194
+ * The breakout room the call's media is in (`moveToRoom`,
195
+ * MEETINGS.md §5); null in the call's main room. `roomId` is the
196
+ * split's `<split id>.<n>`. Absent before 3.11.
197
+ */
198
+ breakout?: { roomId: string; name: string | null } | null;
199
+ /**
200
+ * Your own identity in the media room — your poolse user id — once
201
+ * connected; what `callData.getSelfId()` answers. Absent before 3.11.
202
+ */
203
+ selfIdentity?: string | null;
170
204
  }
171
205
 
172
206
  /** The CallSummary's `recording` object, as the server sent it (docs/CALL_CONTRACT.md §4.2). */
@@ -428,6 +462,12 @@ interface PoolseCallsNative {
428
462
  setBackgroundBlur?(on: boolean): boolean;
429
463
  setAudioOutput?(id: string): void;
430
464
  republish?(): void;
465
+ publishData?(
466
+ topic: string,
467
+ data: string,
468
+ options: { reliable?: boolean; base64?: boolean; to?: string[] } | null,
469
+ ): Promise<boolean>;
470
+ moveToRoom?(session: string): Promise<boolean>;
431
471
  callControl?(): Promise<{
432
472
  callId: string;
433
473
  controlToken: string;
@@ -458,6 +498,7 @@ interface PoolseCallsNative {
458
498
  event: 'onPictureInPicture',
459
499
  cb: (payload: { active: boolean }) => void,
460
500
  ): { remove(): void };
501
+ addListener(event: 'onCallData', cb: (payload: CallDataMessage) => void): { remove(): void };
461
502
  }
462
503
 
463
504
  const native = requireOptionalNativeModule<PoolseCallsNative>('PoolseCalls');
@@ -1029,6 +1070,188 @@ export function onPictureInPicture(cb: (active: boolean) => void): Unsubscribe {
1029
1070
  return () => sub.remove();
1030
1071
  }
1031
1072
 
1073
+ // ── data channel (CL4, CL6) ───────────────────────────────────────────
1074
+
1075
+ /**
1076
+ * The most one data-channel message may carry, in bytes — the same cap
1077
+ * as the web SDK's `CALL_DATA_MAX_BYTES`, under LiveKit's ~15 KiB packet.
1078
+ */
1079
+ export const CALL_DATA_MAX_BYTES = 14_000;
1080
+
1081
+ /** One message from someone in the call's room. */
1082
+ export interface CallDataMessage {
1083
+ topic: string;
1084
+ /** The bytes, base64. */
1085
+ payload: string;
1086
+ /** The bytes as UTF-8 text; null when they are not text. */
1087
+ text: string | null;
1088
+ /** Who sent it (their poolse user id); null when the server did. */
1089
+ fromIdentity: string | null;
1090
+ fromName: string | null;
1091
+ }
1092
+
1093
+ export interface PublishDataOptions {
1094
+ /** Default true. `false` for what is stale a moment later (a moving pointer). */
1095
+ reliable?: boolean;
1096
+ /** `data` is base64 bytes rather than text. */
1097
+ base64?: boolean;
1098
+ /** Only these people (poolse user ids); everyone in the room when left out. */
1099
+ to?: string[];
1100
+ }
1101
+
1102
+ /** UTF-8 length of `s`, without TextEncoder (not on every Hermes). */
1103
+ function utf8Length(s: string): number {
1104
+ let n = 0;
1105
+ for (let i = 0; i < s.length; i++) {
1106
+ const c = s.charCodeAt(i);
1107
+ if (c < 0x80) n += 1;
1108
+ else if (c < 0x800) n += 2;
1109
+ else if (c >= 0xd800 && c <= 0xdbff && i + 1 < s.length) {
1110
+ n += 4;
1111
+ i++;
1112
+ } else n += 3;
1113
+ }
1114
+ return n;
1115
+ }
1116
+
1117
+ /**
1118
+ * Send `data` under `topic` to everyone in the call's room over LiveKit's
1119
+ * data channel, through the SFU, never stored (CL4, CL6). Web, desktop
1120
+ * and phones share topics and formats: `poolse.reaction`,
1121
+ * `poolse.annotate` (see {@link callData} for JSON). Resolves false with
1122
+ * no call connected, over {@link CALL_DATA_MAX_BYTES}, or on a build
1123
+ * without it.
1124
+ */
1125
+ export async function publishData(
1126
+ topic: string,
1127
+ data: string,
1128
+ options: PublishDataOptions = {},
1129
+ ): Promise<boolean> {
1130
+ if (!native?.publishData || !topic) return false;
1131
+ const size = options.base64 ? Math.floor((data.length * 3) / 4) : utf8Length(data);
1132
+ if (size > CALL_DATA_MAX_BYTES) return false;
1133
+ try {
1134
+ return await native.publishData(topic, data, {
1135
+ reliable: options.reliable ?? true,
1136
+ base64: options.base64 ?? false,
1137
+ ...(options.to ? { to: options.to } : {}),
1138
+ });
1139
+ } catch {
1140
+ return false;
1141
+ }
1142
+ }
1143
+
1144
+ /** Every data-channel message others send in the call's room (yours are not echoed). */
1145
+ export function onCallData(cb: (message: CallDataMessage) => void): Unsubscribe {
1146
+ if (!native?.publishData) return () => undefined;
1147
+ const sub = native.addListener('onCallData', cb);
1148
+ return () => sub.remove();
1149
+ }
1150
+
1151
+ type DataListener = (
1152
+ message: unknown,
1153
+ from: { userId: string | null; name: string | null },
1154
+ ) => void;
1155
+ const dataListeners = new Map<string, Set<DataListener>>();
1156
+ let dataSub: Unsubscribe | null = null;
1157
+
1158
+ /**
1159
+ * The native call's data channel in the shape @poolse/sdk's
1160
+ * `CallDataChannel` takes — JSON messages by topic — so the SDK's
1161
+ * `CallReactions` and `ScreenAnnotations` (and @poolse/react's
1162
+ * `useCallReactions` / `useScreenAnnotations`) run on phones exactly as
1163
+ * on the web and desktop, and interoperate with them:
1164
+ *
1165
+ * import { callData } from '@poolse/native';
1166
+ * const { reactions, send } = useCallReactions(callData);
1167
+ * const { state } = useScreenAnnotations(callData, sharerUserId);
1168
+ * <AnnotationOverlay state={state} />
1169
+ *
1170
+ * One process-wide object; it follows whichever call is live.
1171
+ */
1172
+ export const callData = {
1173
+ getSelfId(): string | null {
1174
+ return getCallState()?.selfIdentity ?? null;
1175
+ },
1176
+ sendData(
1177
+ topic: string,
1178
+ message: unknown,
1179
+ opts: { reliable?: boolean; to?: string[] } = {},
1180
+ ): Promise<boolean> {
1181
+ let text: string;
1182
+ try {
1183
+ text = JSON.stringify(message);
1184
+ } catch {
1185
+ return Promise.resolve(false);
1186
+ }
1187
+ return publishData(topic, text, opts);
1188
+ },
1189
+ onData(topic: string, fn: DataListener): Unsubscribe {
1190
+ let set = dataListeners.get(topic);
1191
+ if (!set) {
1192
+ set = new Set();
1193
+ dataListeners.set(topic, set);
1194
+ }
1195
+ set.add(fn);
1196
+ dataSub ??= onCallData((m) => {
1197
+ const listeners = dataListeners.get(m.topic);
1198
+ if (!listeners?.size || m.text == null) return;
1199
+ let parsed: unknown;
1200
+ try {
1201
+ parsed = JSON.parse(m.text);
1202
+ } catch {
1203
+ return;
1204
+ }
1205
+ const from = { userId: m.fromIdentity, name: m.fromName };
1206
+ for (const l of [...listeners]) l(parsed, from);
1207
+ });
1208
+ return () => {
1209
+ set.delete(fn);
1210
+ if (set.size === 0) dataListeners.delete(topic);
1211
+ if (dataListeners.size === 0 && dataSub) {
1212
+ dataSub();
1213
+ dataSub = null;
1214
+ }
1215
+ };
1216
+ },
1217
+ };
1218
+
1219
+ // ── breakout rooms (CL5) ──────────────────────────────────────────────
1220
+
1221
+ /**
1222
+ * What {@link moveToRoom} takes: the session bundle `POST
1223
+ * /v1/breakouts/:room/join` or `POST /v1/calls/:id/breakouts/return`
1224
+ * answers with (@poolse/sdk's `meetingsLive.breakouts.join` /
1225
+ * `returnToMain`), or its JSON text.
1226
+ */
1227
+ export interface RoomSessionBundle {
1228
+ call: { id: string };
1229
+ livekit: { url: string; token: string };
1230
+ control_token: string;
1231
+ breakout?: { room_id: string; name: string | null } | null;
1232
+ }
1233
+
1234
+ /**
1235
+ * Breakout rooms (MEETINGS.md §5): move the call you are on into another
1236
+ * of its rooms — your breakout room, or back to the main room — without
1237
+ * hanging up. CallKit / the Android call service keep the call; only
1238
+ * the media swaps rooms, mute and camera as they were, and
1239
+ * `snapshot.breakout` says where you are. If the new room can't be
1240
+ * joined, the media goes back to the room it came from.
1241
+ *
1242
+ * Resolves false with no call connected (or still connecting), for
1243
+ * another call's session, or on a build without it. @poolse/react-native's
1244
+ * `useNativeBreakouts` does this for you as the split opens and closes.
1245
+ */
1246
+ export async function moveToRoom(session: RoomSessionBundle | string): Promise<boolean> {
1247
+ if (!native?.moveToRoom) return false;
1248
+ try {
1249
+ return await native.moveToRoom(typeof session === 'string' ? session : JSON.stringify(session));
1250
+ } catch {
1251
+ return false;
1252
+ }
1253
+ }
1254
+
1032
1255
  // ── video ─────────────────────────────────────────────────────────────
1033
1256
 
1034
1257
  export interface CallVideoViewProps extends ViewProps {