@whereby.com/core 1.32.1 → 1.33.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/dist/index.d.ts CHANGED
@@ -1243,85 +1243,6 @@ interface RoomState {
1243
1243
  mode: RoomMode | null;
1244
1244
  }
1245
1245
 
1246
- type LocalMediaOptions$1 = {
1247
- audio: boolean;
1248
- video: boolean;
1249
- };
1250
- /**
1251
- * Reducer
1252
- */
1253
- interface LocalMediaState$1 {
1254
- beforeEffectTracks?: {
1255
- audio?: MediaStreamTrack;
1256
- video?: MediaStreamTrack;
1257
- };
1258
- busyDeviceIds: string[];
1259
- cameraDeviceError?: unknown;
1260
- cameraEnabled: boolean;
1261
- currentCameraDeviceId?: string;
1262
- currentMicrophoneDeviceId?: string;
1263
- currentSpeakerDeviceId?: string;
1264
- devices: MediaDeviceInfo[];
1265
- hdMode: boolean;
1266
- isSettingCameraDevice: boolean;
1267
- isSettingMicrophoneDevice: boolean;
1268
- isSettingSpeakerDevice: boolean;
1269
- isSwitchingStream: boolean;
1270
- isTogglingCamera: boolean;
1271
- lowDataMode: boolean;
1272
- microphoneDeviceError?: unknown;
1273
- microphoneEnabled: boolean;
1274
- onDeviceChange?: () => void;
1275
- options?: LocalMediaOptions$1;
1276
- speakerDeviceError?: unknown;
1277
- status: "inactive" | "stopped" | "starting" | "started" | "error";
1278
- startError?: unknown;
1279
- stream?: MediaStream;
1280
- widescreenMode: boolean;
1281
- }
1282
-
1283
- /**
1284
- * Reducer
1285
- */
1286
- /**
1287
- * Whether to join with the camera and/or microphone muted. The devices are still
1288
- * acquired according to `localMediaOptions` - this only decides the state we join
1289
- * with. `true` means muted, an omitted key leaves that device untouched.
1290
- */
1291
- type InitialMuteStates = {
1292
- camera?: boolean;
1293
- microphone?: boolean;
1294
- };
1295
- interface AppConfig {
1296
- assistantKey?: string | null;
1297
- displayName: string;
1298
- externalId: string | null;
1299
- ignoreBreakoutGroups?: boolean;
1300
- initialMuteStates?: InitialMuteStates;
1301
- isAudioRecorder?: boolean;
1302
- isDialIn?: boolean;
1303
- isNodeSdk?: boolean;
1304
- localMediaOptions?: LocalMediaOptions$1;
1305
- roomKey: string | null;
1306
- roomUrl: string;
1307
- userAgent?: string;
1308
- }
1309
- interface AppState {
1310
- displayName: string | null;
1311
- externalId: string | null;
1312
- ignoreBreakoutGroups: boolean;
1313
- initialConfig?: AppConfig;
1314
- initialMuteStates?: InitialMuteStates;
1315
- isActive: boolean;
1316
- isAssistant: boolean;
1317
- isAudioRecorder: boolean;
1318
- isDialIn: boolean;
1319
- isNodeSdk: boolean;
1320
- roomName: string | null;
1321
- roomUrl: string | null;
1322
- userAgent: string | null;
1323
- }
1324
-
1325
1246
  type ConnectionStatus = "ready" | "connecting" | "connected" | "room_locked" | "knocking" | "knock_on_hold" | "knock_rejected" | "kicked" | "leaving" | "left" | "disconnected" | "reconnecting";
1326
1247
  type JoinRoomStage = "credentials" | "organization" | "local_media" | "signal_connect" | "identify_device" | "join_room";
1327
1248
  type JoinRoomErrorNames = "organization_fetch_failed" | "join_cancelled";
@@ -1408,6 +1329,92 @@ declare function roomIntegrationPickerUrl({ integration, parentOrigin, featureSo
1408
1329
  featureSource?: string;
1409
1330
  }): string;
1410
1331
 
1332
+ type LocalMediaOptions$1 = {
1333
+ audio: boolean;
1334
+ video: boolean;
1335
+ };
1336
+ /**
1337
+ * Reducer
1338
+ */
1339
+ interface LocalMediaState$1 {
1340
+ beforeEffectTracks?: {
1341
+ audio?: MediaStreamTrack;
1342
+ video?: MediaStreamTrack;
1343
+ };
1344
+ busyDeviceIds: string[];
1345
+ cameraDeviceError?: unknown;
1346
+ cameraEnabled: boolean;
1347
+ currentCameraDeviceId?: string;
1348
+ currentMicrophoneDeviceId?: string;
1349
+ currentSpeakerDeviceId?: string;
1350
+ devices: MediaDeviceInfo[];
1351
+ hdMode: boolean;
1352
+ isSettingCameraDevice: boolean;
1353
+ isSettingMicrophoneDevice: boolean;
1354
+ isSettingSpeakerDevice: boolean;
1355
+ isSwitchingStream: boolean;
1356
+ isTogglingCamera: boolean;
1357
+ lowDataMode: boolean;
1358
+ microphoneDeviceError?: unknown;
1359
+ microphoneEnabled: boolean;
1360
+ onDeviceChange?: () => void;
1361
+ options?: LocalMediaOptions$1;
1362
+ speakerDeviceError?: unknown;
1363
+ status: "inactive" | "stopped" | "starting" | "started" | "error";
1364
+ startError?: unknown;
1365
+ stream?: MediaStream;
1366
+ widescreenMode: boolean;
1367
+ }
1368
+
1369
+ /**
1370
+ * Reducer
1371
+ */
1372
+ /**
1373
+ * Whether to join with the camera and/or microphone muted. The devices are still
1374
+ * acquired according to `localMediaOptions` - this only decides the state we join
1375
+ * with. `true` means muted, an omitted key leaves that device untouched.
1376
+ */
1377
+ type InitialMuteStates = {
1378
+ camera?: boolean;
1379
+ microphone?: boolean;
1380
+ };
1381
+ interface AppConfig {
1382
+ assistantKey?: string | null;
1383
+ displayName: string;
1384
+ externalId: string | null;
1385
+ ignoreBreakoutGroups?: boolean;
1386
+ initialMuteStates?: InitialMuteStates;
1387
+ isAudioRecorder?: boolean;
1388
+ isDialIn?: boolean;
1389
+ isNodeSdk?: boolean;
1390
+ localMediaOptions?: LocalMediaOptions$1;
1391
+ roomKey: string | null;
1392
+ roomUrl: string;
1393
+ userAgent?: string;
1394
+ }
1395
+ interface AppState {
1396
+ displayName: string | null;
1397
+ externalId: string | null;
1398
+ ignoreBreakoutGroups: boolean;
1399
+ initialConfig?: AppConfig;
1400
+ initialMuteStates?: InitialMuteStates;
1401
+ isActive: boolean;
1402
+ isAssistant: boolean;
1403
+ isAudioRecorder: boolean;
1404
+ isDialIn: boolean;
1405
+ isNodeSdk: boolean;
1406
+ roomName: string | null;
1407
+ roomUrl: string | null;
1408
+ userAgent: string | null;
1409
+ }
1410
+
1411
+ /**
1412
+ * Reducer
1413
+ */
1414
+ interface RoomLayoutState {
1415
+ sortedClientIds: string[];
1416
+ }
1417
+
1411
1418
  /**
1412
1419
  * Reducer
1413
1420
  */
@@ -1476,6 +1483,7 @@ declare const appReducer: redux.Reducer<{
1476
1483
  room: RoomState;
1477
1484
  roomConnection: RoomConnectionState$1;
1478
1485
  roomIntegrations: RoomIntegrationsState$1;
1486
+ roomLayout: RoomLayoutState;
1479
1487
  rtcAnalytics: rtcAnalyticsState;
1480
1488
  rtcConnection: RtcConnectionState;
1481
1489
  signalConnection: SignalConnectionState;
@@ -1504,6 +1512,7 @@ declare const appReducer: redux.Reducer<{
1504
1512
  room: RoomState | undefined;
1505
1513
  roomConnection: RoomConnectionState$1 | undefined;
1506
1514
  roomIntegrations: RoomIntegrationsState$1 | undefined;
1515
+ roomLayout: RoomLayoutState | undefined;
1507
1516
  rtcAnalytics: rtcAnalyticsState | undefined;
1508
1517
  rtcConnection: RtcConnectionState | undefined;
1509
1518
  signalConnection: SignalConnectionState | undefined;
@@ -1536,6 +1545,7 @@ declare const createStore: ({ preloadedState, injectServices, }: {
1536
1545
  room: RoomState;
1537
1546
  roomConnection: RoomConnectionState$1;
1538
1547
  roomIntegrations: RoomIntegrationsState$1;
1548
+ roomLayout: RoomLayoutState;
1539
1549
  rtcAnalytics: rtcAnalyticsState;
1540
1550
  rtcConnection: RtcConnectionState;
1541
1551
  signalConnection: SignalConnectionState;
@@ -1565,6 +1575,7 @@ declare const createStore: ({ preloadedState, injectServices, }: {
1565
1575
  room: RoomState;
1566
1576
  roomConnection: RoomConnectionState$1;
1567
1577
  roomIntegrations: RoomIntegrationsState$1;
1578
+ roomLayout: RoomLayoutState;
1568
1579
  rtcAnalytics: rtcAnalyticsState;
1569
1580
  rtcConnection: RtcConnectionState;
1570
1581
  signalConnection: SignalConnectionState;
@@ -1602,6 +1613,7 @@ interface GridState {
1602
1613
  spotlightedParticipants: ClientView[];
1603
1614
  numParticipants: number;
1604
1615
  runningRoomIntegrations: RoomIntegrationSessionView[];
1616
+ canSpotlight: boolean;
1605
1617
  }
1606
1618
 
1607
1619
  declare abstract class BaseClient<TState, TEvents extends Record<string, unknown[]>> extends EventEmitter<TEvents> {
@@ -1656,6 +1668,18 @@ declare class GridClient extends BaseClient<GridState, GridEvents> {
1656
1668
  subscribeRunningRoomIntegrations(callback: (sessions: RoomIntegrationSessionView[]) => void): () => void;
1657
1669
  spotlightParticipant(id: string): void;
1658
1670
  removeSpotlight(id: string): void;
1671
+ /** Only for this participant. */
1672
+ reorderClientViews({ id, targetId }: {
1673
+ id: string;
1674
+ targetId: string;
1675
+ }): void;
1676
+ /** Only for this participant. Puts the listed client views first; the rest keep their current order. */
1677
+ setClientViewOrder(ids: string[]): void;
1678
+ /** For everyone in the room. Needs `canSpotlight`. */
1679
+ swapSpotlightOrder({ id, targetId }: {
1680
+ id: string;
1681
+ targetId: string;
1682
+ }): void;
1659
1683
  destroy(): void;
1660
1684
  }
1661
1685
 
package/dist/index.mjs CHANGED
@@ -1352,7 +1352,7 @@ const createReactor = (selectors, callback) => {
1352
1352
  });
1353
1353
  };
1354
1354
 
1355
- const coreVersion = "1.32.1";
1355
+ const coreVersion = "1.33.0";
1356
1356
 
1357
1357
  const initialState$2 = {
1358
1358
  displayName: null,
@@ -1441,6 +1441,7 @@ const signalEvents = {
1441
1441
  screenshareEnableRequested: createSignalEventAction("screenshareEnableRequested"),
1442
1442
  spotlightAdded: createSignalEventAction("spotlightAdded"),
1443
1443
  spotlightRemoved: createSignalEventAction("spotlightRemoved"),
1444
+ spotlightOrderSwapped: createSignalEventAction("spotlightOrderSwapped"),
1444
1445
  streamingStopped: createSignalEventAction("streamingStopped"),
1445
1446
  videoEnabled: createSignalEventAction("videoEnabled"),
1446
1447
  videoEnableRequested: createSignalEventAction("videoEnableRequested"),
@@ -1639,6 +1640,7 @@ function forwardSocketEvents(socket, dispatch) {
1639
1640
  socket.on("streaming_stopped", () => dispatch(signalEvents.streamingStopped()));
1640
1641
  socket.on("spotlight_added", (payload) => dispatch(signalEvents.spotlightAdded(payload)));
1641
1642
  socket.on("spotlight_removed", (payload) => dispatch(signalEvents.spotlightRemoved(payload)));
1643
+ socket.on("spotlight_order_swapped", (payload) => dispatch(signalEvents.spotlightOrderSwapped(payload)));
1642
1644
  socket.on("live_transcription_started", (payload) => dispatch(signalEvents.liveTranscriptionStarted(payload)));
1643
1645
  socket.on("live_transcription_stopped", (payload) => dispatch(signalEvents.liveTranscriptionStopped(payload)));
1644
1646
  socket.on("live_captions_started", (payload) => dispatch(signalEvents.liveCaptionsStarted(payload)));
@@ -3862,7 +3864,7 @@ createReactor([selectShouldFetchRoom], ({ dispatch, getState }, shouldFetchRoom)
3862
3864
 
3863
3865
  function streamIdForClient({ isPresentation, stream }) {
3864
3866
  var _a, _b;
3865
- return isPresentation ? (_b = (_a = stream === null || stream === void 0 ? void 0 : stream.outboundId) !== null && _a !== void 0 ? _a : stream === null || stream === void 0 ? void 0 : stream.inboundId) !== null && _b !== void 0 ? _b : stream === null || stream === void 0 ? void 0 : stream.id : CAMERA_STREAM_ID;
3867
+ return isPresentation ? ((_b = (_a = stream === null || stream === void 0 ? void 0 : stream.outboundId) !== null && _a !== void 0 ? _a : stream === null || stream === void 0 ? void 0 : stream.inboundId) !== null && _b !== void 0 ? _b : stream === null || stream === void 0 ? void 0 : stream.id) : CAMERA_STREAM_ID;
3866
3868
  }
3867
3869
  function isClientSpotlighted({ spotlights, isPresentation, clientId, stream, }) {
3868
3870
  return !!spotlights.find((s) => {
@@ -3877,6 +3879,17 @@ function mergeSpotlight(spotlights, spotlight) {
3877
3879
  }
3878
3880
  return spotlights.concat(spotlight);
3879
3881
  }
3882
+ const isSameSpotlight = (a, b) => a.clientId === b.clientId && a.streamId === b.streamId;
3883
+ function swapSpotlights(spotlights, source, target) {
3884
+ const index = spotlights.findIndex((s) => isSameSpotlight(s, source));
3885
+ const targetIndex = spotlights.findIndex((s) => isSameSpotlight(s, target));
3886
+ if (index < 0 || targetIndex < 0 || index === targetIndex) {
3887
+ return spotlights;
3888
+ }
3889
+ const swapped = [...spotlights];
3890
+ [swapped[index], swapped[targetIndex]] = [swapped[targetIndex], swapped[index]];
3891
+ return swapped;
3892
+ }
3880
3893
  function mapSpotlightsToClientViews(spotlights, clientViews) {
3881
3894
  return spotlights.reduce((acc, s) => {
3882
3895
  const clientView = clientViews.find((c) => s.clientId === c.clientId && s.streamId === streamIdForClient(c));
@@ -3922,6 +3935,14 @@ const spotlightsSlice = createSlice({
3922
3935
  const { clientId, streamId } = action.payload;
3923
3936
  return Object.assign(Object.assign({}, state), { sorted: state.sorted.filter((s) => !(s.clientId === clientId && s.streamId === streamId)) });
3924
3937
  });
3938
+ builder.addCase(signalEvents.spotlightOrderSwapped, (state, action) => {
3939
+ if ("error" in action.payload) {
3940
+ return state;
3941
+ }
3942
+ const { source, target } = action.payload;
3943
+ const sorted = swapSpotlights(state.sorted, source, target);
3944
+ return sorted === state.sorted ? state : Object.assign(Object.assign({}, state), { sorted });
3945
+ });
3925
3946
  builder.addMatcher(isAnyOf(signalEvents.clientKicked, signalEvents.clientLeft), (state, action) => {
3926
3947
  const { clientId } = action.payload;
3927
3948
  return Object.assign(Object.assign({}, state), { sorted: state.sorted.filter((s) => s.clientId !== clientId) });
@@ -3951,6 +3972,31 @@ const doRemoveSpotlight = createAppAuthorizedThunk((state) => selectIsAuthorized
3951
3972
  const payload = { clientId: clientView.id, streamId: streamId !== null && streamId !== void 0 ? streamId : CAMERA_STREAM_ID };
3952
3973
  socket === null || socket === void 0 ? void 0 : socket.emit("remove_spotlight", payload);
3953
3974
  });
3975
+ const doSwapSpotlightOrder = createAppAuthorizedThunk((state) => selectIsAuthorizedToSpotlight(state), ({ id, targetId }) => (_, getState) => {
3976
+ const state = getState();
3977
+ const clientViews = selectAllClientViews(state);
3978
+ const spotlights = selectSpotlights(state);
3979
+ const toSpotlight = (clientViewId) => {
3980
+ var _a;
3981
+ const clientView = clientViews.find((c) => c.id === clientViewId);
3982
+ if (!clientView) {
3983
+ return null;
3984
+ }
3985
+ const spotlight = {
3986
+ clientId: clientView.clientId,
3987
+ streamId: (_a = streamIdForClient(clientView)) !== null && _a !== void 0 ? _a : CAMERA_STREAM_ID,
3988
+ };
3989
+ return spotlights.some((s) => isSameSpotlight(s, spotlight)) ? spotlight : null;
3990
+ };
3991
+ const source = toSpotlight(id);
3992
+ const target = toSpotlight(targetId);
3993
+ if (!source || !target || isSameSpotlight(source, target)) {
3994
+ return;
3995
+ }
3996
+ const { socket } = selectSignalConnectionRaw(state);
3997
+ const payload = { source, target };
3998
+ socket === null || socket === void 0 ? void 0 : socket.emit("swap_spotlight_order", payload);
3999
+ });
3954
4000
  const selectSpotlights = (state) => state.spotlights.sorted;
3955
4001
  createSelector(selectLocalParticipantRaw, selectSpotlights, (localParticipant, spotlights) => {
3956
4002
  return isClientSpotlighted({ clientId: localParticipant.id, stream: localParticipant.stream, spotlights });
@@ -5188,6 +5234,50 @@ createReactor([selectBreakoutAssignments, selectDeviceId, selectLocalParticipant
5188
5234
  }
5189
5235
  });
5190
5236
 
5237
+ const roomLayoutSliceInitialState = {
5238
+ sortedClientIds: [],
5239
+ };
5240
+ const roomLayoutSlice = createSlice({
5241
+ name: "roomLayout",
5242
+ initialState: roomLayoutSliceInitialState,
5243
+ reducers: {
5244
+ setSortedClientIds(state, action) {
5245
+ return Object.assign(Object.assign({}, state), { sortedClientIds: Array.from(new Set(action.payload)) });
5246
+ },
5247
+ },
5248
+ });
5249
+ const { setSortedClientIds } = roomLayoutSlice.actions;
5250
+ const doReorderClientViews = createAppThunk(({ id, targetId }) => (dispatch, getState) => {
5251
+ const clientIds = selectSortedClientViews(getState()).map((c) => c.id);
5252
+ const index = clientIds.indexOf(id);
5253
+ const targetIndex = clientIds.indexOf(targetId);
5254
+ if (index < 0 || targetIndex < 0 || index === targetIndex) {
5255
+ return;
5256
+ }
5257
+ [clientIds[index], clientIds[targetIndex]] = [clientIds[targetIndex], clientIds[index]];
5258
+ dispatch(setSortedClientIds(clientIds));
5259
+ });
5260
+ const doSetClientViewOrder = createAppThunk((ids) => (dispatch, getState) => {
5261
+ const listed = new Set(ids);
5262
+ const unlisted = selectSortedClientViews(getState())
5263
+ .map((c) => c.id)
5264
+ .filter((id) => !listed.has(id));
5265
+ dispatch(setSortedClientIds([...ids, ...unlisted]));
5266
+ });
5267
+ const selectSortedClientIds = (state) => state.roomLayout.sortedClientIds;
5268
+ const selectSortedClientViews = createSelector(selectAllClientViews, selectSortedClientIds, (clientViews, sortedClientIds) => sortClientViews({ sortedClientIds, clientViews }));
5269
+ function sortClientViews({ sortedClientIds, clientViews, }) {
5270
+ if (!sortedClientIds.length) {
5271
+ return clientViews;
5272
+ }
5273
+ const rank = new Map(sortedClientIds.map((id, index) => [id, index]));
5274
+ const unranked = sortedClientIds.length;
5275
+ return clientViews
5276
+ .map((clientView, index) => { var _a; return ({ clientView, index, rank: (_a = rank.get(clientView.id)) !== null && _a !== void 0 ? _a : unranked }); })
5277
+ .sort((a, b) => a.rank - b.rank || a.index - b.index)
5278
+ .map(({ clientView }) => clientView);
5279
+ }
5280
+
5191
5281
  function isCustomElementName(value) {
5192
5282
  return typeof value === "string" && value === value.toLowerCase() && value.includes("-");
5193
5283
  }
@@ -6172,6 +6262,7 @@ const appReducer = combineReducers({
6172
6262
  room: roomSlice.reducer,
6173
6263
  roomConnection: roomConnectionSlice.reducer,
6174
6264
  roomIntegrations: roomIntegrationsSlice.reducer,
6265
+ roomLayout: roomLayoutSlice.reducer,
6175
6266
  rtcAnalytics: rtcAnalyticsSlice.reducer,
6176
6267
  rtcConnection: rtcConnectionSlice.reducer,
6177
6268
  signalConnection: signalConnectionSlice.reducer,
@@ -6213,12 +6304,13 @@ const CLIENT_VIEW_SPOTLIGHTS_CHANGED = "grid:client-view-spotlights-changed";
6213
6304
  const NUMBER_OF_CLIENT_VIEWS_CHANGED = "grid:number-of-client-views-changed";
6214
6305
  const RUNNING_ROOM_INTEGRATIONS_CHANGED = "grid:running-room-integrations-changed";
6215
6306
 
6216
- const selectGridState = createSelector(selectAllClientViews, selectSpotlightedClientViews, selectNumClients, selectRunningRoomIntegrations, (allClientViews, spotlightedParticipants, numClients, runningRoomIntegrations) => {
6307
+ const selectGridState = createSelector(selectSortedClientViews, selectSpotlightedClientViews, selectNumClients, selectRunningRoomIntegrations, selectIsAuthorizedToSpotlight, (allClientViews, spotlightedParticipants, numClients, runningRoomIntegrations, canSpotlight) => {
6217
6308
  return {
6218
6309
  allClientViews,
6219
6310
  spotlightedParticipants,
6220
6311
  numParticipants: numClients,
6221
6312
  runningRoomIntegrations,
6313
+ canSpotlight,
6222
6314
  };
6223
6315
  });
6224
6316
 
@@ -6302,6 +6394,24 @@ class GridClient extends BaseClient {
6302
6394
  removeSpotlight(id) {
6303
6395
  this.store.dispatch(doRemoveSpotlight({ id }));
6304
6396
  }
6397
+ reorderClientViews({ id, targetId }) {
6398
+ if (typeof id !== "string" || typeof targetId !== "string") {
6399
+ throw new TypeError("reorderClientViews expects { id, targetId } with string client view ids");
6400
+ }
6401
+ this.store.dispatch(doReorderClientViews({ id, targetId }));
6402
+ }
6403
+ setClientViewOrder(ids) {
6404
+ if (!Array.isArray(ids) || ids.some((id) => typeof id !== "string")) {
6405
+ throw new TypeError("setClientViewOrder expects an array of client view ids");
6406
+ }
6407
+ this.store.dispatch(doSetClientViewOrder(ids));
6408
+ }
6409
+ swapSpotlightOrder({ id, targetId }) {
6410
+ if (typeof id !== "string" || typeof targetId !== "string") {
6411
+ throw new TypeError("swapSpotlightOrder expects { id, targetId } with string client view ids");
6412
+ }
6413
+ this.store.dispatch(doSwapSpotlightOrder({ id, targetId }));
6414
+ }
6305
6415
  destroy() {
6306
6416
  super.destroy();
6307
6417
  this.clientViewSubscribers.clear();
@@ -1352,7 +1352,7 @@ const createReactor = (selectors, callback) => {
1352
1352
  });
1353
1353
  };
1354
1354
 
1355
- const coreVersion = "1.32.1";
1355
+ const coreVersion = "1.33.0";
1356
1356
 
1357
1357
  const initialState$2 = {
1358
1358
  displayName: null,
@@ -1441,6 +1441,7 @@ const signalEvents = {
1441
1441
  screenshareEnableRequested: createSignalEventAction("screenshareEnableRequested"),
1442
1442
  spotlightAdded: createSignalEventAction("spotlightAdded"),
1443
1443
  spotlightRemoved: createSignalEventAction("spotlightRemoved"),
1444
+ spotlightOrderSwapped: createSignalEventAction("spotlightOrderSwapped"),
1444
1445
  streamingStopped: createSignalEventAction("streamingStopped"),
1445
1446
  videoEnabled: createSignalEventAction("videoEnabled"),
1446
1447
  videoEnableRequested: createSignalEventAction("videoEnableRequested"),
@@ -1639,6 +1640,7 @@ function forwardSocketEvents(socket, dispatch) {
1639
1640
  socket.on("streaming_stopped", () => dispatch(signalEvents.streamingStopped()));
1640
1641
  socket.on("spotlight_added", (payload) => dispatch(signalEvents.spotlightAdded(payload)));
1641
1642
  socket.on("spotlight_removed", (payload) => dispatch(signalEvents.spotlightRemoved(payload)));
1643
+ socket.on("spotlight_order_swapped", (payload) => dispatch(signalEvents.spotlightOrderSwapped(payload)));
1642
1644
  socket.on("live_transcription_started", (payload) => dispatch(signalEvents.liveTranscriptionStarted(payload)));
1643
1645
  socket.on("live_transcription_stopped", (payload) => dispatch(signalEvents.liveTranscriptionStopped(payload)));
1644
1646
  socket.on("live_captions_started", (payload) => dispatch(signalEvents.liveCaptionsStarted(payload)));
@@ -3862,7 +3864,7 @@ createReactor([selectShouldFetchRoom], ({ dispatch, getState }, shouldFetchRoom)
3862
3864
 
3863
3865
  function streamIdForClient({ isPresentation, stream }) {
3864
3866
  var _a, _b;
3865
- return isPresentation ? (_b = (_a = stream === null || stream === void 0 ? void 0 : stream.outboundId) !== null && _a !== void 0 ? _a : stream === null || stream === void 0 ? void 0 : stream.inboundId) !== null && _b !== void 0 ? _b : stream === null || stream === void 0 ? void 0 : stream.id : CAMERA_STREAM_ID;
3867
+ return isPresentation ? ((_b = (_a = stream === null || stream === void 0 ? void 0 : stream.outboundId) !== null && _a !== void 0 ? _a : stream === null || stream === void 0 ? void 0 : stream.inboundId) !== null && _b !== void 0 ? _b : stream === null || stream === void 0 ? void 0 : stream.id) : CAMERA_STREAM_ID;
3866
3868
  }
3867
3869
  function isClientSpotlighted({ spotlights, isPresentation, clientId, stream, }) {
3868
3870
  return !!spotlights.find((s) => {
@@ -3877,6 +3879,17 @@ function mergeSpotlight(spotlights, spotlight) {
3877
3879
  }
3878
3880
  return spotlights.concat(spotlight);
3879
3881
  }
3882
+ const isSameSpotlight = (a, b) => a.clientId === b.clientId && a.streamId === b.streamId;
3883
+ function swapSpotlights(spotlights, source, target) {
3884
+ const index = spotlights.findIndex((s) => isSameSpotlight(s, source));
3885
+ const targetIndex = spotlights.findIndex((s) => isSameSpotlight(s, target));
3886
+ if (index < 0 || targetIndex < 0 || index === targetIndex) {
3887
+ return spotlights;
3888
+ }
3889
+ const swapped = [...spotlights];
3890
+ [swapped[index], swapped[targetIndex]] = [swapped[targetIndex], swapped[index]];
3891
+ return swapped;
3892
+ }
3880
3893
  function mapSpotlightsToClientViews(spotlights, clientViews) {
3881
3894
  return spotlights.reduce((acc, s) => {
3882
3895
  const clientView = clientViews.find((c) => s.clientId === c.clientId && s.streamId === streamIdForClient(c));
@@ -3922,6 +3935,14 @@ const spotlightsSlice = createSlice({
3922
3935
  const { clientId, streamId } = action.payload;
3923
3936
  return Object.assign(Object.assign({}, state), { sorted: state.sorted.filter((s) => !(s.clientId === clientId && s.streamId === streamId)) });
3924
3937
  });
3938
+ builder.addCase(signalEvents.spotlightOrderSwapped, (state, action) => {
3939
+ if ("error" in action.payload) {
3940
+ return state;
3941
+ }
3942
+ const { source, target } = action.payload;
3943
+ const sorted = swapSpotlights(state.sorted, source, target);
3944
+ return sorted === state.sorted ? state : Object.assign(Object.assign({}, state), { sorted });
3945
+ });
3925
3946
  builder.addMatcher(isAnyOf(signalEvents.clientKicked, signalEvents.clientLeft), (state, action) => {
3926
3947
  const { clientId } = action.payload;
3927
3948
  return Object.assign(Object.assign({}, state), { sorted: state.sorted.filter((s) => s.clientId !== clientId) });
@@ -3951,6 +3972,31 @@ const doRemoveSpotlight = createAppAuthorizedThunk((state) => selectIsAuthorized
3951
3972
  const payload = { clientId: clientView.id, streamId: streamId !== null && streamId !== void 0 ? streamId : CAMERA_STREAM_ID };
3952
3973
  socket === null || socket === void 0 ? void 0 : socket.emit("remove_spotlight", payload);
3953
3974
  });
3975
+ const doSwapSpotlightOrder = createAppAuthorizedThunk((state) => selectIsAuthorizedToSpotlight(state), ({ id, targetId }) => (_, getState) => {
3976
+ const state = getState();
3977
+ const clientViews = selectAllClientViews(state);
3978
+ const spotlights = selectSpotlights(state);
3979
+ const toSpotlight = (clientViewId) => {
3980
+ var _a;
3981
+ const clientView = clientViews.find((c) => c.id === clientViewId);
3982
+ if (!clientView) {
3983
+ return null;
3984
+ }
3985
+ const spotlight = {
3986
+ clientId: clientView.clientId,
3987
+ streamId: (_a = streamIdForClient(clientView)) !== null && _a !== void 0 ? _a : CAMERA_STREAM_ID,
3988
+ };
3989
+ return spotlights.some((s) => isSameSpotlight(s, spotlight)) ? spotlight : null;
3990
+ };
3991
+ const source = toSpotlight(id);
3992
+ const target = toSpotlight(targetId);
3993
+ if (!source || !target || isSameSpotlight(source, target)) {
3994
+ return;
3995
+ }
3996
+ const { socket } = selectSignalConnectionRaw(state);
3997
+ const payload = { source, target };
3998
+ socket === null || socket === void 0 ? void 0 : socket.emit("swap_spotlight_order", payload);
3999
+ });
3954
4000
  const selectSpotlights = (state) => state.spotlights.sorted;
3955
4001
  createSelector(selectLocalParticipantRaw, selectSpotlights, (localParticipant, spotlights) => {
3956
4002
  return isClientSpotlighted({ clientId: localParticipant.id, stream: localParticipant.stream, spotlights });
@@ -5188,6 +5234,50 @@ createReactor([selectBreakoutAssignments, selectDeviceId, selectLocalParticipant
5188
5234
  }
5189
5235
  });
5190
5236
 
5237
+ const roomLayoutSliceInitialState = {
5238
+ sortedClientIds: [],
5239
+ };
5240
+ const roomLayoutSlice = createSlice({
5241
+ name: "roomLayout",
5242
+ initialState: roomLayoutSliceInitialState,
5243
+ reducers: {
5244
+ setSortedClientIds(state, action) {
5245
+ return Object.assign(Object.assign({}, state), { sortedClientIds: Array.from(new Set(action.payload)) });
5246
+ },
5247
+ },
5248
+ });
5249
+ const { setSortedClientIds } = roomLayoutSlice.actions;
5250
+ const doReorderClientViews = createAppThunk(({ id, targetId }) => (dispatch, getState) => {
5251
+ const clientIds = selectSortedClientViews(getState()).map((c) => c.id);
5252
+ const index = clientIds.indexOf(id);
5253
+ const targetIndex = clientIds.indexOf(targetId);
5254
+ if (index < 0 || targetIndex < 0 || index === targetIndex) {
5255
+ return;
5256
+ }
5257
+ [clientIds[index], clientIds[targetIndex]] = [clientIds[targetIndex], clientIds[index]];
5258
+ dispatch(setSortedClientIds(clientIds));
5259
+ });
5260
+ const doSetClientViewOrder = createAppThunk((ids) => (dispatch, getState) => {
5261
+ const listed = new Set(ids);
5262
+ const unlisted = selectSortedClientViews(getState())
5263
+ .map((c) => c.id)
5264
+ .filter((id) => !listed.has(id));
5265
+ dispatch(setSortedClientIds([...ids, ...unlisted]));
5266
+ });
5267
+ const selectSortedClientIds = (state) => state.roomLayout.sortedClientIds;
5268
+ const selectSortedClientViews = createSelector(selectAllClientViews, selectSortedClientIds, (clientViews, sortedClientIds) => sortClientViews({ sortedClientIds, clientViews }));
5269
+ function sortClientViews({ sortedClientIds, clientViews, }) {
5270
+ if (!sortedClientIds.length) {
5271
+ return clientViews;
5272
+ }
5273
+ const rank = new Map(sortedClientIds.map((id, index) => [id, index]));
5274
+ const unranked = sortedClientIds.length;
5275
+ return clientViews
5276
+ .map((clientView, index) => { var _a; return ({ clientView, index, rank: (_a = rank.get(clientView.id)) !== null && _a !== void 0 ? _a : unranked }); })
5277
+ .sort((a, b) => a.rank - b.rank || a.index - b.index)
5278
+ .map(({ clientView }) => clientView);
5279
+ }
5280
+
5191
5281
  function isCustomElementName(value) {
5192
5282
  return typeof value === "string" && value === value.toLowerCase() && value.includes("-");
5193
5283
  }
@@ -6172,6 +6262,7 @@ const appReducer = combineReducers({
6172
6262
  room: roomSlice.reducer,
6173
6263
  roomConnection: roomConnectionSlice.reducer,
6174
6264
  roomIntegrations: roomIntegrationsSlice.reducer,
6265
+ roomLayout: roomLayoutSlice.reducer,
6175
6266
  rtcAnalytics: rtcAnalyticsSlice.reducer,
6176
6267
  rtcConnection: rtcConnectionSlice.reducer,
6177
6268
  signalConnection: signalConnectionSlice.reducer,
@@ -6213,12 +6304,13 @@ const CLIENT_VIEW_SPOTLIGHTS_CHANGED = "grid:client-view-spotlights-changed";
6213
6304
  const NUMBER_OF_CLIENT_VIEWS_CHANGED = "grid:number-of-client-views-changed";
6214
6305
  const RUNNING_ROOM_INTEGRATIONS_CHANGED = "grid:running-room-integrations-changed";
6215
6306
 
6216
- const selectGridState = createSelector(selectAllClientViews, selectSpotlightedClientViews, selectNumClients, selectRunningRoomIntegrations, (allClientViews, spotlightedParticipants, numClients, runningRoomIntegrations) => {
6307
+ const selectGridState = createSelector(selectSortedClientViews, selectSpotlightedClientViews, selectNumClients, selectRunningRoomIntegrations, selectIsAuthorizedToSpotlight, (allClientViews, spotlightedParticipants, numClients, runningRoomIntegrations, canSpotlight) => {
6217
6308
  return {
6218
6309
  allClientViews,
6219
6310
  spotlightedParticipants,
6220
6311
  numParticipants: numClients,
6221
6312
  runningRoomIntegrations,
6313
+ canSpotlight,
6222
6314
  };
6223
6315
  });
6224
6316
 
@@ -6302,6 +6394,24 @@ class GridClient extends BaseClient {
6302
6394
  removeSpotlight(id) {
6303
6395
  this.store.dispatch(doRemoveSpotlight({ id }));
6304
6396
  }
6397
+ reorderClientViews({ id, targetId }) {
6398
+ if (typeof id !== "string" || typeof targetId !== "string") {
6399
+ throw new TypeError("reorderClientViews expects { id, targetId } with string client view ids");
6400
+ }
6401
+ this.store.dispatch(doReorderClientViews({ id, targetId }));
6402
+ }
6403
+ setClientViewOrder(ids) {
6404
+ if (!Array.isArray(ids) || ids.some((id) => typeof id !== "string")) {
6405
+ throw new TypeError("setClientViewOrder expects an array of client view ids");
6406
+ }
6407
+ this.store.dispatch(doSetClientViewOrder(ids));
6408
+ }
6409
+ swapSpotlightOrder({ id, targetId }) {
6410
+ if (typeof id !== "string" || typeof targetId !== "string") {
6411
+ throw new TypeError("swapSpotlightOrder expects { id, targetId } with string client view ids");
6412
+ }
6413
+ this.store.dispatch(doSwapSpotlightOrder({ id, targetId }));
6414
+ }
6305
6415
  destroy() {
6306
6416
  super.destroy();
6307
6417
  this.clientViewSubscribers.clear();