@whereby.com/core 1.31.5 → 1.31.7

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.cjs CHANGED
@@ -1314,7 +1314,7 @@ const createReactor = (selectors, callback) => {
1314
1314
  });
1315
1315
  };
1316
1316
 
1317
- const coreVersion = "1.31.5";
1317
+ const coreVersion = "1.31.7";
1318
1318
 
1319
1319
  function decodeRoomName(roomName) {
1320
1320
  if (!roomName) {
@@ -1911,6 +1911,17 @@ const localMediaSlice = toolkit.createSlice({
1911
1911
  });
1912
1912
  },
1913
1913
  });
1914
+ const snapshotTracks = (stream) => ({
1915
+ audio: stream.getAudioTracks()[0] || null,
1916
+ video: stream.getVideoTracks()[0] || null,
1917
+ });
1918
+ const findChangedTracks = (stream, before) => {
1919
+ const after = snapshotTracks(stream);
1920
+ return ["audio", "video"].flatMap((kind) => {
1921
+ const track = after[kind];
1922
+ return track && track !== before[kind] ? [{ track, oldTrack: before[kind] }] : [];
1923
+ });
1924
+ };
1914
1925
  const { deviceBusy, setCurrentCameraDeviceId, setCurrentMicrophoneDeviceId, setCurrentSpeakerDeviceId, toggleCameraEnabled, toggleMicrophoneEnabled, toggleHdModeEnabled, toggleLowDataModeEnabled, toggleWidescreenModeEnabled, setLocalMediaOptions, setLocalMediaStream, localMediaStopped, localStreamMetadataUpdated, } = localMediaSlice.actions;
1915
1926
  const doToggleCamera = createAppAsyncThunk("localMedia/doToggleCamera", (_1, _a) => __awaiter(void 0, [_1, _a], void 0, function* (_, { getState, rejectWithValue }) {
1916
1927
  const state = getState();
@@ -1918,8 +1929,9 @@ const doToggleCamera = createAppAsyncThunk("localMedia/doToggleCamera", (_1, _a)
1918
1929
  if (!stream) {
1919
1930
  return;
1920
1931
  }
1921
- let track = stream.getVideoTracks()[0];
1932
+ const track = stream.getVideoTracks()[0];
1922
1933
  const enabled = selectIsCameraEnabled(state);
1934
+ const before = snapshotTracks(stream);
1923
1935
  try {
1924
1936
  if (enabled) {
1925
1937
  if (track) {
@@ -1929,7 +1941,6 @@ const doToggleCamera = createAppAsyncThunk("localMedia/doToggleCamera", (_1, _a)
1929
1941
  const constraintsOptions = selectLocalMediaConstraintsOptions(state);
1930
1942
  const cameraDeviceId = selectCurrentCameraDeviceId(state);
1931
1943
  yield media.getStream(Object.assign(Object.assign({}, constraintsOptions), { audioId: false, videoId: cameraDeviceId, type: "exact" }), { replaceStream: stream });
1932
- track = stream.getVideoTracks()[0];
1933
1944
  }
1934
1945
  }
1935
1946
  else {
@@ -1940,7 +1951,7 @@ const doToggleCamera = createAppAsyncThunk("localMedia/doToggleCamera", (_1, _a)
1940
1951
  track.stop();
1941
1952
  stream.removeTrack(track);
1942
1953
  }
1943
- stream.dispatchEvent(new CustomEvent("stopresumevideo", { detail: { track, enable: enabled } }));
1954
+ return { changedTracks: findChangedTracks(stream, before) };
1944
1955
  }
1945
1956
  catch (error) {
1946
1957
  return rejectWithValue(error);
@@ -1970,13 +1981,17 @@ const doSetDevice = createAppAsyncThunk("localMedia/reactSetDevice", (_a, _b) =>
1970
1981
  const audioId = audio ? selectCurrentMicrophoneDeviceId(state) : false;
1971
1982
  const videoId = video ? selectCurrentCameraDeviceId(state) : false;
1972
1983
  const constraintsOptions = selectLocalMediaConstraintsOptions(state);
1984
+ const before = snapshotTracks(stream);
1973
1985
  const { replacedTracks } = yield media.getStream(Object.assign(Object.assign({}, constraintsOptions), { audioId,
1974
1986
  videoId, type: "exact" }), { replaceStream: stream });
1975
1987
  const isAudioEnabled = selectIsMicrophoneEnabled(state);
1976
1988
  stream.getAudioTracks().forEach((track) => (track.enabled = isAudioEnabled));
1977
1989
  const isVideoEnabled = selectIsCameraEnabled(state);
1978
1990
  stream.getVideoTracks().forEach((track) => (track.enabled = isVideoEnabled));
1979
- return { replacedTracks };
1991
+ return {
1992
+ replacedTracks,
1993
+ changedTracks: findChangedTracks(stream, before),
1994
+ };
1980
1995
  }
1981
1996
  catch (error) {
1982
1997
  return rejectWithValue(error);
@@ -2050,6 +2065,7 @@ const doSwitchLocalStream = createAppAsyncThunk("localMedia/doSwitchLocalStream"
2050
2065
  beforeEffectTracks.video = undefined;
2051
2066
  }
2052
2067
  const hasLiveTrackFromDevice = (deviceId) => (audioId ? replaceStream.getAudioTracks() : replaceStream.getVideoTracks()).some((track) => track.readyState === "live" && track.getSettings().deviceId === deviceId);
2068
+ const before = snapshotTracks(replaceStream);
2053
2069
  try {
2054
2070
  const { replacedTracks } = yield media.getStream(Object.assign(Object.assign({}, constraintsOptions), { audioId: audioId === undefined ? false : audioId, videoId: videoId === undefined ? false : videoId, type: "exact" }), { replaceStream });
2055
2071
  const deviceId = audioId || videoId;
@@ -2058,7 +2074,11 @@ const doSwitchLocalStream = createAppAsyncThunk("localMedia/doSwitchLocalStream"
2058
2074
  deviceId,
2059
2075
  }));
2060
2076
  }
2061
- return { replacedTracks, beforeEffectTracks };
2077
+ return {
2078
+ replacedTracks,
2079
+ beforeEffectTracks,
2080
+ changedTracks: findChangedTracks(replaceStream, before),
2081
+ };
2062
2082
  }
2063
2083
  catch (error) {
2064
2084
  console.error(error);
@@ -2127,6 +2147,7 @@ const doLocalStreamEffect = createAppAsyncThunk("localMedia/doLocalStreamEffect"
2127
2147
  if (!stream) {
2128
2148
  throw new Error("No local media stream");
2129
2149
  }
2150
+ const before = snapshotTracks(stream);
2130
2151
  if (effectStream) {
2131
2152
  if (!beforeTrack) {
2132
2153
  beforeEffectTracks = {
@@ -2147,7 +2168,12 @@ const doLocalStreamEffect = createAppAsyncThunk("localMedia/doLocalStreamEffect"
2147
2168
  };
2148
2169
  beforeTrack.stop();
2149
2170
  }
2150
- return { effectStream, beforeEffectTracks, replacedTracks };
2171
+ return {
2172
+ effectStream,
2173
+ beforeEffectTracks,
2174
+ replacedTracks,
2175
+ changedTracks: findChangedTracks(stream, before),
2176
+ };
2151
2177
  }
2152
2178
  catch (error) {
2153
2179
  console.error("Error applying local stream effect", error);
@@ -4067,19 +4093,21 @@ const selectRtcIsCreatingDispatcher = (state) => state.rtcConnection.isCreatingD
4067
4093
  const selectRtcStatus = (state) => state.rtcConnection.status;
4068
4094
  const selectIsAcceptingStreams = (state) => state.rtcConnection.isAcceptingStreams;
4069
4095
  const selectIsAudioOnlyModeEnabled = (state) => state.rtcConnection.isAudioOnlyModeEnabled;
4096
+ const handOverChangedTracks = ({ payload }, { getState }) => {
4097
+ const { rtcManager } = selectRtcConnectionRaw(getState());
4098
+ payload === null || payload === void 0 ? void 0 : payload.changedTracks.forEach(({ track, oldTrack }) => {
4099
+ rtcManager === null || rtcManager === void 0 ? void 0 : rtcManager.replaceTrack(oldTrack, track);
4100
+ });
4101
+ };
4102
+ startAppListening({ actionCreator: doSetDevice.fulfilled, effect: handOverChangedTracks });
4103
+ startAppListening({ actionCreator: doSwitchLocalStream.fulfilled, effect: handOverChangedTracks });
4104
+ startAppListening({ actionCreator: doLocalStreamEffect.fulfilled, effect: handOverChangedTracks });
4070
4105
  startAppListening({
4071
- actionCreator: doSetDevice.fulfilled,
4072
- effect: ({ payload }, { getState }) => {
4073
- const { replacedTracks } = payload;
4106
+ actionCreator: doToggleCamera.fulfilled,
4107
+ effect: (action, { getState }) => {
4108
+ handOverChangedTracks(action, { getState });
4074
4109
  const { rtcManager } = selectRtcConnectionRaw(getState());
4075
- const stream = selectLocalMediaStream(getState());
4076
- const replace = (kind, oldTrack) => {
4077
- const track = stream === null || stream === void 0 ? void 0 : stream.getTracks().find((t) => t.kind === kind);
4078
- return track && (rtcManager === null || rtcManager === void 0 ? void 0 : rtcManager.replaceTrack(oldTrack, track));
4079
- };
4080
- replacedTracks === null || replacedTracks === void 0 ? void 0 : replacedTracks.forEach((t) => {
4081
- replace(t.kind, t);
4082
- });
4110
+ rtcManager === null || rtcManager === void 0 ? void 0 : rtcManager.stopOrResumeVideo({ enable: selectIsCameraEnabled(getState()) });
4083
4111
  },
4084
4112
  });
4085
4113
  startAppListening({
@@ -4113,23 +4141,6 @@ startAppListening({
4113
4141
  rtcManager === null || rtcManager === void 0 ? void 0 : rtcManager.removeScreenshareStream(stream);
4114
4142
  },
4115
4143
  });
4116
- startAppListening({
4117
- matcher: toolkit.isAnyOf(doSwitchLocalStream.fulfilled, doLocalStreamEffect.fulfilled),
4118
- effect: ({ payload }, { getState }) => {
4119
- var _a;
4120
- const stream = selectLocalMediaStream(getState());
4121
- const { rtcManager } = selectRtcConnectionRaw(getState());
4122
- if (stream && rtcManager) {
4123
- const replace = (kind, oldTrack) => {
4124
- const track = stream.getTracks().find((t) => t.kind === kind);
4125
- return track && rtcManager.replaceTrack(oldTrack, track);
4126
- };
4127
- (_a = payload === null || payload === void 0 ? void 0 : payload.replacedTracks) === null || _a === void 0 ? void 0 : _a.forEach((t) => {
4128
- replace(t.kind, t);
4129
- });
4130
- }
4131
- },
4132
- });
4133
4144
  startAppListening({
4134
4145
  actionCreator: audioOnlyModeToggled,
4135
4146
  effect: (_, { getState }) => {