Skip to content

Commit e54cab7

Browse files
committed
core: release camera and microphone when the local client is kicked
1 parent 2f7286e commit e54cab7

4 files changed

Lines changed: 54 additions & 0 deletions

File tree

.changeset/fast-drinks-end.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@whereby.com/core": patch
3+
---
4+
5+
core: release camera and microphone when the local client is kicked, eg when the meeting is ended by the host

packages/core/src/redux/slices/roomConnection/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,13 @@ startAppListening({
304304
},
305305
});
306306

307+
startAppListening({
308+
actionCreator: signalEvents.clientKicked,
309+
effect: (_, { dispatch }) => {
310+
dispatch(doAppStop());
311+
},
312+
});
313+
307314
startAppListening({
308315
actionCreator: doAppStop,
309316
effect: (_, { dispatch, getState }) => {

packages/core/src/redux/tests/store/localMedia.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import * as localMediaSlice from "../../slices/localMedia";
2+
import { initialState as appInitialState } from "../../slices/app";
3+
import { signalEvents } from "../../slices/signalConnection/actions";
24
import { createStore } from "../store.setup";
35
import { diff } from "deep-object-diff";
46
import * as MediaDevices from "@whereby.com/media";
@@ -158,6 +160,27 @@ describe("actions", () => {
158160
stream: undefined,
159161
});
160162
});
163+
164+
it("should stop all tracks when the local client is kicked", () => {
165+
const store = createStore({
166+
withSignalConnection: true,
167+
connectToRoom: true,
168+
initialState: {
169+
...initialState,
170+
localMedia: {
171+
...initialState.localMedia!,
172+
options: { audio: true, video: true },
173+
},
174+
app: { ...appInitialState, isActive: true },
175+
},
176+
});
177+
178+
store.dispatch(signalEvents.clientKicked({ clientId: "self-client-id" }));
179+
180+
expect(audioTrack.stop).toHaveBeenCalled();
181+
expect(videoTrack.stop).toHaveBeenCalled();
182+
expect(store.getState().localMedia.status).toEqual("stopped");
183+
});
161184
});
162185
});
163186

packages/core/src/redux/tests/store/roomConnection.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { createStore, mockSignalEmit } from "../store.setup";
22
import { doKnockRoom, doConnectRoom } from "../../slices/roomConnection";
3+
import { initialState as appInitialState } from "../../slices/app";
4+
import { signalEvents } from "../../slices/signalConnection/actions";
35
import { diff } from "deep-object-diff";
46

57
describe("actions", () => {
@@ -30,6 +32,23 @@ describe("actions", () => {
3032
});
3133
});
3234

35+
describe("signalEvents.clientKicked", () => {
36+
it("should stop the app so local media and connections are cleaned up", () => {
37+
const store = createStore({
38+
withSignalConnection: true,
39+
connectToRoom: true,
40+
initialState: {
41+
app: { ...appInitialState, isActive: true },
42+
},
43+
});
44+
45+
store.dispatch(signalEvents.clientKicked({ clientId: "self-client-id" }));
46+
47+
expect(store.getState().roomConnection.status).toEqual("kicked");
48+
expect(store.getState().app.isActive).toEqual(false);
49+
});
50+
});
51+
3352
it("doConnectRoom", async () => {
3453
const store = createStore({ withSignalConnection: true });
3554

0 commit comments

Comments
 (0)