Skip to content

Commit 821908f

Browse files
authored
Merge pull request #171 from whereby/kevinhanna/test-node-core-export
Add Core SDK export for Node client
2 parents 3a3eeb5 + d6af9a5 commit 821908f

File tree

12 files changed

+143
-36
lines changed

12 files changed

+143
-36
lines changed

package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@whereby.com/browser-sdk",
3-
"version": "2.1.0-beta2",
3+
"version": "2.1.0-beta3",
44
"description": "Modules for integration Whereby video in web apps",
55
"author": "Whereby AS",
66
"license": "MIT",
@@ -11,6 +11,10 @@
1111
"browserslist": "> 0.5%, last 2 versions, not dead",
1212
"source": "src/index.js",
1313
"exports": {
14+
"./core": {
15+
"import": "./dist/core/index.js",
16+
"types": "./dist/core/index.d.ts"
17+
},
1418
"./react": {
1519
"import": "./dist/react/index.esm.js",
1620
"types": "./dist/react/index.d.ts"
@@ -26,6 +30,9 @@
2630
},
2731
"typesVersions": {
2832
"*": {
33+
"core": [
34+
"dist/core/index.d.ts"
35+
],
2936
"react": [
3037
"dist/react/index.d.ts"
3138
],
@@ -109,7 +116,7 @@
109116
"dependencies": {
110117
"@reduxjs/toolkit": "^2.0.1",
111118
"@swc/helpers": "^0.3.13",
112-
"@whereby/jslib-media": "whereby/jslib-media.git#1.4.1",
119+
"@whereby/jslib-media": "whereby/jslib-media.git#1.7.2",
113120
"axios": "^1.2.3",
114121
"btoa": "^1.2.1",
115122
"events": "^3.3.0",

rollup.config.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const dotenv = require("dotenv");
2+
dotenv.config();
13
const nodeResolve = require("@rollup/plugin-node-resolve");
24
const commonjs = require("@rollup/plugin-commonjs");
35
const json = require("@rollup/plugin-json");
@@ -65,6 +67,24 @@ const plugins = [
6567
];
6668

6769
module.exports = [
70+
{
71+
input: "src/lib/core/index.ts",
72+
output: {
73+
exports: "named",
74+
file: "dist/core/index.js",
75+
format: "cjs",
76+
},
77+
plugins: [
78+
nodeResolve({
79+
browser: false,
80+
preferBuiltins: true,
81+
}),
82+
commonjs(),
83+
json(),
84+
replace(replaceValues),
85+
typescript(),
86+
],
87+
},
6888
// Esm build of lib, to be used with bundlers
6989
{
7090
input: "src/lib/react/index.ts",
@@ -96,7 +116,6 @@ module.exports = [
96116
external: ["heresy", ...peerDependencies],
97117
plugins,
98118
},
99-
100119
// CDN builds
101120
{
102121
input: "src/lib/embed/index.ts",
@@ -136,6 +155,12 @@ module.exports = [
136155
},
137156

138157
// Type definitions
158+
{
159+
input: "src/lib/core/index.ts",
160+
output: [{ file: "dist/core/index.d.ts", format: "es" }],
161+
external: ["@whereby/jslib-media/src/webrtc/RtcManager"],
162+
plugins: [dts()],
163+
},
139164
{
140165
input: "src/lib/react/index.ts",
141166
output: [{ file: "dist/react/index.d.ts", format: "es" }],

src/lib/core/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export * from "./redux/thunk";
2+
export * from "./redux/store";
3+
export * from "./redux/listenerMiddleware";
4+
export * from "../services";
5+
export * from "./redux/slices/roomConnection";
6+
export * from "./redux/slices/app";
7+
export * from "./redux/slices/remoteParticipants";
8+
export * from "./redux/slices/rtcConnection";
9+
export * from "./redux/slices/signalConnection";
10+
export * from "../version";

src/lib/core/redux/slices/__tests__/app.unit.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ describe("appSlice", () => {
2222
displayName: "displayName",
2323
sdkVersion: "sdkVersion",
2424
externalId: "externalId",
25+
isNodeSdk: true,
2526
});
2627
});
2728

src/lib/core/redux/slices/__tests__/localMedia.unit.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@ describe("localMediaSlice", () => {
44
describe("reactors", () => {
55
describe("reactLocalMediaStart", () => {
66
it.each`
7-
appWantsToJoin | localMediaStatus | localMediaOptions | expected
8-
${false} | ${""} | ${undefined} | ${undefined}
9-
${false} | ${"started"} | ${undefined} | ${undefined}
10-
${false} | ${"started"} | ${{ audio: true, video: true }} | ${undefined}
11-
${true} | ${"started"} | ${{ audio: true, video: true }} | ${undefined}
12-
${true} | ${""} | ${undefined} | ${undefined}
13-
${true} | ${""} | ${{ audio: true, video: true }} | ${{ audio: true, video: true }}
7+
appWantsToJoin | localMediaStatus | localMediaOptions | isNodeSdk | expected
8+
${false} | ${""} | ${undefined} | ${false} | ${undefined}
9+
${false} | ${"started"} | ${undefined} | ${false} | ${undefined}
10+
${false} | ${"started"} | ${{ audio: true, video: true }} | ${false} | ${undefined}
11+
${true} | ${"started"} | ${{ audio: true, video: true }} | ${false} | ${undefined}
12+
${true} | ${""} | ${undefined} | ${false} | ${undefined}
13+
${true} | ${""} | ${{ audio: true, video: true }} | ${true} | ${undefined}
14+
${true} | ${""} | ${{ audio: true, video: true }} | ${false} | ${{ audio: true, video: true }}
1415
`(
15-
"expected $expected when appWantsToJoin=$appWantsToJoin, localMediaStatus=$localMediaStatus, localMediaOptions=$localMediaOptions",
16-
({ appWantsToJoin, localMediaStatus, localMediaOptions, expected }) => {
16+
"expected $expected when appWantsToJoin=$appWantsToJoin, localMediaStatus=$localMediaStatus, localMediaOptions=$localMediaOptions, isNodeSdk=$isNodeSdk",
17+
({ appWantsToJoin, localMediaStatus, localMediaOptions, isNodeSdk, expected }) => {
1718
expect(
1819
selectLocalMediaShouldStartWithOptions.resultFunc(
1920
appWantsToJoin,
2021
localMediaStatus,
21-
localMediaOptions
22+
localMediaOptions,
23+
isNodeSdk
2224
)
2325
).toEqual(expected);
2426
}

src/lib/core/redux/slices/__tests__/roomConnection.unit.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,23 @@ describe("roomConnectionSlice", () => {
4646
const x = () => oneOf(true, false);
4747

4848
it.each`
49-
organizationId | roomConnectionStatus | signalIdentified | localMediaStatus | expected
50-
${undefined} | ${"initializing"} | ${x()} | ${"started"} | ${false}
51-
${"orgId"} | ${"initializing"} | ${true} | ${"started"} | ${true}
52-
${"orgId"} | ${"connected"} | ${x()} | ${"started"} | ${false}
53-
${"orgId"} | ${"initializing"} | ${false} | ${"starting"} | ${false}
54-
${"orgId"} | ${"initializing"} | ${x()} | ${"error"} | ${false}
49+
organizationId | roomConnectionStatus | signalIdentified | localMediaStatus | isNodeSdk | expected
50+
${undefined} | ${"initializing"} | ${x()} | ${"started"} | ${x()} | ${false}
51+
${"orgId"} | ${"initializing"} | ${true} | ${"started"} | ${false} | ${true}
52+
${"orgId"} | ${"connected"} | ${x()} | ${"started"} | ${x()} | ${false}
53+
${"orgId"} | ${"initializing"} | ${false} | ${"starting"} | ${x()} | ${false}
54+
${"orgId"} | ${"initializing"} | ${x()} | ${"error"} | ${false} | ${false}
55+
${"orgId"} | ${"initializing"} | ${true} | ${"error"} | ${true} | ${true}
5556
`(
56-
"should return $expected when hasOrganizationIdFetched=$hasOrganizationIdFetched, roomConnectionStatus=$roomConnectionStatus, signalIdentified=$signalIdentified, localMediaStatus=$localMediaStatus",
57-
({ organizationId, roomConnectionStatus, signalIdentified, localMediaStatus, expected }) => {
57+
"Should return $expected when organizationId=$organizationId, roomConnectionStatus=$roomConnectionStatus, signalIdentified=$signalIdentified, localMediaStatus=$localMediaStatus, isNodeSdk=$isNodeSdk",
58+
({ organizationId, roomConnectionStatus, signalIdentified, localMediaStatus, isNodeSdk, expected }) => {
5859
expect(
5960
selectShouldConnectRoom.resultFunc(
6061
organizationId,
6162
roomConnectionStatus,
6263
signalIdentified,
63-
localMediaStatus
64+
localMediaStatus,
65+
isNodeSdk
6466
)
6567
).toEqual(expected);
6668
}

src/lib/core/redux/slices/app.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface AppState {
1313
displayName: string | null;
1414
sdkVersion: string | null;
1515
externalId: string | null;
16+
isNodeSdk: boolean;
1617
}
1718

1819
const initialState: AppState = {
@@ -23,6 +24,7 @@ const initialState: AppState = {
2324
displayName: null,
2425
sdkVersion: null,
2526
externalId: null,
27+
isNodeSdk: typeof process !== "undefined" && process.release.name === "node",
2628
};
2729

2830
export const appSlice = createSlice({
@@ -77,3 +79,4 @@ export const selectAppRoomKey = (state: RootState) => state.app.roomKey;
7779
export const selectAppDisplayName = (state: RootState) => state.app.displayName;
7880
export const selectAppSdkVersion = (state: RootState) => state.app.sdkVersion;
7981
export const selectAppExternalId = (state: RootState) => state.app.externalId;
82+
export const selectAppIsNodeSdk = (state: RootState) => state.app.isNodeSdk;

src/lib/core/redux/slices/localMedia.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { getStream, getUpdatedDevices, getDeviceData } from "@whereby/jslib-medi
33
import { createAppAsyncThunk, createAppThunk } from "../../redux/thunk";
44
import { RootState } from "../../redux/store";
55
import { createReactor, startAppListening } from "../../redux/listenerMiddleware";
6-
import { doAppJoin, selectAppWantsToJoin } from "./app";
6+
import { doAppJoin, selectAppIsNodeSdk, selectAppWantsToJoin } from "./app";
77
import debounce from "../../../utils/debounce";
88

99
export type LocalMediaOptions = {
10+
disabled?: boolean;
1011
audio: boolean;
1112
video: boolean;
1213
};
@@ -606,7 +607,11 @@ export const selectLocalMediaShouldStartWithOptions = createSelector(
606607
selectAppWantsToJoin,
607608
selectLocalMediaStatus,
608609
selectLocalMediaOptions,
609-
(appWantsToJoin, localMediaStatus, localMediaOptions) => {
610+
selectAppIsNodeSdk,
611+
(appWantsToJoin, localMediaStatus, localMediaOptions, isNodeSdk) => {
612+
if (isNodeSdk) {
613+
return;
614+
}
610615
if (appWantsToJoin && localMediaStatus === "" && localMediaOptions) {
611616
return localMediaOptions;
612617
}

src/lib/core/redux/slices/roomConnection.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
selectAppSdkVersion,
1111
selectAppExternalId,
1212
setRoomKey,
13+
selectAppIsNodeSdk,
1314
} from "./app";
1415

1516
import { selectOrganizationId } from "./organization";
@@ -189,10 +190,16 @@ export const selectRoomConnectionStatus = (state: RootState) => state.roomConnec
189190
*/
190191

191192
export const selectShouldConnectRoom = createSelector(
192-
[selectOrganizationId, selectRoomConnectionStatus, selectSignalConnectionDeviceIdentified, selectLocalMediaStatus],
193-
(hasOrganizationIdFetched, roomConnectionStatus, signalConnectionDeviceIdentified, localMediaStatus) => {
193+
[
194+
selectOrganizationId,
195+
selectRoomConnectionStatus,
196+
selectSignalConnectionDeviceIdentified,
197+
selectLocalMediaStatus,
198+
selectAppIsNodeSdk,
199+
],
200+
(hasOrganizationIdFetched, roomConnectionStatus, signalConnectionDeviceIdentified, localMediaStatus, isNodeSdk) => {
194201
if (
195-
localMediaStatus === "started" &&
202+
(localMediaStatus === "started" || isNodeSdk) && // the node SDK doesn't use LocalMedia, so we can join without
196203
signalConnectionDeviceIdentified &&
197204
!!hasOrganizationIdFetched &&
198205
["initializing", "reconnect"].includes(roomConnectionStatus)

src/lib/core/redux/slices/rtcConnection/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import RtcManagerDispatcher, {
1111
import { createReactor, startAppListening } from "../../listenerMiddleware";
1212
import { selectRemoteParticipants, streamStatusUpdated } from "../remoteParticipants";
1313
import { StreamState } from "../../../../../lib/RoomParticipant";
14-
import { selectAppWantsToJoin } from "../app";
14+
import { selectAppIsNodeSdk, selectAppWantsToJoin } from "../app";
1515
import {
1616
selectIsCameraEnabled,
1717
selectIsMicrophoneEnabled,
@@ -23,6 +23,7 @@ import { rtcEvents } from "./actions";
2323
import { StreamStatusUpdate } from "./types";
2424
import { signalEvents } from "../signalConnection/actions";
2525
import { doStartScreenshare, stopScreenshare } from "../localScreenshare";
26+
import { Chrome111 as MediasoupDeviceHandler } from "mediasoup-client/lib/handlers/Chrome111";
2627

2728
export const createWebRtcEmitter = (dispatch: AppDispatch) => {
2829
return {
@@ -165,6 +166,7 @@ export const doConnectRtc = createAppThunk(() => (dispatch, getState) => {
165166
const dispatcher = selectRtcConnectionRaw(state).rtcManagerDispatcher;
166167
const isCameraEnabled = selectIsCameraEnabled(state);
167168
const isMicrophoneEnabled = selectIsMicrophoneEnabled(state);
169+
const isNodeSdk = selectAppIsNodeSdk(state);
168170

169171
if (dispatcher) {
170172
return;
@@ -193,6 +195,7 @@ export const doConnectRtc = createAppThunk(() => (dispatch, getState) => {
193195
vp9On: false,
194196
h264On: false,
195197
simulcastScreenshareOn: false,
198+
deviceHandlerFactory: isNodeSdk ? MediasoupDeviceHandler.createFactory() : undefined,
196199
},
197200
});
198201

src/types.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ declare module "heresy" {
2020
}
2121

2222
declare module "@whereby/jslib-media/src/webrtc/RtcManagerDispatcher" {
23+
import { type HandlerFactory } from "mediasoup-client/lib/handlers/HandlerInterface";
2324
enum RtcEventNames {
2425
rtc_manager_created = "rtc_manager_created",
2526
stream_added = "stream_added",
@@ -57,6 +58,7 @@ declare module "@whereby/jslib-media/src/webrtc/RtcManagerDispatcher" {
5758
vp9On: boolean;
5859
h264On: boolean;
5960
simulcastScreenshareOn: boolean;
61+
deviceHandlerFactory?: HandlerFactory;
6062
};
6163
logger: {
6264
debug: (message: string) => void;

0 commit comments

Comments
 (0)