@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.
@@ -76,7 +76,7 @@ const createReactor = (selectors, callback) => {
76
76
  });
77
77
  };
78
78
 
79
- const coreVersion = "1.32.1";
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)));
@@ -2638,7 +2640,7 @@ createReactor([selectShouldFetchRoom], ({ dispatch, getState }, shouldFetchRoom)
2638
2640
 
2639
2641
  function streamIdForClient({ isPresentation, stream }) {
2640
2642
  var _a, _b;
2641
- 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;
2642
2644
  }
2643
2645
  function isClientSpotlighted({ spotlights, isPresentation, clientId, stream, }) {
2644
2646
  return !!spotlights.find((s) => {
@@ -2653,6 +2655,17 @@ function mergeSpotlight(spotlights, spotlight) {
2653
2655
  }
2654
2656
  return spotlights.concat(spotlight);
2655
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
+ }
2656
2669
  function mapSpotlightsToClientViews(spotlights, clientViews) {
2657
2670
  return spotlights.reduce((acc, s) => {
2658
2671
  const clientView = clientViews.find((c) => s.clientId === c.clientId && s.streamId === streamIdForClient(c));
@@ -2698,6 +2711,14 @@ const spotlightsSlice = toolkit.createSlice({
2698
2711
  const { clientId, streamId } = action.payload;
2699
2712
  return Object.assign(Object.assign({}, state), { sorted: state.sorted.filter((s) => !(s.clientId === clientId && s.streamId === streamId)) });
2700
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
+ });
2701
2722
  builder.addMatcher(toolkit.isAnyOf(signalEvents.clientKicked, signalEvents.clientLeft), (state, action) => {
2702
2723
  const { clientId } = action.payload;
2703
2724
  return Object.assign(Object.assign({}, state), { sorted: state.sorted.filter((s) => s.clientId !== clientId) });
@@ -2727,6 +2748,31 @@ const doRemoveSpotlight = createAppAuthorizedThunk((state) => selectIsAuthorized
2727
2748
  const payload = { clientId: clientView.id, streamId: streamId !== null && streamId !== void 0 ? streamId : media.CAMERA_STREAM_ID };
2728
2749
  socket === null || socket === void 0 ? void 0 : socket.emit("remove_spotlight", payload);
2729
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
+ });
2730
2776
  const selectSpotlightsRaw = (state) => state.spotlights;
2731
2777
  const selectSpotlights = (state) => state.spotlights.sorted;
2732
2778
  const selectIsLocalParticipantSpotlighted = toolkit.createSelector(selectLocalParticipantRaw, selectSpotlights, (localParticipant, spotlights) => {
@@ -3992,6 +4038,51 @@ createReactor([selectBreakoutAssignments, selectDeviceId, selectLocalParticipant
3992
4038
  }
3993
4039
  });
3994
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
+
3995
4086
  function roomIntegrationContentTagName(integrationName) {
3996
4087
  return `${integrationName}-integration-contentframe`;
3997
4088
  }
@@ -4985,6 +5076,7 @@ const appReducer = toolkit.combineReducers({
4985
5076
  room: roomSlice.reducer,
4986
5077
  roomConnection: roomConnectionSlice.reducer,
4987
5078
  roomIntegrations: roomIntegrationsSlice.reducer,
5079
+ roomLayout: roomLayoutSlice.reducer,
4988
5080
  rtcAnalytics: rtcAnalyticsSlice.reducer,
4989
5081
  rtcConnection: rtcConnectionSlice.reducer,
4990
5082
  signalConnection: signalConnectionSlice.reducer,
@@ -6172,6 +6264,7 @@ exports.doOrganizationFetch = doOrganizationFetch;
6172
6264
  exports.doRejectWaitingParticipant = doRejectWaitingParticipant;
6173
6265
  exports.doRemoveChatMessage = doRemoveChatMessage;
6174
6266
  exports.doRemoveSpotlight = doRemoveSpotlight;
6267
+ exports.doReorderClientViews = doReorderClientViews;
6175
6268
  exports.doRequestAudioEnable = doRequestAudioEnable;
6176
6269
  exports.doRequestScreenshareEnable = doRequestScreenshareEnable;
6177
6270
  exports.doRequestVideoEnable = doRequestVideoEnable;
@@ -6182,6 +6275,7 @@ exports.doRtcReportStreamResolution = doRtcReportStreamResolution;
6182
6275
  exports.doSendChatMessage = doSendChatMessage;
6183
6276
  exports.doSendClientMetadata = doSendClientMetadata;
6184
6277
  exports.doSendFiles = doSendFiles;
6278
+ exports.doSetClientViewOrder = doSetClientViewOrder;
6185
6279
  exports.doSetDevice = doSetDevice;
6186
6280
  exports.doSetDisplayName = doSetDisplayName;
6187
6281
  exports.doSetLocalCallQualityScore = doSetLocalCallQualityScore;
@@ -6210,6 +6304,7 @@ exports.doStopLiveTranscription = doStopLiveTranscription;
6210
6304
  exports.doStopLocalMedia = doStopLocalMedia;
6211
6305
  exports.doStopRoomIntegration = doStopRoomIntegration;
6212
6306
  exports.doStopScreenshare = doStopScreenshare;
6307
+ exports.doSwapSpotlightOrder = doSwapSpotlightOrder;
6213
6308
  exports.doSwitchLocalStream = doSwitchLocalStream;
6214
6309
  exports.doToggleAudioOnlyMode = doToggleAudioOnlyMode;
6215
6310
  exports.doToggleCamera = doToggleCamera;
@@ -6262,6 +6357,8 @@ exports.roomIntegrationPickerUrl = roomIntegrationPickerUrl;
6262
6357
  exports.roomIntegrationSignalError = roomIntegrationSignalError;
6263
6358
  exports.roomIntegrationsSlice = roomIntegrationsSlice;
6264
6359
  exports.roomIntegrationsSliceInitialState = roomIntegrationsSliceInitialState;
6360
+ exports.roomLayoutSlice = roomLayoutSlice;
6361
+ exports.roomLayoutSliceInitialState = roomLayoutSliceInitialState;
6265
6362
  exports.roomRejoined = roomRejoined;
6266
6363
  exports.roomSlice = roomSlice;
6267
6364
  exports.roomSliceInitialState = roomSliceInitialState;
@@ -6440,6 +6537,7 @@ exports.selectRoomIntegrationsIsFetching = selectRoomIntegrationsIsFetching;
6440
6537
  exports.selectRoomIntegrationsRaw = selectRoomIntegrationsRaw;
6441
6538
  exports.selectRoomIsLocked = selectRoomIsLocked;
6442
6539
  exports.selectRoomKey = selectRoomKey;
6540
+ exports.selectRoomLayoutRaw = selectRoomLayoutRaw;
6443
6541
  exports.selectRoomLockState = selectRoomLockState;
6444
6542
  exports.selectRoomLockStateRoomUrl = selectRoomLockStateRoomUrl;
6445
6543
  exports.selectRoomLockStateSource = selectRoomLockStateSource;
@@ -6472,6 +6570,8 @@ exports.selectSignalConnectionRaw = selectSignalConnectionRaw;
6472
6570
  exports.selectSignalConnectionSocket = selectSignalConnectionSocket;
6473
6571
  exports.selectSignalIsIdentifyingDevice = selectSignalIsIdentifyingDevice;
6474
6572
  exports.selectSignalStatus = selectSignalStatus;
6573
+ exports.selectSortedClientIds = selectSortedClientIds;
6574
+ exports.selectSortedClientViews = selectSortedClientViews;
6475
6575
  exports.selectSpeakerDevices = selectSpeakerDevices;
6476
6576
  exports.selectSpotlightedClientViews = selectSpotlightedClientViews;
6477
6577
  exports.selectSpotlights = selectSpotlights;
@@ -6493,6 +6593,7 @@ exports.setLocalMediaStream = setLocalMediaStream;
6493
6593
  exports.setRequestedRoomUrl = setRequestedRoomUrl;
6494
6594
  exports.setRoomIntegrationsError = setRoomIntegrationsError;
6495
6595
  exports.setRoomKey = setRoomKey;
6596
+ exports.setSortedClientIds = setSortedClientIds;
6496
6597
  exports.signalConnectionSlice = signalConnectionSlice;
6497
6598
  exports.signalConnectionSliceInitialState = signalConnectionSliceInitialState;
6498
6599
  exports.signalEvents = signalEvents;
@@ -6500,6 +6601,7 @@ exports.socketConnected = socketConnected;
6500
6601
  exports.socketConnecting = socketConnecting;
6501
6602
  exports.socketDisconnected = socketDisconnected;
6502
6603
  exports.socketReconnecting = socketReconnecting;
6604
+ exports.sortClientViews = sortClientViews;
6503
6605
  exports.spotlightsSlice = spotlightsSlice;
6504
6606
  exports.spotlightsSliceInitialState = spotlightsSliceInitialState;
6505
6607
  exports.startAppListening = startAppListening;