Skip to content

Commit

Permalink
Merge pull request #397 from whereby/kevinhanna/close-rtc-stats-on-ap…
Browse files Browse the repository at this point in the history
…p-stop

core: Close rtcstats connection when App is stopped
  • Loading branch information
kevinwhereby authored Sep 9, 2024
2 parents 6ddde54 + 58b9d4a commit ac2331b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/dull-ants-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@whereby.com/core": minor
"@whereby.com/media": patch
---

Close RtcStats connection when App is stopped
11 changes: 10 additions & 1 deletion packages/core/src/redux/slices/rtcConnection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { selectSignalConnectionRaw, selectSignalConnectionSocket, socketReconnec
import { createReactor, startAppListening } from "../../listenerMiddleware";
import { selectRemoteClients, streamStatusUpdated } from "../remoteParticipants";
import { StreamState } from "../../../RoomParticipant";
import { selectAppIsNodeSdk, selectAppIsActive } from "../app";
import { selectAppIsNodeSdk, selectAppIsActive, doAppStop } from "../app";
import { Chrome111 as MediasoupDeviceHandler } from "mediasoup-client/lib/handlers/Chrome111.js";
import {
selectIsCameraEnabled,
Expand Down Expand Up @@ -342,6 +342,15 @@ startAppListening({
},
});

startAppListening({
actionCreator: doAppStop,
effect: (_, { getState }) => {
const rtcManager = selectRtcManager(getState());

rtcManager?.rtcStatsDisconnect();
},
});

startAppListening({
actionCreator: stopScreenshare,
effect: ({ payload }, { getState }) => {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/redux/tests/store.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const mockRtcManager = {
removeStream: jest.fn(),
disconnect: jest.fn(),
disconnectAll: jest.fn(),
rtcStatsDisconnect: jest.fn(),
updateStreamResolution: jest.fn(),
sendStatsCustomEvent: jest.fn(),
};
Expand Down
17 changes: 17 additions & 0 deletions packages/core/src/redux/tests/store/rtcConnection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import {
doDisconnectRtc,
doRtcReportStreamResolution,
doRtcManagerInitialize,
selectRtcManager,
} from "../../slices/rtcConnection";
import { randomRemoteParticipant, randomString } from "../../../__mocks__/appMocks";
import MockMediaStream from "../../../__mocks__/MediaStream";
import { RtcManagerDispatcher } from "@whereby.com/media";
import { initialLocalMediaState } from "../../slices/localMedia";
import { diff } from "deep-object-diff";
import { coreVersion } from "../../../version";
import { doAppStop } from "../../slices/app";

jest.mock("@whereby.com/media");

Expand Down Expand Up @@ -163,3 +165,18 @@ describe("actions", () => {
expect(store.getState().rtcConnection.rtcManagerInitialized).toBe(true);
});
});

describe("middleware", () => {
describe("doAppStop", () => {
it("closes the rtcstats connection", () => {
const store = createStore({
withRtcManager: true,
});
const rtcManager = selectRtcManager(store.getState());

store.dispatch(doAppStop());

expect(rtcManager?.rtcStatsDisconnect).toHaveBeenCalled();
});
});
});
5 changes: 3 additions & 2 deletions packages/media/src/webrtc/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ export interface RtcManager {
clientId,
shouldAddLocalVideo,
streamId,
enforceTurnProtocol
enforceTurnProtocol,
}: {
activeBreakout: boolean;
clientId: string;
shouldAddLocalVideo: boolean;
streamId: string;
enforceTurnProtocol?: TurnTransportProtocol
enforceTurnProtocol?: TurnTransportProtocol;
}) => void;
addNewStream(streamId: string, stream: MediaStream, isAudioEnabled: boolean, isVideoEnabled: boolean): void;
disconnect(streamId: string, activeBreakout: boolean | null, eventClaim?: string): void;
disconnectAll(): void;
rtcStatsDisconnect(): void;
replaceTrack(oldTrack: CustomMediaStreamTrack, newTrack: CustomMediaStreamTrack): void;
removeStream(streamId: string, _stream: MediaStream, requestedByClientId: string | null): void;
shouldAcceptStreamsFromBothSides?: () => boolean;
Expand Down

0 comments on commit ac2331b

Please sign in to comment.