@whereby.com/core 1.32.0 → 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.
@@ -1352,7 +1352,7 @@ const createReactor = (selectors, callback) => {
1352
1352
  });
1353
1353
  };
1354
1354
 
1355
- const coreVersion = "1.32.0";
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)));
@@ -2010,10 +2012,14 @@ const doSetDevice = createAppAsyncThunk("localMedia/reactSetDevice", (_a, _b) =>
2010
2012
  const before = snapshotTracks(stream);
2011
2013
  const { replacedTracks } = yield getStream(Object.assign(Object.assign({}, constraintsOptions), { audioId,
2012
2014
  videoId, type: "exact" }), { replaceStream: stream });
2013
- const isAudioEnabled = selectIsMicrophoneEnabled(state);
2015
+ const isAudioEnabled = selectIsMicrophoneEnabled(getState());
2014
2016
  stream.getAudioTracks().forEach((track) => (track.enabled = isAudioEnabled));
2015
- const isVideoEnabled = selectIsCameraEnabled(state);
2016
- stream.getVideoTracks().forEach((track) => (track.enabled = isVideoEnabled));
2017
+ if (!selectIsCameraEnabled(getState())) {
2018
+ stream.getVideoTracks().forEach((track) => {
2019
+ track.stop();
2020
+ stream.removeTrack(track);
2021
+ });
2022
+ }
2017
2023
  return {
2018
2024
  replacedTracks,
2019
2025
  changedTracks: findChangedTracks(stream, before),
@@ -2100,6 +2106,14 @@ const doSwitchLocalStream = createAppAsyncThunk("localMedia/doSwitchLocalStream"
2100
2106
  deviceId,
2101
2107
  }));
2102
2108
  }
2109
+ const isAudioEnabled = selectIsMicrophoneEnabled(getState());
2110
+ replaceStream.getAudioTracks().forEach((track) => (track.enabled = isAudioEnabled));
2111
+ if (!selectIsCameraEnabled(getState())) {
2112
+ replaceStream.getVideoTracks().forEach((track) => {
2113
+ track.stop();
2114
+ replaceStream.removeTrack(track);
2115
+ });
2116
+ }
2103
2117
  return {
2104
2118
  replacedTracks,
2105
2119
  beforeEffectTracks,
@@ -3850,7 +3864,7 @@ createReactor([selectShouldFetchRoom], ({ dispatch, getState }, shouldFetchRoom)
3850
3864
 
3851
3865
  function streamIdForClient({ isPresentation, stream }) {
3852
3866
  var _a, _b;
3853
- 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;
3854
3868
  }
3855
3869
  function isClientSpotlighted({ spotlights, isPresentation, clientId, stream, }) {
3856
3870
  return !!spotlights.find((s) => {
@@ -3865,6 +3879,17 @@ function mergeSpotlight(spotlights, spotlight) {
3865
3879
  }
3866
3880
  return spotlights.concat(spotlight);
3867
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
+ }
3868
3893
  function mapSpotlightsToClientViews(spotlights, clientViews) {
3869
3894
  return spotlights.reduce((acc, s) => {
3870
3895
  const clientView = clientViews.find((c) => s.clientId === c.clientId && s.streamId === streamIdForClient(c));
@@ -3910,6 +3935,14 @@ const spotlightsSlice = createSlice({
3910
3935
  const { clientId, streamId } = action.payload;
3911
3936
  return Object.assign(Object.assign({}, state), { sorted: state.sorted.filter((s) => !(s.clientId === clientId && s.streamId === streamId)) });
3912
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
+ });
3913
3946
  builder.addMatcher(isAnyOf(signalEvents.clientKicked, signalEvents.clientLeft), (state, action) => {
3914
3947
  const { clientId } = action.payload;
3915
3948
  return Object.assign(Object.assign({}, state), { sorted: state.sorted.filter((s) => s.clientId !== clientId) });
@@ -3939,6 +3972,31 @@ const doRemoveSpotlight = createAppAuthorizedThunk((state) => selectIsAuthorized
3939
3972
  const payload = { clientId: clientView.id, streamId: streamId !== null && streamId !== void 0 ? streamId : CAMERA_STREAM_ID };
3940
3973
  socket === null || socket === void 0 ? void 0 : socket.emit("remove_spotlight", payload);
3941
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
+ });
3942
4000
  const selectSpotlights = (state) => state.spotlights.sorted;
3943
4001
  createSelector(selectLocalParticipantRaw, selectSpotlights, (localParticipant, spotlights) => {
3944
4002
  return isClientSpotlighted({ clientId: localParticipant.id, stream: localParticipant.stream, spotlights });
@@ -5176,6 +5234,50 @@ createReactor([selectBreakoutAssignments, selectDeviceId, selectLocalParticipant
5176
5234
  }
5177
5235
  });
5178
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
+
5179
5281
  function isCustomElementName(value) {
5180
5282
  return typeof value === "string" && value === value.toLowerCase() && value.includes("-");
5181
5283
  }
@@ -6160,6 +6262,7 @@ const appReducer = combineReducers({
6160
6262
  room: roomSlice.reducer,
6161
6263
  roomConnection: roomConnectionSlice.reducer,
6162
6264
  roomIntegrations: roomIntegrationsSlice.reducer,
6265
+ roomLayout: roomLayoutSlice.reducer,
6163
6266
  rtcAnalytics: rtcAnalyticsSlice.reducer,
6164
6267
  rtcConnection: rtcConnectionSlice.reducer,
6165
6268
  signalConnection: signalConnectionSlice.reducer,
@@ -6201,12 +6304,13 @@ const CLIENT_VIEW_SPOTLIGHTS_CHANGED = "grid:client-view-spotlights-changed";
6201
6304
  const NUMBER_OF_CLIENT_VIEWS_CHANGED = "grid:number-of-client-views-changed";
6202
6305
  const RUNNING_ROOM_INTEGRATIONS_CHANGED = "grid:running-room-integrations-changed";
6203
6306
 
6204
- 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) => {
6205
6308
  return {
6206
6309
  allClientViews,
6207
6310
  spotlightedParticipants,
6208
6311
  numParticipants: numClients,
6209
6312
  runningRoomIntegrations,
6313
+ canSpotlight,
6210
6314
  };
6211
6315
  });
6212
6316
 
@@ -6290,6 +6394,24 @@ class GridClient extends BaseClient {
6290
6394
  removeSpotlight(id) {
6291
6395
  this.store.dispatch(doRemoveSpotlight({ id }));
6292
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
+ }
6293
6415
  destroy() {
6294
6416
  super.destroy();
6295
6417
  this.clientViewSubscribers.clear();
@@ -76,7 +76,7 @@ const createReactor = (selectors, callback) => {
76
76
  });
77
77
  };
78
78
 
79
- const coreVersion = "1.32.0";
79
+ const coreVersion = "1.33.0";
80
80
 
81
81
  function decodeRoomName(roomName) {
82
82
  if (!roomName) {
@@ -179,6 +179,7 @@ const signalEvents = {
179
179
  screenshareEnableRequested: createSignalEventAction("screenshareEnableRequested"),
180
180
  spotlightAdded: createSignalEventAction("spotlightAdded"),
181
181
  spotlightRemoved: createSignalEventAction("spotlightRemoved"),
182
+ spotlightOrderSwapped: createSignalEventAction("spotlightOrderSwapped"),
182
183
  streamingStopped: createSignalEventAction("streamingStopped"),
183
184
  videoEnabled: createSignalEventAction("videoEnabled"),
184
185
  videoEnableRequested: createSignalEventAction("videoEnableRequested"),
@@ -375,6 +376,7 @@ function forwardSocketEvents(socket, dispatch) {
375
376
  socket.on("streaming_stopped", () => dispatch(signalEvents.streamingStopped()));
376
377
  socket.on("spotlight_added", (payload) => dispatch(signalEvents.spotlightAdded(payload)));
377
378
  socket.on("spotlight_removed", (payload) => dispatch(signalEvents.spotlightRemoved(payload)));
379
+ socket.on("spotlight_order_swapped", (payload) => dispatch(signalEvents.spotlightOrderSwapped(payload)));
378
380
  socket.on("live_transcription_started", (payload) => dispatch(signalEvents.liveTranscriptionStarted(payload)));
379
381
  socket.on("live_transcription_stopped", (payload) => dispatch(signalEvents.liveTranscriptionStopped(payload)));
380
382
  socket.on("live_captions_started", (payload) => dispatch(signalEvents.liveCaptionsStarted(payload)));
@@ -775,10 +777,14 @@ const doSetDevice = createAppAsyncThunk("localMedia/reactSetDevice", (_a, _b) =>
775
777
  const before = snapshotTracks(stream);
776
778
  const { replacedTracks } = yield media.getStream(Object.assign(Object.assign({}, constraintsOptions), { audioId,
777
779
  videoId, type: "exact" }), { replaceStream: stream });
778
- const isAudioEnabled = selectIsMicrophoneEnabled(state);
780
+ const isAudioEnabled = selectIsMicrophoneEnabled(getState());
779
781
  stream.getAudioTracks().forEach((track) => (track.enabled = isAudioEnabled));
780
- const isVideoEnabled = selectIsCameraEnabled(state);
781
- stream.getVideoTracks().forEach((track) => (track.enabled = isVideoEnabled));
782
+ if (!selectIsCameraEnabled(getState())) {
783
+ stream.getVideoTracks().forEach((track) => {
784
+ track.stop();
785
+ stream.removeTrack(track);
786
+ });
787
+ }
782
788
  return {
783
789
  replacedTracks,
784
790
  changedTracks: findChangedTracks(stream, before),
@@ -865,6 +871,14 @@ const doSwitchLocalStream = createAppAsyncThunk("localMedia/doSwitchLocalStream"
865
871
  deviceId,
866
872
  }));
867
873
  }
874
+ const isAudioEnabled = selectIsMicrophoneEnabled(getState());
875
+ replaceStream.getAudioTracks().forEach((track) => (track.enabled = isAudioEnabled));
876
+ if (!selectIsCameraEnabled(getState())) {
877
+ replaceStream.getVideoTracks().forEach((track) => {
878
+ track.stop();
879
+ replaceStream.removeTrack(track);
880
+ });
881
+ }
868
882
  return {
869
883
  replacedTracks,
870
884
  beforeEffectTracks,
@@ -2626,7 +2640,7 @@ createReactor([selectShouldFetchRoom], ({ dispatch, getState }, shouldFetchRoom)
2626
2640
 
2627
2641
  function streamIdForClient({ isPresentation, stream }) {
2628
2642
  var _a, _b;
2629
- 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 : media.CAMERA_STREAM_ID;
2643
+ 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) : media.CAMERA_STREAM_ID;
2630
2644
  }
2631
2645
  function isClientSpotlighted({ spotlights, isPresentation, clientId, stream, }) {
2632
2646
  return !!spotlights.find((s) => {
@@ -2641,6 +2655,17 @@ function mergeSpotlight(spotlights, spotlight) {
2641
2655
  }
2642
2656
  return spotlights.concat(spotlight);
2643
2657
  }
2658
+ const isSameSpotlight = (a, b) => a.clientId === b.clientId && a.streamId === b.streamId;
2659
+ function swapSpotlights(spotlights, source, target) {
2660
+ const index = spotlights.findIndex((s) => isSameSpotlight(s, source));
2661
+ const targetIndex = spotlights.findIndex((s) => isSameSpotlight(s, target));
2662
+ if (index < 0 || targetIndex < 0 || index === targetIndex) {
2663
+ return spotlights;
2664
+ }
2665
+ const swapped = [...spotlights];
2666
+ [swapped[index], swapped[targetIndex]] = [swapped[targetIndex], swapped[index]];
2667
+ return swapped;
2668
+ }
2644
2669
  function mapSpotlightsToClientViews(spotlights, clientViews) {
2645
2670
  return spotlights.reduce((acc, s) => {
2646
2671
  const clientView = clientViews.find((c) => s.clientId === c.clientId && s.streamId === streamIdForClient(c));
@@ -2686,6 +2711,14 @@ const spotlightsSlice = toolkit.createSlice({
2686
2711
  const { clientId, streamId } = action.payload;
2687
2712
  return Object.assign(Object.assign({}, state), { sorted: state.sorted.filter((s) => !(s.clientId === clientId && s.streamId === streamId)) });
2688
2713
  });
2714
+ builder.addCase(signalEvents.spotlightOrderSwapped, (state, action) => {
2715
+ if ("error" in action.payload) {
2716
+ return state;
2717
+ }
2718
+ const { source, target } = action.payload;
2719
+ const sorted = swapSpotlights(state.sorted, source, target);
2720
+ return sorted === state.sorted ? state : Object.assign(Object.assign({}, state), { sorted });
2721
+ });
2689
2722
  builder.addMatcher(toolkit.isAnyOf(signalEvents.clientKicked, signalEvents.clientLeft), (state, action) => {
2690
2723
  const { clientId } = action.payload;
2691
2724
  return Object.assign(Object.assign({}, state), { sorted: state.sorted.filter((s) => s.clientId !== clientId) });
@@ -2715,6 +2748,31 @@ const doRemoveSpotlight = createAppAuthorizedThunk((state) => selectIsAuthorized
2715
2748
  const payload = { clientId: clientView.id, streamId: streamId !== null && streamId !== void 0 ? streamId : media.CAMERA_STREAM_ID };
2716
2749
  socket === null || socket === void 0 ? void 0 : socket.emit("remove_spotlight", payload);
2717
2750
  });
2751
+ const doSwapSpotlightOrder = createAppAuthorizedThunk((state) => selectIsAuthorizedToSpotlight(state), ({ id, targetId }) => (_, getState) => {
2752
+ const state = getState();
2753
+ const clientViews = selectAllClientViews(state);
2754
+ const spotlights = selectSpotlights(state);
2755
+ const toSpotlight = (clientViewId) => {
2756
+ var _a;
2757
+ const clientView = clientViews.find((c) => c.id === clientViewId);
2758
+ if (!clientView) {
2759
+ return null;
2760
+ }
2761
+ const spotlight = {
2762
+ clientId: clientView.clientId,
2763
+ streamId: (_a = streamIdForClient(clientView)) !== null && _a !== void 0 ? _a : media.CAMERA_STREAM_ID,
2764
+ };
2765
+ return spotlights.some((s) => isSameSpotlight(s, spotlight)) ? spotlight : null;
2766
+ };
2767
+ const source = toSpotlight(id);
2768
+ const target = toSpotlight(targetId);
2769
+ if (!source || !target || isSameSpotlight(source, target)) {
2770
+ return;
2771
+ }
2772
+ const { socket } = selectSignalConnectionRaw(state);
2773
+ const payload = { source, target };
2774
+ socket === null || socket === void 0 ? void 0 : socket.emit("swap_spotlight_order", payload);
2775
+ });
2718
2776
  const selectSpotlightsRaw = (state) => state.spotlights;
2719
2777
  const selectSpotlights = (state) => state.spotlights.sorted;
2720
2778
  const selectIsLocalParticipantSpotlighted = toolkit.createSelector(selectLocalParticipantRaw, selectSpotlights, (localParticipant, spotlights) => {
@@ -3980,6 +4038,51 @@ createReactor([selectBreakoutAssignments, selectDeviceId, selectLocalParticipant
3980
4038
  }
3981
4039
  });
3982
4040
 
4041
+ const roomLayoutSliceInitialState = {
4042
+ sortedClientIds: [],
4043
+ };
4044
+ const roomLayoutSlice = toolkit.createSlice({
4045
+ name: "roomLayout",
4046
+ initialState: roomLayoutSliceInitialState,
4047
+ reducers: {
4048
+ setSortedClientIds(state, action) {
4049
+ return Object.assign(Object.assign({}, state), { sortedClientIds: Array.from(new Set(action.payload)) });
4050
+ },
4051
+ },
4052
+ });
4053
+ const { setSortedClientIds } = roomLayoutSlice.actions;
4054
+ const doReorderClientViews = createAppThunk(({ id, targetId }) => (dispatch, getState) => {
4055
+ const clientIds = selectSortedClientViews(getState()).map((c) => c.id);
4056
+ const index = clientIds.indexOf(id);
4057
+ const targetIndex = clientIds.indexOf(targetId);
4058
+ if (index < 0 || targetIndex < 0 || index === targetIndex) {
4059
+ return;
4060
+ }
4061
+ [clientIds[index], clientIds[targetIndex]] = [clientIds[targetIndex], clientIds[index]];
4062
+ dispatch(setSortedClientIds(clientIds));
4063
+ });
4064
+ const doSetClientViewOrder = createAppThunk((ids) => (dispatch, getState) => {
4065
+ const listed = new Set(ids);
4066
+ const unlisted = selectSortedClientViews(getState())
4067
+ .map((c) => c.id)
4068
+ .filter((id) => !listed.has(id));
4069
+ dispatch(setSortedClientIds([...ids, ...unlisted]));
4070
+ });
4071
+ const selectRoomLayoutRaw = (state) => state.roomLayout;
4072
+ const selectSortedClientIds = (state) => state.roomLayout.sortedClientIds;
4073
+ const selectSortedClientViews = toolkit.createSelector(selectAllClientViews, selectSortedClientIds, (clientViews, sortedClientIds) => sortClientViews({ sortedClientIds, clientViews }));
4074
+ function sortClientViews({ sortedClientIds, clientViews, }) {
4075
+ if (!sortedClientIds.length) {
4076
+ return clientViews;
4077
+ }
4078
+ const rank = new Map(sortedClientIds.map((id, index) => [id, index]));
4079
+ const unranked = sortedClientIds.length;
4080
+ return clientViews
4081
+ .map((clientView, index) => { var _a; return ({ clientView, index, rank: (_a = rank.get(clientView.id)) !== null && _a !== void 0 ? _a : unranked }); })
4082
+ .sort((a, b) => a.rank - b.rank || a.index - b.index)
4083
+ .map(({ clientView }) => clientView);
4084
+ }
4085
+
3983
4086
  function roomIntegrationContentTagName(integrationName) {
3984
4087
  return `${integrationName}-integration-contentframe`;
3985
4088
  }
@@ -4973,6 +5076,7 @@ const appReducer = toolkit.combineReducers({
4973
5076
  room: roomSlice.reducer,
4974
5077
  roomConnection: roomConnectionSlice.reducer,
4975
5078
  roomIntegrations: roomIntegrationsSlice.reducer,
5079
+ roomLayout: roomLayoutSlice.reducer,
4976
5080
  rtcAnalytics: rtcAnalyticsSlice.reducer,
4977
5081
  rtcConnection: rtcConnectionSlice.reducer,
4978
5082
  signalConnection: signalConnectionSlice.reducer,
@@ -6160,6 +6264,7 @@ exports.doOrganizationFetch = doOrganizationFetch;
6160
6264
  exports.doRejectWaitingParticipant = doRejectWaitingParticipant;
6161
6265
  exports.doRemoveChatMessage = doRemoveChatMessage;
6162
6266
  exports.doRemoveSpotlight = doRemoveSpotlight;
6267
+ exports.doReorderClientViews = doReorderClientViews;
6163
6268
  exports.doRequestAudioEnable = doRequestAudioEnable;
6164
6269
  exports.doRequestScreenshareEnable = doRequestScreenshareEnable;
6165
6270
  exports.doRequestVideoEnable = doRequestVideoEnable;
@@ -6170,6 +6275,7 @@ exports.doRtcReportStreamResolution = doRtcReportStreamResolution;
6170
6275
  exports.doSendChatMessage = doSendChatMessage;
6171
6276
  exports.doSendClientMetadata = doSendClientMetadata;
6172
6277
  exports.doSendFiles = doSendFiles;
6278
+ exports.doSetClientViewOrder = doSetClientViewOrder;
6173
6279
  exports.doSetDevice = doSetDevice;
6174
6280
  exports.doSetDisplayName = doSetDisplayName;
6175
6281
  exports.doSetLocalCallQualityScore = doSetLocalCallQualityScore;
@@ -6198,6 +6304,7 @@ exports.doStopLiveTranscription = doStopLiveTranscription;
6198
6304
  exports.doStopLocalMedia = doStopLocalMedia;
6199
6305
  exports.doStopRoomIntegration = doStopRoomIntegration;
6200
6306
  exports.doStopScreenshare = doStopScreenshare;
6307
+ exports.doSwapSpotlightOrder = doSwapSpotlightOrder;
6201
6308
  exports.doSwitchLocalStream = doSwitchLocalStream;
6202
6309
  exports.doToggleAudioOnlyMode = doToggleAudioOnlyMode;
6203
6310
  exports.doToggleCamera = doToggleCamera;
@@ -6250,6 +6357,8 @@ exports.roomIntegrationPickerUrl = roomIntegrationPickerUrl;
6250
6357
  exports.roomIntegrationSignalError = roomIntegrationSignalError;
6251
6358
  exports.roomIntegrationsSlice = roomIntegrationsSlice;
6252
6359
  exports.roomIntegrationsSliceInitialState = roomIntegrationsSliceInitialState;
6360
+ exports.roomLayoutSlice = roomLayoutSlice;
6361
+ exports.roomLayoutSliceInitialState = roomLayoutSliceInitialState;
6253
6362
  exports.roomRejoined = roomRejoined;
6254
6363
  exports.roomSlice = roomSlice;
6255
6364
  exports.roomSliceInitialState = roomSliceInitialState;
@@ -6428,6 +6537,7 @@ exports.selectRoomIntegrationsIsFetching = selectRoomIntegrationsIsFetching;
6428
6537
  exports.selectRoomIntegrationsRaw = selectRoomIntegrationsRaw;
6429
6538
  exports.selectRoomIsLocked = selectRoomIsLocked;
6430
6539
  exports.selectRoomKey = selectRoomKey;
6540
+ exports.selectRoomLayoutRaw = selectRoomLayoutRaw;
6431
6541
  exports.selectRoomLockState = selectRoomLockState;
6432
6542
  exports.selectRoomLockStateRoomUrl = selectRoomLockStateRoomUrl;
6433
6543
  exports.selectRoomLockStateSource = selectRoomLockStateSource;
@@ -6460,6 +6570,8 @@ exports.selectSignalConnectionRaw = selectSignalConnectionRaw;
6460
6570
  exports.selectSignalConnectionSocket = selectSignalConnectionSocket;
6461
6571
  exports.selectSignalIsIdentifyingDevice = selectSignalIsIdentifyingDevice;
6462
6572
  exports.selectSignalStatus = selectSignalStatus;
6573
+ exports.selectSortedClientIds = selectSortedClientIds;
6574
+ exports.selectSortedClientViews = selectSortedClientViews;
6463
6575
  exports.selectSpeakerDevices = selectSpeakerDevices;
6464
6576
  exports.selectSpotlightedClientViews = selectSpotlightedClientViews;
6465
6577
  exports.selectSpotlights = selectSpotlights;
@@ -6481,6 +6593,7 @@ exports.setLocalMediaStream = setLocalMediaStream;
6481
6593
  exports.setRequestedRoomUrl = setRequestedRoomUrl;
6482
6594
  exports.setRoomIntegrationsError = setRoomIntegrationsError;
6483
6595
  exports.setRoomKey = setRoomKey;
6596
+ exports.setSortedClientIds = setSortedClientIds;
6484
6597
  exports.signalConnectionSlice = signalConnectionSlice;
6485
6598
  exports.signalConnectionSliceInitialState = signalConnectionSliceInitialState;
6486
6599
  exports.signalEvents = signalEvents;
@@ -6488,6 +6601,7 @@ exports.socketConnected = socketConnected;
6488
6601
  exports.socketConnecting = socketConnecting;
6489
6602
  exports.socketDisconnected = socketDisconnected;
6490
6603
  exports.socketReconnecting = socketReconnecting;
6604
+ exports.sortClientViews = sortClientViews;
6491
6605
  exports.spotlightsSlice = spotlightsSlice;
6492
6606
  exports.spotlightsSliceInitialState = spotlightsSliceInitialState;
6493
6607
  exports.startAppListening = startAppListening;