Skip to content

Commit

Permalink
Merge pull request #173 from whereby/thomas/PAN-670-camera-light-not-…
Browse files Browse the repository at this point in the history
…turning-off

Fix camera light not turning off when turning off camera
  • Loading branch information
thyal authored Jan 5, 2024
2 parents c593d75 + 19f730b commit 111cb3b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
28 changes: 14 additions & 14 deletions src/lib/core/redux/slices/localMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,23 @@ export const localMediaSlice = createSlice({
options: action.payload.localMediaOptions,
};
})
.addCase(reactSetDevice.pending, (state, action) => {
.addCase(doSetDevice.pending, (state, action) => {
const { audio, video } = action.meta.arg;
return {
...state,
isSettingCameraDevice: video,
isSettingMicrophoneDevice: audio,
};
})
.addCase(reactSetDevice.fulfilled, (state, action) => {
.addCase(doSetDevice.fulfilled, (state, action) => {
const { audio, video } = action.meta.arg;
return {
...state,
isSettingCameraDevice: video ? false : state.isSettingCameraDevice,
isSettingMicrophoneDevice: audio ? false : state.isSettingMicrophoneDevice,
};
})
.addCase(reactSetDevice.rejected, (state, action) => {
.addCase(doSetDevice.rejected, (state, action) => {
const { audio, video } = action.meta.arg;
return {
...state,
Expand All @@ -115,13 +115,13 @@ export const localMediaSlice = createSlice({
microphoneDeviceError: audio ? action.error : state.microphoneDeviceError,
};
})
.addCase(reactToggleCamera.pending, (state) => {
.addCase(doToggleCamera.pending, (state) => {
return {
...state,
isTogglingCamera: true,
};
})
.addCase(reactToggleCamera.fulfilled, (state) => {
.addCase(doToggleCamera.fulfilled, (state) => {
return {
...state,
isTogglingCamera: false,
Expand Down Expand Up @@ -205,7 +205,7 @@ export const {
stopScreenshare,
} = localMediaSlice.actions;

const reactToggleCamera = createAppAsyncThunk("localMedia/doToggleCamera", async (_, { getState, rejectWithValue }) => {
const doToggleCamera = createAppAsyncThunk("localMedia/doToggleCamera", async (_, { getState, rejectWithValue }) => {
const state = getState();
const stream = selectLocalMediaStream(state);
if (!stream) {
Expand All @@ -214,8 +214,6 @@ const reactToggleCamera = createAppAsyncThunk("localMedia/doToggleCamera", async
let track = stream.getVideoTracks()[0];
const enabled = selectIsCameraEnabled(state);

// this.dispatchEvent(new LocalMediaEvent("camera_enabled", { detail: { enabled: this._cameraEnabled } }));

// Only stop tracks if we fully own the media stream
const shouldStopTrack = selectLocalMediaOwnsStream(state);

Expand Down Expand Up @@ -260,7 +258,7 @@ const reactToggleCamera = createAppAsyncThunk("localMedia/doToggleCamera", async
}
});

const reactToggleMicrophone = createAppAsyncThunk("localMedia/doToggleMicrophone", (_, { getState }) => {
const doToggleMicrophone = createAppAsyncThunk("localMedia/doToggleMicrophone", (_, { getState }) => {
const state = getState();
const stream = selectLocalMediaStream(state);
if (!stream) {
Expand All @@ -275,7 +273,7 @@ const reactToggleMicrophone = createAppAsyncThunk("localMedia/doToggleMicrophone
audioTrack.enabled = enabled;
});

export const reactSetDevice = createAppAsyncThunk(
export const doSetDevice = createAppAsyncThunk(
"localMedia/reactSetDevice",
async ({ audio, video }: { audio: boolean; video: boolean }, { getState, rejectWithValue }) => {
try {
Expand Down Expand Up @@ -324,6 +322,8 @@ export const doStartLocalMedia = createAppAsyncThunk(

if (!(payload.audio || payload.video)) {
return { stream: new MediaStream() };
} else {
dispatch(doSetLocalMediaOptions({ options: payload }));
}

try {
Expand Down Expand Up @@ -496,7 +496,7 @@ startAppListening({
return isReady && oldValue !== newValue;
},
effect: (_, { dispatch }) => {
dispatch(reactToggleMicrophone());
dispatch(doToggleMicrophone());
},
});

Expand All @@ -512,7 +512,7 @@ startAppListening({
return isReady && oldValue !== newValue;
},
effect: (_action, { dispatch }) => {
dispatch(reactToggleCamera());
dispatch(doToggleCamera());
},
});

Expand All @@ -524,7 +524,7 @@ startAppListening({
return isReady && oldValue !== newValue;
},
effect: (_action, { dispatch }) => {
dispatch(reactSetDevice({ audio: false, video: true }));
dispatch(doSetDevice({ audio: false, video: true }));
},
});

Expand All @@ -536,6 +536,6 @@ startAppListening({
return isReady && oldValue !== newValue;
},
effect: (_action, { dispatch }) => {
dispatch(reactSetDevice({ audio: true, video: false }));
dispatch(doSetDevice({ audio: true, video: false }));
},
});
4 changes: 2 additions & 2 deletions src/lib/core/redux/slices/rtcConnection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
selectIsMicrophoneEnabled,
selectLocalMediaStream,
selectLocalMediaStatus,
reactSetDevice,
doSetDevice,
doStartScreenshare,
stopScreenshare,
} from "../localMedia";
Expand Down Expand Up @@ -338,7 +338,7 @@ startAppListening({
});

startAppListening({
actionCreator: reactSetDevice.fulfilled,
actionCreator: doSetDevice.fulfilled,
effect: ({ payload }, { getState }) => {
const { replacedTracks } = payload;
const { rtcManager } = selectRtcConnectionRaw(getState());
Expand Down
1 change: 1 addition & 0 deletions src/lib/core/redux/tests/store/localMedia.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ describe("actions", () => {
status: "started",
stream: newStream,
devices: expect.any(Object),
options: { audio: true, video: true },
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/stories/custom-ui.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const RoomConnectionWithLocalMedia = ({ roomUrl, displayName }: { roomUrl
};

export const LocalMediaOnly = () => {
const localMedia = useLocalMedia();
const localMedia = useLocalMedia({ audio: true, video: true });

return (
<div>
Expand Down

0 comments on commit 111cb3b

Please sign in to comment.