From 8266f4e94329f53c2a53390d37bb08f8b19f9ae6 Mon Sep 17 00:00:00 2001 From: Thomas Frivold Date: Tue, 10 Dec 2024 11:51:32 +0100 Subject: [PATCH] core: Do not send client metadata before connecting to room --- .changeset/nervous-shrimps-deny.md | 5 +++ packages/core/src/redux/index.ts | 1 + .../src/redux/slices/connectionMonitor.ts | 2 +- .../core/src/redux/slices/localParticipant.ts | 15 ++++--- .../src/redux/slices/notifications/index.ts | 2 +- .../index.ts} | 45 ++++++++++--------- .../redux/slices/roomConnection/selectors.ts | 10 +++++ .../core/src/redux/slices/rtcAnalytics.ts | 2 +- 8 files changed, 54 insertions(+), 28 deletions(-) create mode 100644 .changeset/nervous-shrimps-deny.md rename packages/core/src/redux/slices/{roomConnection.ts => roomConnection/index.ts} (88%) create mode 100644 packages/core/src/redux/slices/roomConnection/selectors.ts diff --git a/.changeset/nervous-shrimps-deny.md b/.changeset/nervous-shrimps-deny.md new file mode 100644 index 000000000..f8b041d61 --- /dev/null +++ b/.changeset/nervous-shrimps-deny.md @@ -0,0 +1,5 @@ +--- +"@whereby.com/core": minor +--- + +Do not send client metadata before connecting to room diff --git a/packages/core/src/redux/index.ts b/packages/core/src/redux/index.ts index a73c4603b..f3cda6216 100644 --- a/packages/core/src/redux/index.ts +++ b/packages/core/src/redux/index.ts @@ -17,6 +17,7 @@ export * from "./slices/organization"; export * from "./slices/remoteParticipants"; export * from "./slices/room"; export * from "./slices/roomConnection"; +export * from "./slices/roomConnection/selectors"; export * from "./slices/rtcAnalytics"; export * from "./slices/spotlights"; export * from "./slices/streaming"; diff --git a/packages/core/src/redux/slices/connectionMonitor.ts b/packages/core/src/redux/slices/connectionMonitor.ts index c0ba3849f..cbeadc7e4 100644 --- a/packages/core/src/redux/slices/connectionMonitor.ts +++ b/packages/core/src/redux/slices/connectionMonitor.ts @@ -3,7 +3,7 @@ import { setClientProvider, subscribeIssues } from "@whereby.com/media"; import { RootState } from "../store"; import { createAppThunk } from "../thunk"; import { createReactor } from "../listenerMiddleware"; -import { selectRoomConnectionStatus } from "./roomConnection"; +import { selectRoomConnectionStatus } from "./roomConnection/selectors"; import { selectRtcManager } from "./rtcConnection"; import { selectAllClientViews } from "./room"; diff --git a/packages/core/src/redux/slices/localParticipant.ts b/packages/core/src/redux/slices/localParticipant.ts index 3f98ec317..5dc948f7a 100644 --- a/packages/core/src/redux/slices/localParticipant.ts +++ b/packages/core/src/redux/slices/localParticipant.ts @@ -6,10 +6,11 @@ import { LocalParticipant } from "../../RoomParticipant"; import { selectSignalConnectionRaw } from "./signalConnection"; import { doAppStart } from "./app"; import { selectLocalMediaStream, toggleCameraEnabled, toggleMicrophoneEnabled } from "./localMedia"; -import { createReactor, startAppListening } from "../listenerMiddleware"; +import { startAppListening } from "../listenerMiddleware"; import { signalEvents } from "./signalConnection/actions"; import { ClientView } from "../types"; import { NON_PERSON_ROLES } from "../constants"; +import { selectRoomConnectionStatus } from "./roomConnection/selectors"; export interface LocalParticipantState extends LocalParticipant { isScreenSharing: boolean; @@ -217,7 +218,11 @@ startAppListening({ effect: ({ payload }, { dispatch, getState }) => { const { enabled } = payload; const { isVideoEnabled } = selectLocalParticipantRaw(getState()); + const roomConnectionStatus = selectRoomConnectionStatus(getState()); + if (roomConnectionStatus !== "connected") { + return; + } dispatch(doEnableVideo({ enabled: enabled || !isVideoEnabled })); }, }); @@ -227,11 +232,11 @@ startAppListening({ effect: ({ payload }, { dispatch, getState }) => { const { enabled } = payload; const { isAudioEnabled } = selectLocalParticipantRaw(getState()); + const roomConnectionStatus = selectRoomConnectionStatus(getState()); + if (roomConnectionStatus !== "connected") { + return; + } dispatch(doEnableAudio({ enabled: enabled || !isAudioEnabled })); }, }); - -createReactor([selectLocalParticipantDisplayName, selectLocalParticipantStickyReaction], ({ dispatch }) => { - dispatch(doSendClientMetadata()); -}); diff --git a/packages/core/src/redux/slices/notifications/index.ts b/packages/core/src/redux/slices/notifications/index.ts index a84626ed3..8fa51698a 100644 --- a/packages/core/src/redux/slices/notifications/index.ts +++ b/packages/core/src/redux/slices/notifications/index.ts @@ -7,7 +7,7 @@ import { createReactor, startAppListening } from "../../listenerMiddleware"; import { signalEvents } from "../signalConnection/actions"; import { selectRemoteParticipants } from "../remoteParticipants"; import { selectSignalStatus } from "../signalConnection"; -import { selectRoomConnectionStatus } from "../roomConnection"; +import { selectRoomConnectionStatus } from "../roomConnection/selectors"; import { selectIsAuthorizedToAskToSpeak } from "../authorization"; import { Notification, diff --git a/packages/core/src/redux/slices/roomConnection.ts b/packages/core/src/redux/slices/roomConnection/index.ts similarity index 88% rename from packages/core/src/redux/slices/roomConnection.ts rename to packages/core/src/redux/slices/roomConnection/index.ts index 783835785..ad19d61d2 100644 --- a/packages/core/src/redux/slices/roomConnection.ts +++ b/packages/core/src/redux/slices/roomConnection/index.ts @@ -1,8 +1,8 @@ import { PayloadAction, createSelector, createSlice } from "@reduxjs/toolkit"; -import { createReactor, startAppListening } from "../listenerMiddleware"; -import { RootState } from "../store"; -import { createAppThunk } from "../thunk"; +import { createReactor, startAppListening } from "../../listenerMiddleware"; +import { selectRoomConnectionError, selectRoomConnectionStatus } from "./selectors"; +import { createAppThunk } from "../../thunk"; import { doAppStop, selectAppDisplayName, @@ -11,19 +11,25 @@ import { selectAppExternalId, selectAppIsActive, selectAppIsDialIn, -} from "./app"; -import { selectRoomKey, setRoomKey } from "./authorization"; +} from "../app"; +import { selectRoomKey, setRoomKey } from "../authorization"; -import { selectOrganizationId } from "./organization"; -import { signalEvents } from "./signalConnection/actions"; +import { selectOrganizationId } from "../organization"; +import { signalEvents } from "../signalConnection/actions"; import { doSignalDisconnect, selectSignalConnectionDeviceIdentified, selectSignalConnectionRaw, socketReconnecting, -} from "./signalConnection"; -import { selectIsCameraEnabled, selectIsMicrophoneEnabled, selectLocalMediaStatus } from "./localMedia"; -import { selectSelfId, selectLocalParticipantClientClaim } from "./localParticipant"; +} from "../signalConnection"; +import { selectIsCameraEnabled, selectIsMicrophoneEnabled, selectLocalMediaStatus } from "../localMedia"; +import { + selectSelfId, + selectLocalParticipantClientClaim, + selectLocalParticipantDisplayName, + selectLocalParticipantStickyReaction, + doSendClientMetadata, +} from "../localParticipant"; export type ConnectionStatus = | "ready" @@ -219,16 +225,6 @@ export const doConnectRoom = createAppThunk(() => (dispatch, getState) => { dispatch(connectionStatusChanged("connecting")); }); -/** - * Selectors - */ - -export const selectRoomConnectionRaw = (state: RootState) => state.roomConnection; -export const selectRoomConnectionSession = (state: RootState) => state.roomConnection.session; -export const selectRoomConnectionSessionId = (state: RootState) => state.roomConnection.session?.id; -export const selectRoomConnectionStatus = (state: RootState) => state.roomConnection.status; -export const selectRoomConnectionError = (state: RootState) => state.roomConnection.error; - /** * Reactors */ @@ -309,3 +305,12 @@ startAppListening({ } }, }); + +createReactor( + [selectLocalParticipantDisplayName, selectLocalParticipantStickyReaction, selectRoomConnectionStatus], + ({ dispatch }, diplayName, stickyReaction, roomConnectionStatus) => { + if (roomConnectionStatus === "connected") { + dispatch(doSendClientMetadata()); + } + }, +); diff --git a/packages/core/src/redux/slices/roomConnection/selectors.ts b/packages/core/src/redux/slices/roomConnection/selectors.ts new file mode 100644 index 000000000..bc964449f --- /dev/null +++ b/packages/core/src/redux/slices/roomConnection/selectors.ts @@ -0,0 +1,10 @@ +import { RootState } from "../../store"; +/** + * Selectors + */ + +export const selectRoomConnectionRaw = (state: RootState) => state.roomConnection; +export const selectRoomConnectionSession = (state: RootState) => state.roomConnection.session; +export const selectRoomConnectionSessionId = (state: RootState) => state.roomConnection.session?.id; +export const selectRoomConnectionStatus = (state: RootState) => state.roomConnection.status; +export const selectRoomConnectionError = (state: RootState) => state.roomConnection.error; diff --git a/packages/core/src/redux/slices/rtcAnalytics.ts b/packages/core/src/redux/slices/rtcAnalytics.ts index c52dd6627..ac9b2f005 100644 --- a/packages/core/src/redux/slices/rtcAnalytics.ts +++ b/packages/core/src/redux/slices/rtcAnalytics.ts @@ -12,7 +12,7 @@ import { selectSignalStatus } from "./signalConnection"; import { selectDeviceId } from "./deviceCredentials"; import { doSetDevice, selectIsCameraEnabled, selectIsMicrophoneEnabled, selectLocalMediaStream } from "./localMedia"; import { doStartScreenshare, selectLocalScreenshareStream, stopScreenshare } from "./localScreenshare"; -import { selectRoomConnectionSessionId } from "./roomConnection"; +import { selectRoomConnectionSessionId } from "./roomConnection/selectors"; import { signalEvents } from "./signalConnection/actions"; type RtcAnalyticsCustomEvent = {