@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.
@@ -74,7 +74,7 @@ const createReactor = (selectors, callback) => {
74
74
  });
75
75
  };
76
76
 
77
- const coreVersion = "1.31.5";
77
+ const coreVersion = "1.31.7";
78
78
 
79
79
  function decodeRoomName(roomName) {
80
80
  if (!roomName) {
@@ -690,6 +690,17 @@ const localMediaSlice = createSlice({
690
690
  });
691
691
  },
692
692
  });
693
+ const snapshotTracks = (stream) => ({
694
+ audio: stream.getAudioTracks()[0] || null,
695
+ video: stream.getVideoTracks()[0] || null,
696
+ });
697
+ const findChangedTracks = (stream, before) => {
698
+ const after = snapshotTracks(stream);
699
+ return ["audio", "video"].flatMap((kind) => {
700
+ const track = after[kind];
701
+ return track && track !== before[kind] ? [{ track, oldTrack: before[kind] }] : [];
702
+ });
703
+ };
693
704
  const { deviceBusy, setCurrentCameraDeviceId, setCurrentMicrophoneDeviceId, setCurrentSpeakerDeviceId, toggleCameraEnabled, toggleMicrophoneEnabled, toggleHdModeEnabled, toggleLowDataModeEnabled, toggleWidescreenModeEnabled, setLocalMediaOptions, setLocalMediaStream, localMediaStopped, localStreamMetadataUpdated, } = localMediaSlice.actions;
694
705
  const doToggleCamera = createAppAsyncThunk("localMedia/doToggleCamera", (_1, _a) => __awaiter(void 0, [_1, _a], void 0, function* (_, { getState, rejectWithValue }) {
695
706
  const state = getState();
@@ -697,8 +708,9 @@ const doToggleCamera = createAppAsyncThunk("localMedia/doToggleCamera", (_1, _a)
697
708
  if (!stream) {
698
709
  return;
699
710
  }
700
- let track = stream.getVideoTracks()[0];
711
+ const track = stream.getVideoTracks()[0];
701
712
  const enabled = selectIsCameraEnabled(state);
713
+ const before = snapshotTracks(stream);
702
714
  try {
703
715
  if (enabled) {
704
716
  if (track) {
@@ -708,7 +720,6 @@ const doToggleCamera = createAppAsyncThunk("localMedia/doToggleCamera", (_1, _a)
708
720
  const constraintsOptions = selectLocalMediaConstraintsOptions(state);
709
721
  const cameraDeviceId = selectCurrentCameraDeviceId(state);
710
722
  yield getStream(Object.assign(Object.assign({}, constraintsOptions), { audioId: false, videoId: cameraDeviceId, type: "exact" }), { replaceStream: stream });
711
- track = stream.getVideoTracks()[0];
712
723
  }
713
724
  }
714
725
  else {
@@ -719,7 +730,7 @@ const doToggleCamera = createAppAsyncThunk("localMedia/doToggleCamera", (_1, _a)
719
730
  track.stop();
720
731
  stream.removeTrack(track);
721
732
  }
722
- stream.dispatchEvent(new CustomEvent("stopresumevideo", { detail: { track, enable: enabled } }));
733
+ return { changedTracks: findChangedTracks(stream, before) };
723
734
  }
724
735
  catch (error) {
725
736
  return rejectWithValue(error);
@@ -759,13 +770,17 @@ const doSetDevice = createAppAsyncThunk("localMedia/reactSetDevice", (_a, _b) =>
759
770
  const audioId = audio ? selectCurrentMicrophoneDeviceId(state) : false;
760
771
  const videoId = video ? selectCurrentCameraDeviceId(state) : false;
761
772
  const constraintsOptions = selectLocalMediaConstraintsOptions(state);
773
+ const before = snapshotTracks(stream);
762
774
  const { replacedTracks } = yield getStream(Object.assign(Object.assign({}, constraintsOptions), { audioId,
763
775
  videoId, type: "exact" }), { replaceStream: stream });
764
776
  const isAudioEnabled = selectIsMicrophoneEnabled(state);
765
777
  stream.getAudioTracks().forEach((track) => (track.enabled = isAudioEnabled));
766
778
  const isVideoEnabled = selectIsCameraEnabled(state);
767
779
  stream.getVideoTracks().forEach((track) => (track.enabled = isVideoEnabled));
768
- return { replacedTracks };
780
+ return {
781
+ replacedTracks,
782
+ changedTracks: findChangedTracks(stream, before),
783
+ };
769
784
  }
770
785
  catch (error) {
771
786
  return rejectWithValue(error);
@@ -839,6 +854,7 @@ const doSwitchLocalStream = createAppAsyncThunk("localMedia/doSwitchLocalStream"
839
854
  beforeEffectTracks.video = undefined;
840
855
  }
841
856
  const hasLiveTrackFromDevice = (deviceId) => (audioId ? replaceStream.getAudioTracks() : replaceStream.getVideoTracks()).some((track) => track.readyState === "live" && track.getSettings().deviceId === deviceId);
857
+ const before = snapshotTracks(replaceStream);
842
858
  try {
843
859
  const { replacedTracks } = yield getStream(Object.assign(Object.assign({}, constraintsOptions), { audioId: audioId === undefined ? false : audioId, videoId: videoId === undefined ? false : videoId, type: "exact" }), { replaceStream });
844
860
  const deviceId = audioId || videoId;
@@ -847,7 +863,11 @@ const doSwitchLocalStream = createAppAsyncThunk("localMedia/doSwitchLocalStream"
847
863
  deviceId,
848
864
  }));
849
865
  }
850
- return { replacedTracks, beforeEffectTracks };
866
+ return {
867
+ replacedTracks,
868
+ beforeEffectTracks,
869
+ changedTracks: findChangedTracks(replaceStream, before),
870
+ };
851
871
  }
852
872
  catch (error) {
853
873
  console.error(error);
@@ -916,6 +936,7 @@ const doLocalStreamEffect = createAppAsyncThunk("localMedia/doLocalStreamEffect"
916
936
  if (!stream) {
917
937
  throw new Error("No local media stream");
918
938
  }
939
+ const before = snapshotTracks(stream);
919
940
  if (effectStream) {
920
941
  if (!beforeTrack) {
921
942
  beforeEffectTracks = {
@@ -936,7 +957,12 @@ const doLocalStreamEffect = createAppAsyncThunk("localMedia/doLocalStreamEffect"
936
957
  };
937
958
  beforeTrack.stop();
938
959
  }
939
- return { effectStream, beforeEffectTracks, replacedTracks };
960
+ return {
961
+ effectStream,
962
+ beforeEffectTracks,
963
+ replacedTracks,
964
+ changedTracks: findChangedTracks(stream, before),
965
+ };
940
966
  }
941
967
  catch (error) {
942
968
  console.error("Error applying local stream effect", error);
@@ -2869,19 +2895,21 @@ const selectRtcIsCreatingDispatcher = (state) => state.rtcConnection.isCreatingD
2869
2895
  const selectRtcStatus = (state) => state.rtcConnection.status;
2870
2896
  const selectIsAcceptingStreams = (state) => state.rtcConnection.isAcceptingStreams;
2871
2897
  const selectIsAudioOnlyModeEnabled = (state) => state.rtcConnection.isAudioOnlyModeEnabled;
2898
+ const handOverChangedTracks = ({ payload }, { getState }) => {
2899
+ const { rtcManager } = selectRtcConnectionRaw(getState());
2900
+ payload === null || payload === void 0 ? void 0 : payload.changedTracks.forEach(({ track, oldTrack }) => {
2901
+ rtcManager === null || rtcManager === void 0 ? void 0 : rtcManager.replaceTrack(oldTrack, track);
2902
+ });
2903
+ };
2904
+ startAppListening({ actionCreator: doSetDevice.fulfilled, effect: handOverChangedTracks });
2905
+ startAppListening({ actionCreator: doSwitchLocalStream.fulfilled, effect: handOverChangedTracks });
2906
+ startAppListening({ actionCreator: doLocalStreamEffect.fulfilled, effect: handOverChangedTracks });
2872
2907
  startAppListening({
2873
- actionCreator: doSetDevice.fulfilled,
2874
- effect: ({ payload }, { getState }) => {
2875
- const { replacedTracks } = payload;
2908
+ actionCreator: doToggleCamera.fulfilled,
2909
+ effect: (action, { getState }) => {
2910
+ handOverChangedTracks(action, { getState });
2876
2911
  const { rtcManager } = selectRtcConnectionRaw(getState());
2877
- const stream = selectLocalMediaStream(getState());
2878
- const replace = (kind, oldTrack) => {
2879
- const track = stream === null || stream === void 0 ? void 0 : stream.getTracks().find((t) => t.kind === kind);
2880
- return track && (rtcManager === null || rtcManager === void 0 ? void 0 : rtcManager.replaceTrack(oldTrack, track));
2881
- };
2882
- replacedTracks === null || replacedTracks === void 0 ? void 0 : replacedTracks.forEach((t) => {
2883
- replace(t.kind, t);
2884
- });
2912
+ rtcManager === null || rtcManager === void 0 ? void 0 : rtcManager.stopOrResumeVideo({ enable: selectIsCameraEnabled(getState()) });
2885
2913
  },
2886
2914
  });
2887
2915
  startAppListening({
@@ -2915,23 +2943,6 @@ startAppListening({
2915
2943
  rtcManager === null || rtcManager === void 0 ? void 0 : rtcManager.removeScreenshareStream(stream);
2916
2944
  },
2917
2945
  });
2918
- startAppListening({
2919
- matcher: isAnyOf(doSwitchLocalStream.fulfilled, doLocalStreamEffect.fulfilled),
2920
- effect: ({ payload }, { getState }) => {
2921
- var _a;
2922
- const stream = selectLocalMediaStream(getState());
2923
- const { rtcManager } = selectRtcConnectionRaw(getState());
2924
- if (stream && rtcManager) {
2925
- const replace = (kind, oldTrack) => {
2926
- const track = stream.getTracks().find((t) => t.kind === kind);
2927
- return track && rtcManager.replaceTrack(oldTrack, track);
2928
- };
2929
- (_a = payload === null || payload === void 0 ? void 0 : payload.replacedTracks) === null || _a === void 0 ? void 0 : _a.forEach((t) => {
2930
- replace(t.kind, t);
2931
- });
2932
- }
2933
- },
2934
- });
2935
2946
  startAppListening({
2936
2947
  actionCreator: audioOnlyModeToggled,
2937
2948
  effect: (_, { getState }) => {
@@ -74,7 +74,7 @@ const createReactor = (selectors, callback) => {
74
74
  });
75
75
  };
76
76
 
77
- const coreVersion = "1.31.5";
77
+ const coreVersion = "1.31.7";
78
78
 
79
79
  function decodeRoomName(roomName) {
80
80
  if (!roomName) {
@@ -690,6 +690,17 @@ const localMediaSlice = createSlice({
690
690
  });
691
691
  },
692
692
  });
693
+ const snapshotTracks = (stream) => ({
694
+ audio: stream.getAudioTracks()[0] || null,
695
+ video: stream.getVideoTracks()[0] || null,
696
+ });
697
+ const findChangedTracks = (stream, before) => {
698
+ const after = snapshotTracks(stream);
699
+ return ["audio", "video"].flatMap((kind) => {
700
+ const track = after[kind];
701
+ return track && track !== before[kind] ? [{ track, oldTrack: before[kind] }] : [];
702
+ });
703
+ };
693
704
  const { deviceBusy, setCurrentCameraDeviceId, setCurrentMicrophoneDeviceId, setCurrentSpeakerDeviceId, toggleCameraEnabled, toggleMicrophoneEnabled, toggleHdModeEnabled, toggleLowDataModeEnabled, toggleWidescreenModeEnabled, setLocalMediaOptions, setLocalMediaStream, localMediaStopped, localStreamMetadataUpdated, } = localMediaSlice.actions;
694
705
  const doToggleCamera = createAppAsyncThunk("localMedia/doToggleCamera", (_1, _a) => __awaiter(void 0, [_1, _a], void 0, function* (_, { getState, rejectWithValue }) {
695
706
  const state = getState();
@@ -697,8 +708,9 @@ const doToggleCamera = createAppAsyncThunk("localMedia/doToggleCamera", (_1, _a)
697
708
  if (!stream) {
698
709
  return;
699
710
  }
700
- let track = stream.getVideoTracks()[0];
711
+ const track = stream.getVideoTracks()[0];
701
712
  const enabled = selectIsCameraEnabled(state);
713
+ const before = snapshotTracks(stream);
702
714
  try {
703
715
  if (enabled) {
704
716
  if (track) {
@@ -708,7 +720,6 @@ const doToggleCamera = createAppAsyncThunk("localMedia/doToggleCamera", (_1, _a)
708
720
  const constraintsOptions = selectLocalMediaConstraintsOptions(state);
709
721
  const cameraDeviceId = selectCurrentCameraDeviceId(state);
710
722
  yield getStream(Object.assign(Object.assign({}, constraintsOptions), { audioId: false, videoId: cameraDeviceId, type: "exact" }), { replaceStream: stream });
711
- track = stream.getVideoTracks()[0];
712
723
  }
713
724
  }
714
725
  else {
@@ -719,7 +730,7 @@ const doToggleCamera = createAppAsyncThunk("localMedia/doToggleCamera", (_1, _a)
719
730
  track.stop();
720
731
  stream.removeTrack(track);
721
732
  }
722
- stream.dispatchEvent(new CustomEvent("stopresumevideo", { detail: { track, enable: enabled } }));
733
+ return { changedTracks: findChangedTracks(stream, before) };
723
734
  }
724
735
  catch (error) {
725
736
  return rejectWithValue(error);
@@ -759,13 +770,17 @@ const doSetDevice = createAppAsyncThunk("localMedia/reactSetDevice", (_a, _b) =>
759
770
  const audioId = audio ? selectCurrentMicrophoneDeviceId(state) : false;
760
771
  const videoId = video ? selectCurrentCameraDeviceId(state) : false;
761
772
  const constraintsOptions = selectLocalMediaConstraintsOptions(state);
773
+ const before = snapshotTracks(stream);
762
774
  const { replacedTracks } = yield getStream(Object.assign(Object.assign({}, constraintsOptions), { audioId,
763
775
  videoId, type: "exact" }), { replaceStream: stream });
764
776
  const isAudioEnabled = selectIsMicrophoneEnabled(state);
765
777
  stream.getAudioTracks().forEach((track) => (track.enabled = isAudioEnabled));
766
778
  const isVideoEnabled = selectIsCameraEnabled(state);
767
779
  stream.getVideoTracks().forEach((track) => (track.enabled = isVideoEnabled));
768
- return { replacedTracks };
780
+ return {
781
+ replacedTracks,
782
+ changedTracks: findChangedTracks(stream, before),
783
+ };
769
784
  }
770
785
  catch (error) {
771
786
  return rejectWithValue(error);
@@ -839,6 +854,7 @@ const doSwitchLocalStream = createAppAsyncThunk("localMedia/doSwitchLocalStream"
839
854
  beforeEffectTracks.video = undefined;
840
855
  }
841
856
  const hasLiveTrackFromDevice = (deviceId) => (audioId ? replaceStream.getAudioTracks() : replaceStream.getVideoTracks()).some((track) => track.readyState === "live" && track.getSettings().deviceId === deviceId);
857
+ const before = snapshotTracks(replaceStream);
842
858
  try {
843
859
  const { replacedTracks } = yield getStream(Object.assign(Object.assign({}, constraintsOptions), { audioId: audioId === undefined ? false : audioId, videoId: videoId === undefined ? false : videoId, type: "exact" }), { replaceStream });
844
860
  const deviceId = audioId || videoId;
@@ -847,7 +863,11 @@ const doSwitchLocalStream = createAppAsyncThunk("localMedia/doSwitchLocalStream"
847
863
  deviceId,
848
864
  }));
849
865
  }
850
- return { replacedTracks, beforeEffectTracks };
866
+ return {
867
+ replacedTracks,
868
+ beforeEffectTracks,
869
+ changedTracks: findChangedTracks(replaceStream, before),
870
+ };
851
871
  }
852
872
  catch (error) {
853
873
  console.error(error);
@@ -916,6 +936,7 @@ const doLocalStreamEffect = createAppAsyncThunk("localMedia/doLocalStreamEffect"
916
936
  if (!stream) {
917
937
  throw new Error("No local media stream");
918
938
  }
939
+ const before = snapshotTracks(stream);
919
940
  if (effectStream) {
920
941
  if (!beforeTrack) {
921
942
  beforeEffectTracks = {
@@ -936,7 +957,12 @@ const doLocalStreamEffect = createAppAsyncThunk("localMedia/doLocalStreamEffect"
936
957
  };
937
958
  beforeTrack.stop();
938
959
  }
939
- return { effectStream, beforeEffectTracks, replacedTracks };
960
+ return {
961
+ effectStream,
962
+ beforeEffectTracks,
963
+ replacedTracks,
964
+ changedTracks: findChangedTracks(stream, before),
965
+ };
940
966
  }
941
967
  catch (error) {
942
968
  console.error("Error applying local stream effect", error);
@@ -2869,19 +2895,21 @@ const selectRtcIsCreatingDispatcher = (state) => state.rtcConnection.isCreatingD
2869
2895
  const selectRtcStatus = (state) => state.rtcConnection.status;
2870
2896
  const selectIsAcceptingStreams = (state) => state.rtcConnection.isAcceptingStreams;
2871
2897
  const selectIsAudioOnlyModeEnabled = (state) => state.rtcConnection.isAudioOnlyModeEnabled;
2898
+ const handOverChangedTracks = ({ payload }, { getState }) => {
2899
+ const { rtcManager } = selectRtcConnectionRaw(getState());
2900
+ payload === null || payload === void 0 ? void 0 : payload.changedTracks.forEach(({ track, oldTrack }) => {
2901
+ rtcManager === null || rtcManager === void 0 ? void 0 : rtcManager.replaceTrack(oldTrack, track);
2902
+ });
2903
+ };
2904
+ startAppListening({ actionCreator: doSetDevice.fulfilled, effect: handOverChangedTracks });
2905
+ startAppListening({ actionCreator: doSwitchLocalStream.fulfilled, effect: handOverChangedTracks });
2906
+ startAppListening({ actionCreator: doLocalStreamEffect.fulfilled, effect: handOverChangedTracks });
2872
2907
  startAppListening({
2873
- actionCreator: doSetDevice.fulfilled,
2874
- effect: ({ payload }, { getState }) => {
2875
- const { replacedTracks } = payload;
2908
+ actionCreator: doToggleCamera.fulfilled,
2909
+ effect: (action, { getState }) => {
2910
+ handOverChangedTracks(action, { getState });
2876
2911
  const { rtcManager } = selectRtcConnectionRaw(getState());
2877
- const stream = selectLocalMediaStream(getState());
2878
- const replace = (kind, oldTrack) => {
2879
- const track = stream === null || stream === void 0 ? void 0 : stream.getTracks().find((t) => t.kind === kind);
2880
- return track && (rtcManager === null || rtcManager === void 0 ? void 0 : rtcManager.replaceTrack(oldTrack, track));
2881
- };
2882
- replacedTracks === null || replacedTracks === void 0 ? void 0 : replacedTracks.forEach((t) => {
2883
- replace(t.kind, t);
2884
- });
2912
+ rtcManager === null || rtcManager === void 0 ? void 0 : rtcManager.stopOrResumeVideo({ enable: selectIsCameraEnabled(getState()) });
2885
2913
  },
2886
2914
  });
2887
2915
  startAppListening({
@@ -2915,23 +2943,6 @@ startAppListening({
2915
2943
  rtcManager === null || rtcManager === void 0 ? void 0 : rtcManager.removeScreenshareStream(stream);
2916
2944
  },
2917
2945
  });
2918
- startAppListening({
2919
- matcher: isAnyOf(doSwitchLocalStream.fulfilled, doLocalStreamEffect.fulfilled),
2920
- effect: ({ payload }, { getState }) => {
2921
- var _a;
2922
- const stream = selectLocalMediaStream(getState());
2923
- const { rtcManager } = selectRtcConnectionRaw(getState());
2924
- if (stream && rtcManager) {
2925
- const replace = (kind, oldTrack) => {
2926
- const track = stream.getTracks().find((t) => t.kind === kind);
2927
- return track && rtcManager.replaceTrack(oldTrack, track);
2928
- };
2929
- (_a = payload === null || payload === void 0 ? void 0 : payload.replacedTracks) === null || _a === void 0 ? void 0 : _a.forEach((t) => {
2930
- replace(t.kind, t);
2931
- });
2932
- }
2933
- },
2934
- });
2935
2946
  startAppListening({
2936
2947
  actionCreator: audioOnlyModeToggled,
2937
2948
  effect: (_, { getState }) => {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@whereby.com/core",
3
3
  "description": "Core library for whereby.com sdk",
4
4
  "author": "Whereby AS",
5
- "version": "1.31.5",
5
+ "version": "1.31.7",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
@@ -71,8 +71,8 @@
71
71
  },
72
72
  "dependencies": {
73
73
  "@reduxjs/toolkit": "^2.2.3",
74
- "@whereby.com/media": "11.4.0",
75
- "@whereby.com/audio-denoiser": "1.0.34",
74
+ "@whereby.com/media": "11.4.2",
75
+ "@whereby.com/audio-denoiser": "1.0.36",
76
76
  "@whereby.com/camera-effects": "1.1.4",
77
77
  "axios": "^1.21.1",
78
78
  "btoa": "^1.2.1",