@whereby.com/core 0.30.3 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -76,7 +76,7 @@ const createReactor = (selectors, callback) => {
76
76
  });
77
77
  };
78
78
 
79
- const coreVersion = "0.30.3";
79
+ const coreVersion = "0.31.0";
80
80
 
81
81
  const initialState$g = {
82
82
  isNodeSdk: false,
@@ -515,59 +515,22 @@ const selectCloudRecordingStartedAt = (state) => state.cloudRecording.startedAt;
515
515
  const selectCloudRecordingError = (state) => state.cloudRecording.error;
516
516
  const selectIsCloudRecording = (state) => state.cloudRecording.isRecording;
517
517
 
518
- const initialState$b = {
519
- data: null,
520
- isFetching: false,
521
- error: null,
518
+ const selectRoomConnectionRaw = (state) => state.roomConnection;
519
+ const selectRoomConnectionSession = (state) => state.roomConnection.session;
520
+ const selectRoomConnectionSessionId = (state) => { var _a; return (_a = state.roomConnection.session) === null || _a === void 0 ? void 0 : _a.id; };
521
+ const selectRoomConnectionStatus = (state) => state.roomConnection.status;
522
+ const selectRoomConnectionError = (state) => state.roomConnection.error;
523
+
524
+ function createRtcEventAction(name) {
525
+ return toolkit.createAction(`rtcConnection/event/${name}`);
526
+ }
527
+ const rtcEvents = {
528
+ rtcManagerCreated: createRtcEventAction("rtcManagerCreated"),
529
+ rtcManagerDestroyed: createRtcEventAction("rtcManagerDestroyed"),
530
+ streamAdded: createRtcEventAction("streamAdded"),
522
531
  };
523
- const organizationSlice = toolkit.createSlice({
524
- initialState: initialState$b,
525
- name: "organization",
526
- reducers: {},
527
- extraReducers: (builder) => {
528
- builder.addCase(doOrganizationFetch.pending, (state) => {
529
- return Object.assign(Object.assign({}, state), { isFetching: true });
530
- });
531
- builder.addCase(doOrganizationFetch.fulfilled, (state, action) => {
532
- if (!action.payload)
533
- return Object.assign(Object.assign({}, state), { isFetching: true });
534
- return Object.assign(Object.assign({}, state), { isFetching: false, data: action.payload });
535
- });
536
- builder.addCase(doOrganizationFetch.rejected, (state) => {
537
- return Object.assign(Object.assign({}, state), { isFetching: false, error: true });
538
- });
539
- },
540
- });
541
- const doOrganizationFetch = createAppAsyncThunk("organization/doOrganizationFetch", (_, { extra, getState }) => __awaiter(void 0, void 0, void 0, function* () {
542
- try {
543
- const roomUrl = selectAppRoomUrl(getState());
544
- const organization = yield extra.services.fetchOrganizationFromRoomUrl(roomUrl || "");
545
- if (!organization) {
546
- throw new Error("Invalid room url");
547
- }
548
- return organization;
549
- }
550
- catch (error) {
551
- console.error(error);
552
- }
553
- }));
554
- const selectOrganizationRaw = (state) => state.organization;
555
- const selectOrganizationId = (state) => { var _a; return (_a = state.organization.data) === null || _a === void 0 ? void 0 : _a.organizationId; };
556
- const selectShouldFetchOrganization = toolkit.createSelector(selectAppIsActive, selectOrganizationRaw, selectDeviceCredentialsRaw, (appIsActive, organization, deviceCredentials) => {
557
- if (appIsActive &&
558
- !organization.data &&
559
- !organization.isFetching &&
560
- !organization.error &&
561
- !deviceCredentials.isFetching) {
562
- return true;
563
- }
564
- return false;
565
- });
566
- createReactor([selectShouldFetchOrganization], ({ dispatch }, shouldFetchOrganization) => {
567
- if (shouldFetchOrganization) {
568
- dispatch(doOrganizationFetch());
569
- }
570
- });
532
+
533
+ const NON_PERSON_ROLES = ["recorder", "streamer"];
571
534
 
572
535
  function fakeAudioStream() {
573
536
  const audioCtx = new AudioContext();
@@ -1139,9 +1102,7 @@ startAppListening({
1139
1102
  },
1140
1103
  });
1141
1104
 
1142
- const NON_PERSON_ROLES = ["recorder", "streamer"];
1143
-
1144
- const initialState$a = {
1105
+ const initialState$b = {
1145
1106
  displayName: "",
1146
1107
  id: "",
1147
1108
  breakoutGroup: null,
@@ -1157,7 +1118,7 @@ const initialState$a = {
1157
1118
  };
1158
1119
  const localParticipantSlice = toolkit.createSlice({
1159
1120
  name: "localParticipant",
1160
- initialState: initialState$a,
1121
+ initialState: initialState$b,
1161
1122
  reducers: {
1162
1123
  setDisplayName: (state, action) => {
1163
1124
  return Object.assign(Object.assign({}, state), { displayName: action.payload.displayName });
@@ -1265,6 +1226,10 @@ startAppListening({
1265
1226
  effect: ({ payload }, { dispatch, getState }) => {
1266
1227
  const { enabled } = payload;
1267
1228
  const { isVideoEnabled } = selectLocalParticipantRaw(getState());
1229
+ const roomConnectionStatus = selectRoomConnectionStatus(getState());
1230
+ if (roomConnectionStatus !== "connected") {
1231
+ return;
1232
+ }
1268
1233
  dispatch(doEnableVideo({ enabled: enabled || !isVideoEnabled }));
1269
1234
  },
1270
1235
  });
@@ -1273,196 +1238,19 @@ startAppListening({
1273
1238
  effect: ({ payload }, { dispatch, getState }) => {
1274
1239
  const { enabled } = payload;
1275
1240
  const { isAudioEnabled } = selectLocalParticipantRaw(getState());
1276
- dispatch(doEnableAudio({ enabled: enabled || !isAudioEnabled }));
1277
- },
1278
- });
1279
- createReactor([selectLocalParticipantDisplayName, selectLocalParticipantStickyReaction], ({ dispatch }) => {
1280
- dispatch(doSendClientMetadata());
1281
- });
1282
-
1283
- const initialState$9 = {
1284
- session: null,
1285
- status: "ready",
1286
- error: null,
1287
- };
1288
- const roomConnectionSlice = toolkit.createSlice({
1289
- initialState: initialState$9,
1290
- name: "roomConnection",
1291
- reducers: {
1292
- connectionStatusChanged: (state, action) => {
1293
- return Object.assign(Object.assign({}, state), { status: action.payload });
1294
- },
1295
- },
1296
- extraReducers: (builder) => {
1297
- builder.addCase(signalEvents.roomJoined, (state, action) => {
1298
- var _a, _b;
1299
- const { error, isLocked } = action.payload;
1300
- if (error === "room_locked" && isLocked) {
1301
- return Object.assign(Object.assign({}, state), { status: "room_locked" });
1302
- }
1303
- if (error) {
1304
- return Object.assign(Object.assign({}, state), { status: "disconnected", error });
1305
- }
1306
- return Object.assign(Object.assign({}, state), { status: "connected", session: (_b = (_a = action.payload.room) === null || _a === void 0 ? void 0 : _a.session) !== null && _b !== void 0 ? _b : null });
1307
- });
1308
- builder.addCase(signalEvents.disconnect, (state) => {
1309
- if (["kicked", "left"].includes(state.status)) {
1310
- return Object.assign({}, state);
1311
- }
1312
- return Object.assign(Object.assign({}, state), { status: "disconnected" });
1313
- });
1314
- builder.addCase(signalEvents.newClient, (state, action) => {
1315
- var _a, _b;
1316
- return Object.assign(Object.assign({}, state), { session: (_b = (_a = action.payload.room) === null || _a === void 0 ? void 0 : _a.session) !== null && _b !== void 0 ? _b : null });
1317
- });
1318
- builder.addCase(signalEvents.roomSessionEnded, (state, action) => {
1319
- var _a;
1320
- if (((_a = state.session) === null || _a === void 0 ? void 0 : _a.id) !== action.payload.roomSessionId) {
1321
- return state;
1322
- }
1323
- return Object.assign(Object.assign({}, state), { session: null });
1324
- });
1325
- builder.addCase(signalEvents.clientKicked, (state) => {
1326
- return Object.assign(Object.assign({}, state), { status: "kicked" });
1327
- });
1328
- builder.addCase(signalEvents.roomLeft, (state) => {
1329
- return Object.assign(Object.assign({}, state), { status: "left" });
1330
- });
1331
- builder.addCase(socketReconnecting, (state) => {
1332
- return Object.assign(Object.assign({}, state), { status: "reconnecting" });
1333
- });
1334
- },
1335
- });
1336
- const { connectionStatusChanged } = roomConnectionSlice.actions;
1337
- const doKnockRoom = createAppThunk(() => (dispatch, getState) => {
1338
- const state = getState();
1339
- const socket = selectSignalConnectionRaw(state).socket;
1340
- const roomName = selectAppRoomName(state);
1341
- const roomKey = selectRoomKey(state);
1342
- const displayName = selectAppDisplayName(state);
1343
- const isDialIn = selectAppIsDialIn(state);
1344
- const userAgent = selectAppUserAgent(state);
1345
- const externalId = selectAppExternalId(state);
1346
- const organizationId = selectOrganizationId(state);
1347
- const connectionStatus = selectRoomConnectionStatus(state);
1348
- if (connectionStatus !== "room_locked") {
1349
- console.warn("Room is not locked, knock aborted");
1350
- return;
1351
- }
1352
- socket === null || socket === void 0 ? void 0 : socket.emit("knock_room", {
1353
- avatarUrl: null,
1354
- config: {
1355
- isAudioEnabled: true,
1356
- isVideoEnabled: true,
1357
- },
1358
- deviceCapabilities: { canScreenshare: true },
1359
- displayName,
1360
- isCoLocated: false,
1361
- isDialIn,
1362
- isDevicePermissionDenied: false,
1363
- kickFromOtherRooms: false,
1364
- organizationId,
1365
- roomKey,
1366
- roomName,
1367
- userAgent,
1368
- externalId,
1369
- });
1370
- dispatch(connectionStatusChanged("knocking"));
1371
- });
1372
- const doConnectRoom = createAppThunk(() => (dispatch, getState) => {
1373
- const state = getState();
1374
- const socket = selectSignalConnectionRaw(state).socket;
1375
- const roomName = selectAppRoomName(state);
1376
- const roomKey = selectRoomKey(state);
1377
- const displayName = selectAppDisplayName(state);
1378
- const userAgent = selectAppUserAgent(state);
1379
- const externalId = selectAppExternalId(state);
1380
- const isDialIn = selectAppIsDialIn(state);
1381
- const organizationId = selectOrganizationId(state);
1382
- const isCameraEnabled = selectIsCameraEnabled(getState());
1383
- const isMicrophoneEnabled = selectIsMicrophoneEnabled(getState());
1384
- const clientClaim = selectLocalParticipantClientClaim(getState());
1385
- socket === null || socket === void 0 ? void 0 : socket.emit("join_room", Object.assign({ avatarUrl: null, config: {
1386
- isAudioEnabled: isMicrophoneEnabled,
1387
- isVideoEnabled: isCameraEnabled,
1388
- }, deviceCapabilities: { canScreenshare: true }, displayName, isCoLocated: false, isDialIn, isDevicePermissionDenied: false, kickFromOtherRooms: false, organizationId,
1389
- roomKey,
1390
- roomName,
1391
- userAgent,
1392
- externalId }, (clientClaim && { clientClaim })));
1393
- dispatch(connectionStatusChanged("connecting"));
1394
- });
1395
- const selectRoomConnectionRaw = (state) => state.roomConnection;
1396
- const selectRoomConnectionSession = (state) => state.roomConnection.session;
1397
- const selectRoomConnectionSessionId = (state) => { var _a; return (_a = state.roomConnection.session) === null || _a === void 0 ? void 0 : _a.id; };
1398
- const selectRoomConnectionStatus = (state) => state.roomConnection.status;
1399
- const selectRoomConnectionError = (state) => state.roomConnection.error;
1400
- const selectShouldConnectRoom = toolkit.createSelector([
1401
- selectAppIsActive,
1402
- selectOrganizationId,
1403
- selectRoomConnectionStatus,
1404
- selectSignalConnectionDeviceIdentified,
1405
- selectLocalMediaStatus,
1406
- selectRoomConnectionError,
1407
- ], (appIsActive, hasOrganizationIdFetched, roomConnectionStatus, signalConnectionDeviceIdentified, localMediaStatus, roomConnectionError) => {
1408
- if (appIsActive &&
1409
- localMediaStatus === "started" &&
1410
- signalConnectionDeviceIdentified &&
1411
- !!hasOrganizationIdFetched &&
1412
- ["ready", "reconnecting", "disconnected"].includes(roomConnectionStatus) &&
1413
- !roomConnectionError) {
1414
- return true;
1415
- }
1416
- return false;
1417
- });
1418
- createReactor([selectShouldConnectRoom], ({ dispatch }, shouldConnectRoom) => {
1419
- if (shouldConnectRoom) {
1420
- dispatch(doConnectRoom());
1421
- }
1422
- });
1423
- startAppListening({
1424
- actionCreator: signalEvents.knockHandled,
1425
- effect: ({ payload }, { dispatch, getState }) => {
1426
- const { clientId, resolution } = payload;
1427
- const state = getState();
1428
- const selfId = selectSelfId(state);
1429
- if (clientId !== selfId) {
1241
+ const roomConnectionStatus = selectRoomConnectionStatus(getState());
1242
+ if (roomConnectionStatus !== "connected") {
1430
1243
  return;
1431
1244
  }
1432
- if (resolution === "accepted") {
1433
- dispatch(setRoomKey(payload.metadata.roomKey));
1434
- dispatch(doConnectRoom());
1435
- }
1436
- else if (resolution === "rejected") {
1437
- dispatch(connectionStatusChanged("knock_rejected"));
1438
- }
1245
+ dispatch(doEnableAudio({ enabled: enabled || !isAudioEnabled }));
1439
1246
  },
1440
1247
  });
1441
- startAppListening({
1442
- actionCreator: doAppStop,
1443
- effect: (_, { dispatch, getState }) => {
1444
- const state = getState();
1445
- const roomConnectionStatus = selectRoomConnectionStatus(state);
1446
- if (roomConnectionStatus === "connected") {
1447
- const socket = selectSignalConnectionRaw(state).socket;
1448
- socket === null || socket === void 0 ? void 0 : socket.emit("leave_room");
1449
- dispatch(connectionStatusChanged("leaving"));
1450
- }
1451
- else {
1452
- doSignalDisconnect();
1453
- }
1454
- },
1248
+ createReactor([selectLocalParticipantDisplayName, selectLocalParticipantStickyReaction, selectRoomConnectionStatus], ({ dispatch }, diplayName, stickyReaction, roomConnectionStatus) => {
1249
+ if (roomConnectionStatus === "connected") {
1250
+ dispatch(doSendClientMetadata());
1251
+ }
1455
1252
  });
1456
1253
 
1457
- function createRtcEventAction(name) {
1458
- return toolkit.createAction(`rtcConnection/event/${name}`);
1459
- }
1460
- const rtcEvents = {
1461
- rtcManagerCreated: createRtcEventAction("rtcManagerCreated"),
1462
- rtcManagerDestroyed: createRtcEventAction("rtcManagerDestroyed"),
1463
- streamAdded: createRtcEventAction("streamAdded"),
1464
- };
1465
-
1466
1254
  function createRemoteParticipant(client, newJoiner = false) {
1467
1255
  const { streams, role, breakoutGroup } = client, rest = __rest(client, ["streams", "role", "breakoutGroup"]);
1468
1256
  return Object.assign(Object.assign({}, rest), { stream: null, streams: streams.map((streamId) => ({ id: streamId, state: newJoiner ? "new_accept" : "to_accept" })), isLocalParticipant: false, roleName: (role === null || role === void 0 ? void 0 : role.roleName) || "none", presentationStream: null, breakoutGroup: breakoutGroup || null, newJoiner });
@@ -1554,12 +1342,12 @@ function addStream(state, payload) {
1554
1342
  presentationStream: stream,
1555
1343
  });
1556
1344
  }
1557
- const initialState$8 = {
1345
+ const initialState$a = {
1558
1346
  remoteParticipants: [],
1559
1347
  };
1560
1348
  const remoteParticipantsSlice = toolkit.createSlice({
1561
1349
  name: "remoteParticipants",
1562
- initialState: initialState$8,
1350
+ initialState: initialState$a,
1563
1351
  reducers: {
1564
1352
  streamStatusUpdated: (state, action) => {
1565
1353
  let newState = state;
@@ -1666,14 +1454,14 @@ const selectNumParticipants = toolkit.createSelector(selectRemoteParticipants, s
1666
1454
  return clients.length + 1;
1667
1455
  });
1668
1456
 
1669
- const initialState$7 = {
1457
+ const initialState$9 = {
1670
1458
  status: "inactive",
1671
1459
  stream: null,
1672
1460
  error: null,
1673
1461
  };
1674
1462
  const localScreenshareSlice = toolkit.createSlice({
1675
1463
  name: "localScreenshare",
1676
- initialState: initialState$7,
1464
+ initialState: initialState$9,
1677
1465
  reducers: {
1678
1466
  stopScreenshare(state, action) {
1679
1467
  return Object.assign(Object.assign({}, state), { status: "inactive", stream: null });
@@ -1758,7 +1546,7 @@ const createWebRtcEmitter = (dispatch) => {
1758
1546
  },
1759
1547
  };
1760
1548
  };
1761
- const initialState$6 = {
1549
+ const initialState$8 = {
1762
1550
  dispatcherCreated: false,
1763
1551
  error: null,
1764
1552
  isCreatingDispatcher: false,
@@ -1771,7 +1559,7 @@ const initialState$6 = {
1771
1559
  };
1772
1560
  const rtcConnectionSlice = toolkit.createSlice({
1773
1561
  name: "rtcConnection",
1774
- initialState: initialState$6,
1562
+ initialState: initialState$8,
1775
1563
  reducers: {
1776
1564
  isAcceptingStreams: (state, action) => {
1777
1565
  return Object.assign(Object.assign({}, state), { isAcceptingStreams: action.payload });
@@ -1781,7 +1569,7 @@ const rtcConnectionSlice = toolkit.createSlice({
1781
1569
  return Object.assign(Object.assign({}, state), { reportedStreamResolutions: Object.assign(Object.assign({}, state.reportedStreamResolutions), { [streamId]: { width, height } }) });
1782
1570
  },
1783
1571
  rtcDisconnected: () => {
1784
- return Object.assign({}, initialState$6);
1572
+ return Object.assign({}, initialState$8);
1785
1573
  },
1786
1574
  rtcDispatcherCreated: (state, action) => {
1787
1575
  return Object.assign(Object.assign({}, state), { dispatcherCreated: true, rtcManagerDispatcher: action.payload });
@@ -2055,12 +1843,12 @@ function isStreamerClient(client) {
2055
1843
  function isRecorderClient(client) {
2056
1844
  return client.roleName === "recorder";
2057
1845
  }
2058
- const initialState$5 = {
1846
+ const initialState$7 = {
2059
1847
  isLocked: false,
2060
1848
  };
2061
1849
  const roomSlice = toolkit.createSlice({
2062
1850
  name: "room",
2063
- initialState: initialState$5,
1851
+ initialState: initialState$7,
2064
1852
  reducers: {},
2065
1853
  extraReducers: (builder) => {
2066
1854
  builder.addCase(signalEvents.roomJoined, (state, action) => {
@@ -2160,18 +1948,18 @@ const selectAllClientViews = toolkit.createSelector(selectLocalParticipantView,
2160
1948
  return [...(localParticipant ? [localParticipant] : []), ...remoteParticipants];
2161
1949
  });
2162
1950
 
2163
- const initialState$4 = {
1951
+ const initialState$6 = {
2164
1952
  running: false,
2165
1953
  };
2166
1954
  const connectionMonitorSlice = toolkit.createSlice({
2167
1955
  name: "connectionMonitor",
2168
- initialState: initialState$4,
1956
+ initialState: initialState$6,
2169
1957
  reducers: {
2170
1958
  connectionMonitorStarted: (state, action) => {
2171
1959
  return Object.assign(Object.assign({}, state), { running: true, stopCallbackFunction: action.payload.stopIssueSubscription });
2172
1960
  },
2173
1961
  connectionMonitorStopped: () => {
2174
- return Object.assign({}, initialState$4);
1962
+ return Object.assign({}, initialState$6);
2175
1963
  },
2176
1964
  },
2177
1965
  });
@@ -2434,6 +2222,229 @@ startAppListening({
2434
2222
  },
2435
2223
  });
2436
2224
 
2225
+ const initialState$5 = {
2226
+ data: null,
2227
+ isFetching: false,
2228
+ error: null,
2229
+ };
2230
+ const organizationSlice = toolkit.createSlice({
2231
+ initialState: initialState$5,
2232
+ name: "organization",
2233
+ reducers: {},
2234
+ extraReducers: (builder) => {
2235
+ builder.addCase(doOrganizationFetch.pending, (state) => {
2236
+ return Object.assign(Object.assign({}, state), { isFetching: true });
2237
+ });
2238
+ builder.addCase(doOrganizationFetch.fulfilled, (state, action) => {
2239
+ if (!action.payload)
2240
+ return Object.assign(Object.assign({}, state), { isFetching: true });
2241
+ return Object.assign(Object.assign({}, state), { isFetching: false, data: action.payload });
2242
+ });
2243
+ builder.addCase(doOrganizationFetch.rejected, (state) => {
2244
+ return Object.assign(Object.assign({}, state), { isFetching: false, error: true });
2245
+ });
2246
+ },
2247
+ });
2248
+ const doOrganizationFetch = createAppAsyncThunk("organization/doOrganizationFetch", (_, { extra, getState }) => __awaiter(void 0, void 0, void 0, function* () {
2249
+ try {
2250
+ const roomUrl = selectAppRoomUrl(getState());
2251
+ const organization = yield extra.services.fetchOrganizationFromRoomUrl(roomUrl || "");
2252
+ if (!organization) {
2253
+ throw new Error("Invalid room url");
2254
+ }
2255
+ return organization;
2256
+ }
2257
+ catch (error) {
2258
+ console.error(error);
2259
+ }
2260
+ }));
2261
+ const selectOrganizationRaw = (state) => state.organization;
2262
+ const selectOrganizationId = (state) => { var _a; return (_a = state.organization.data) === null || _a === void 0 ? void 0 : _a.organizationId; };
2263
+ const selectShouldFetchOrganization = toolkit.createSelector(selectAppIsActive, selectOrganizationRaw, selectDeviceCredentialsRaw, (appIsActive, organization, deviceCredentials) => {
2264
+ if (appIsActive &&
2265
+ !organization.data &&
2266
+ !organization.isFetching &&
2267
+ !organization.error &&
2268
+ !deviceCredentials.isFetching) {
2269
+ return true;
2270
+ }
2271
+ return false;
2272
+ });
2273
+ createReactor([selectShouldFetchOrganization], ({ dispatch }, shouldFetchOrganization) => {
2274
+ if (shouldFetchOrganization) {
2275
+ dispatch(doOrganizationFetch());
2276
+ }
2277
+ });
2278
+
2279
+ const initialState$4 = {
2280
+ session: null,
2281
+ status: "ready",
2282
+ error: null,
2283
+ };
2284
+ const roomConnectionSlice = toolkit.createSlice({
2285
+ initialState: initialState$4,
2286
+ name: "roomConnection",
2287
+ reducers: {
2288
+ connectionStatusChanged: (state, action) => {
2289
+ return Object.assign(Object.assign({}, state), { status: action.payload });
2290
+ },
2291
+ },
2292
+ extraReducers: (builder) => {
2293
+ builder.addCase(signalEvents.roomJoined, (state, action) => {
2294
+ var _a, _b;
2295
+ const { error, isLocked } = action.payload;
2296
+ if (error === "room_locked" && isLocked) {
2297
+ return Object.assign(Object.assign({}, state), { status: "room_locked" });
2298
+ }
2299
+ if (error) {
2300
+ return Object.assign(Object.assign({}, state), { status: "disconnected", error });
2301
+ }
2302
+ return Object.assign(Object.assign({}, state), { status: "connected", session: (_b = (_a = action.payload.room) === null || _a === void 0 ? void 0 : _a.session) !== null && _b !== void 0 ? _b : null });
2303
+ });
2304
+ builder.addCase(signalEvents.disconnect, (state) => {
2305
+ if (["kicked", "left"].includes(state.status)) {
2306
+ return Object.assign({}, state);
2307
+ }
2308
+ return Object.assign(Object.assign({}, state), { status: "disconnected" });
2309
+ });
2310
+ builder.addCase(signalEvents.newClient, (state, action) => {
2311
+ var _a, _b;
2312
+ return Object.assign(Object.assign({}, state), { session: (_b = (_a = action.payload.room) === null || _a === void 0 ? void 0 : _a.session) !== null && _b !== void 0 ? _b : null });
2313
+ });
2314
+ builder.addCase(signalEvents.roomSessionEnded, (state, action) => {
2315
+ var _a;
2316
+ if (((_a = state.session) === null || _a === void 0 ? void 0 : _a.id) !== action.payload.roomSessionId) {
2317
+ return state;
2318
+ }
2319
+ return Object.assign(Object.assign({}, state), { session: null });
2320
+ });
2321
+ builder.addCase(signalEvents.clientKicked, (state) => {
2322
+ return Object.assign(Object.assign({}, state), { status: "kicked" });
2323
+ });
2324
+ builder.addCase(signalEvents.roomLeft, (state) => {
2325
+ return Object.assign(Object.assign({}, state), { status: "left" });
2326
+ });
2327
+ builder.addCase(socketReconnecting, (state) => {
2328
+ return Object.assign(Object.assign({}, state), { status: "reconnecting" });
2329
+ });
2330
+ },
2331
+ });
2332
+ const { connectionStatusChanged } = roomConnectionSlice.actions;
2333
+ const doKnockRoom = createAppThunk(() => (dispatch, getState) => {
2334
+ const state = getState();
2335
+ const socket = selectSignalConnectionRaw(state).socket;
2336
+ const roomName = selectAppRoomName(state);
2337
+ const roomKey = selectRoomKey(state);
2338
+ const displayName = selectAppDisplayName(state);
2339
+ const isDialIn = selectAppIsDialIn(state);
2340
+ const userAgent = selectAppUserAgent(state);
2341
+ const externalId = selectAppExternalId(state);
2342
+ const organizationId = selectOrganizationId(state);
2343
+ const connectionStatus = selectRoomConnectionStatus(state);
2344
+ if (connectionStatus !== "room_locked") {
2345
+ console.warn("Room is not locked, knock aborted");
2346
+ return;
2347
+ }
2348
+ socket === null || socket === void 0 ? void 0 : socket.emit("knock_room", {
2349
+ avatarUrl: null,
2350
+ config: {
2351
+ isAudioEnabled: true,
2352
+ isVideoEnabled: true,
2353
+ },
2354
+ deviceCapabilities: { canScreenshare: true },
2355
+ displayName,
2356
+ isCoLocated: false,
2357
+ isDialIn,
2358
+ isDevicePermissionDenied: false,
2359
+ kickFromOtherRooms: false,
2360
+ organizationId,
2361
+ roomKey,
2362
+ roomName,
2363
+ userAgent,
2364
+ externalId,
2365
+ });
2366
+ dispatch(connectionStatusChanged("knocking"));
2367
+ });
2368
+ const doConnectRoom = createAppThunk(() => (dispatch, getState) => {
2369
+ const state = getState();
2370
+ const socket = selectSignalConnectionRaw(state).socket;
2371
+ const roomName = selectAppRoomName(state);
2372
+ const roomKey = selectRoomKey(state);
2373
+ const displayName = selectAppDisplayName(state);
2374
+ const userAgent = selectAppUserAgent(state);
2375
+ const externalId = selectAppExternalId(state);
2376
+ const isDialIn = selectAppIsDialIn(state);
2377
+ const organizationId = selectOrganizationId(state);
2378
+ const isCameraEnabled = selectIsCameraEnabled(getState());
2379
+ const isMicrophoneEnabled = selectIsMicrophoneEnabled(getState());
2380
+ const clientClaim = selectLocalParticipantClientClaim(getState());
2381
+ socket === null || socket === void 0 ? void 0 : socket.emit("join_room", Object.assign({ avatarUrl: null, config: {
2382
+ isAudioEnabled: isMicrophoneEnabled,
2383
+ isVideoEnabled: isCameraEnabled,
2384
+ }, deviceCapabilities: { canScreenshare: true }, displayName, isCoLocated: false, isDialIn, isDevicePermissionDenied: false, kickFromOtherRooms: false, organizationId,
2385
+ roomKey,
2386
+ roomName,
2387
+ userAgent,
2388
+ externalId }, (clientClaim && { clientClaim })));
2389
+ dispatch(connectionStatusChanged("connecting"));
2390
+ });
2391
+ const selectShouldConnectRoom = toolkit.createSelector([
2392
+ selectAppIsActive,
2393
+ selectOrganizationId,
2394
+ selectRoomConnectionStatus,
2395
+ selectSignalConnectionDeviceIdentified,
2396
+ selectLocalMediaStatus,
2397
+ selectRoomConnectionError,
2398
+ ], (appIsActive, hasOrganizationIdFetched, roomConnectionStatus, signalConnectionDeviceIdentified, localMediaStatus, roomConnectionError) => {
2399
+ if (appIsActive &&
2400
+ localMediaStatus === "started" &&
2401
+ signalConnectionDeviceIdentified &&
2402
+ !!hasOrganizationIdFetched &&
2403
+ ["ready", "reconnecting", "disconnected"].includes(roomConnectionStatus) &&
2404
+ !roomConnectionError) {
2405
+ return true;
2406
+ }
2407
+ return false;
2408
+ });
2409
+ createReactor([selectShouldConnectRoom], ({ dispatch }, shouldConnectRoom) => {
2410
+ if (shouldConnectRoom) {
2411
+ dispatch(doConnectRoom());
2412
+ }
2413
+ });
2414
+ startAppListening({
2415
+ actionCreator: signalEvents.knockHandled,
2416
+ effect: ({ payload }, { dispatch, getState }) => {
2417
+ const { clientId, resolution } = payload;
2418
+ const state = getState();
2419
+ const selfId = selectSelfId(state);
2420
+ if (clientId !== selfId) {
2421
+ return;
2422
+ }
2423
+ if (resolution === "accepted") {
2424
+ dispatch(setRoomKey(payload.metadata.roomKey));
2425
+ dispatch(doConnectRoom());
2426
+ }
2427
+ else if (resolution === "rejected") {
2428
+ dispatch(connectionStatusChanged("knock_rejected"));
2429
+ }
2430
+ },
2431
+ });
2432
+ startAppListening({
2433
+ actionCreator: doAppStop,
2434
+ effect: (_, { dispatch, getState }) => {
2435
+ const state = getState();
2436
+ const roomConnectionStatus = selectRoomConnectionStatus(state);
2437
+ if (roomConnectionStatus === "connected") {
2438
+ const socket = selectSignalConnectionRaw(state).socket;
2439
+ socket === null || socket === void 0 ? void 0 : socket.emit("leave_room");
2440
+ dispatch(connectionStatusChanged("leaving"));
2441
+ }
2442
+ else {
2443
+ doSignalDisconnect();
2444
+ }
2445
+ },
2446
+ });
2447
+
2437
2448
  const rtcAnalyticsCustomEvents = {
2438
2449
  audioEnabled: {
2439
2450
  actions: [doEnableAudio.fulfilled],