@whereby.com/core 1.21.2 → 1.22.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.
@@ -1,5 +1,5 @@
1
1
  import nodeBtoa from 'btoa';
2
- import { assert, fromLocation, ServerSocket, isFileShareError, getDeviceData, getStream, getUpdatedDevices, replaceTracksInStream, getDisplayMedia, CAMERA_STREAM_ID, RtcManagerDispatcher, setClientProvider, subscribeIssues } from '@whereby.com/media';
2
+ import { assert, fromLocation, ServerSocket, isFileShareError, getDeviceData, getStream, getUpdatedDevices, replaceTracksInStream, getDisplayMedia, CAMERA_STREAM_ID, RtcManagerDispatcher, setClientProvider, subscribeIssues, isRoomIntegrationErrorCode } from '@whereby.com/media';
3
3
  import axios from 'axios';
4
4
  import { EventEmitter } from 'events';
5
5
  import { createListenerMiddleware, addListener, createSlice, createAction, createSelector, createAsyncThunk, isAnyOf, combineReducers, configureStore } from '@reduxjs/toolkit';
@@ -970,15 +970,6 @@ class RoomService {
970
970
  }
971
971
  }
972
972
 
973
- class LiveCaption {
974
- constructor({ resultId, senderId, text }) {
975
- this.resultId = resultId;
976
- this.participantId = senderId;
977
- this.text = text;
978
- this.timestamp = Date.now();
979
- }
980
- }
981
-
982
973
  /******************************************************************************
983
974
  Copyright (c) Microsoft Corporation.
984
975
 
@@ -1023,6 +1014,49 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
1023
1014
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1024
1015
  };
1025
1016
 
1017
+ function roomPath(organizationId, roomName, suffix = "") {
1018
+ const encodedRoomName = encodeURIComponent(roomName.replace(/^\//, ""));
1019
+ return `/organizations/${encodeURIComponent(organizationId)}/room/${encodedRoomName}${suffix}`;
1020
+ }
1021
+ function asArray(value) {
1022
+ return Array.isArray(value) ? value : [];
1023
+ }
1024
+ class RoomIntegrationService {
1025
+ constructor({ apiClient }) {
1026
+ this._apiClient = apiClient;
1027
+ }
1028
+ findRoomIntegrations(_a) {
1029
+ return __awaiter(this, arguments, void 0, function* ({ organizationId, roomName, }) {
1030
+ const response = yield this._apiClient.request(roomPath(organizationId, roomName, "/room-integrations"), {
1031
+ method: "GET",
1032
+ });
1033
+ const data = (response.data || {});
1034
+ return {
1035
+ enabledRoomIntegrations: asArray(data.enabledRoomIntegrations),
1036
+ disabledRoomIntegrations: asArray(data.disabledRoomIntegrations),
1037
+ unavailableRoomIntegrations: asArray(data.unavailableRoomIntegrations),
1038
+ };
1039
+ });
1040
+ }
1041
+ toggleRoomIntegration(_a) {
1042
+ return __awaiter(this, arguments, void 0, function* ({ organizationId, roomName, roomIntegrationId, enable, }) {
1043
+ yield this._apiClient.request(roomPath(organizationId, roomName, `/room-integrations/${roomIntegrationId}`), {
1044
+ method: "PUT",
1045
+ data: { enable },
1046
+ });
1047
+ });
1048
+ }
1049
+ }
1050
+
1051
+ class LiveCaption {
1052
+ constructor({ resultId, senderId, text }) {
1053
+ this.resultId = resultId;
1054
+ this.participantId = senderId;
1055
+ this.text = text;
1056
+ this.timestamp = Date.now();
1057
+ }
1058
+ }
1059
+
1026
1060
  function getUsableCameraEffectPresets() {
1027
1061
  return __awaiter(this, void 0, void 0, function* () {
1028
1062
  const { getUsablePresets } = yield import('@whereby.com/camera-effects');
@@ -1036,6 +1070,54 @@ function isAudioDenoiserSupported() {
1036
1070
  });
1037
1071
  }
1038
1072
 
1073
+ function roomIntegrationContentTagName(integrationName) {
1074
+ return `${integrationName}-integration-contentframe`;
1075
+ }
1076
+ const YOUTUBE_ID = /(?:youtu\.be\/|youtube(?:-nocookie)?\.com\/(?:watch\?(?:.*&)?v=|embed\/|shorts\/|live\/))([\w-]{11})/i;
1077
+ const YOUTUBE_BARE_ID = /^[\w-]{11}$/;
1078
+ function youtubeStartSeconds(url) {
1079
+ const match = url.match(/[?&](?:t|start)=(\d+)s?/i);
1080
+ return match ? parseInt(match[1], 10) : 0;
1081
+ }
1082
+ function youtube({ url, startAt, metadata = {}, }) {
1083
+ var _a;
1084
+ const trimmed = (url || "").trim();
1085
+ const videoref = YOUTUBE_BARE_ID.test(trimmed) ? trimmed : (_a = trimmed.match(YOUTUBE_ID)) === null || _a === void 0 ? void 0 : _a[1];
1086
+ if (!videoref) {
1087
+ return null;
1088
+ }
1089
+ const time = startAt !== null && startAt !== void 0 ? startAt : youtubeStartSeconds(trimmed);
1090
+ const { aspectRatio = 16 / 9, isLive = false, title } = metadata;
1091
+ return {
1092
+ tagName: roomIntegrationContentTagName("youtube"),
1093
+ shareUrl: `https://www.youtube.com/watch?v=${videoref}${time ? `&t=${time}s` : ""}`,
1094
+ props: {
1095
+ videoref,
1096
+ time,
1097
+ seek: time,
1098
+ playerstate: "playing",
1099
+ started: Date.now() + 4000,
1100
+ paused: false,
1101
+ aspectratio: aspectRatio,
1102
+ islive: isLive,
1103
+ metadata: JSON.stringify(Object.assign({ id: videoref, aspectratio: aspectRatio, live: isLive }, (title ? { title } : {}))),
1104
+ },
1105
+ };
1106
+ }
1107
+ const MIRO_EMBED_LINK = /^https:\/\/miro\.com\/app\/(?:live-embed|access-link)\/[0-9a-zA-Z]+/i;
1108
+ function miro({ accessLink }) {
1109
+ const trimmed = (accessLink || "").trim();
1110
+ if (!MIRO_EMBED_LINK.test(trimmed)) {
1111
+ return null;
1112
+ }
1113
+ return {
1114
+ tagName: roomIntegrationContentTagName("miro"),
1115
+ shareUrl: trimmed,
1116
+ props: { accesslink: trimmed },
1117
+ };
1118
+ }
1119
+ const roomIntegrationContent = { youtube, miro };
1120
+
1039
1121
  class RoomParticipant {
1040
1122
  constructor({ breakoutGroup, displayName, id, isAudioEnabled, isAudioRecorder, isDialIn, isVideoEnabled, stickyReaction, stream, }) {
1041
1123
  this.isLocalParticipant = false;
@@ -1077,6 +1159,7 @@ function createServices() {
1077
1159
  baseUrl: API_BASE_URL,
1078
1160
  });
1079
1161
  const organizationService = new OrganizationService({ apiClient });
1162
+ const roomIntegrationService = new RoomIntegrationService({ apiClient });
1080
1163
  const fetchOrganizationFromRoomUrl = (roomUrl) => {
1081
1164
  const roomUrlObj = new URL(roomUrl);
1082
1165
  const urls = fromLocation({ host: roomUrlObj.host });
@@ -1090,6 +1173,7 @@ function createServices() {
1090
1173
  credentialsService,
1091
1174
  apiClient,
1092
1175
  organizationService,
1176
+ roomIntegrationService,
1093
1177
  fetchOrganizationFromRoomUrl,
1094
1178
  };
1095
1179
  }
@@ -1224,7 +1308,7 @@ const createReactor = (selectors, callback) => {
1224
1308
  });
1225
1309
  };
1226
1310
 
1227
- const coreVersion = "1.21.2";
1311
+ const coreVersion = "1.22.0";
1228
1312
 
1229
1313
  function decodeRoomName(roomName) {
1230
1314
  if (!roomName) {
@@ -1304,6 +1388,11 @@ const signalEvents = {
1304
1388
  knockerLeft: createSignalEventAction("knockerLeft"),
1305
1389
  knockHandled: createSignalEventAction("knockHandled"),
1306
1390
  newClient: createSignalEventAction("newClient"),
1391
+ roomIntegrationStarted: createSignalEventAction("roomIntegrationStarted"),
1392
+ roomIntegrationStopped: createSignalEventAction("roomIntegrationStopped"),
1393
+ roomIntegrationPropsUpdated: createSignalEventAction("roomIntegrationPropsUpdated"),
1394
+ roomIntegrationEnabled: createSignalEventAction("roomIntegrationEnabled"),
1395
+ roomIntegrationDisabled: createSignalEventAction("roomIntegrationDisabled"),
1307
1396
  roomJoined: createSignalEventAction("roomJoined"),
1308
1397
  roomKnocked: createSignalEventAction("roomKnocked"),
1309
1398
  roomLeft: createSignalEventAction("roomLeft"),
@@ -1334,6 +1423,7 @@ const ROOM_ACTION_PERMISSIONS_BY_ROLE = {
1334
1423
  canAskToSpeak: ["host"],
1335
1424
  canSpotlight: ["host"],
1336
1425
  canManageBreakout: ["host"],
1426
+ canManageRoomIntegration: ["host"],
1337
1427
  };
1338
1428
  const authorizationSliceInitialState = {
1339
1429
  roomKey: null,
@@ -1378,6 +1468,7 @@ const selectIsAuthorizedToEndMeeting = createSelector(selectAuthorizationRoleNam
1378
1468
  const selectIsAuthorizedToAskToSpeak = createSelector(selectAuthorizationRoleName, (localParticipantRole) => ROOM_ACTION_PERMISSIONS_BY_ROLE.canAskToSpeak.includes(localParticipantRole));
1379
1469
  const selectIsAuthorizedToSpotlight = createSelector(selectAuthorizationRoleName, (localParticipantRole) => ROOM_ACTION_PERMISSIONS_BY_ROLE.canSpotlight.includes(localParticipantRole));
1380
1470
  const selectIsAuthorizedToManageBreakout = createSelector(selectAuthorizationRoleName, (localParticipantRole) => ROOM_ACTION_PERMISSIONS_BY_ROLE.canManageBreakout.includes(localParticipantRole));
1471
+ const selectIsAuthorizedToManageRoomIntegration = createSelector(selectAuthorizationRoleName, (localParticipantRole) => ROOM_ACTION_PERMISSIONS_BY_ROLE.canManageRoomIntegration.includes(localParticipantRole));
1381
1472
 
1382
1473
  function createAppAsyncThunk(typePrefix, payloadCreator) {
1383
1474
  return createAsyncThunk(typePrefix, payloadCreator);
@@ -1511,6 +1602,11 @@ function forwardSocketEvents(socket, dispatch) {
1511
1602
  socket.on("video_enable_requested", (payload) => dispatch(signalEvents.videoEnableRequested(payload)));
1512
1603
  socket.on("breakout_group_joined", (payload) => dispatch(signalEvents.breakoutGroupJoined(payload)));
1513
1604
  socket.on("breakout_session_updated", (payload) => dispatch(signalEvents.breakoutSessionUpdated(payload)));
1605
+ socket.on("room_integration_started", (payload) => dispatch(signalEvents.roomIntegrationStarted(payload)));
1606
+ socket.on("room_integration_stopped", (payload) => dispatch(signalEvents.roomIntegrationStopped(payload)));
1607
+ socket.on("room_integration_props_updated", (payload) => dispatch(signalEvents.roomIntegrationPropsUpdated(payload)));
1608
+ socket.on("room_integration_enabled", (payload) => dispatch(signalEvents.roomIntegrationEnabled(payload)));
1609
+ socket.on("room_integration_disabled", (payload) => dispatch(signalEvents.roomIntegrationDisabled(payload)));
1514
1610
  socket.on("breakout_move_to_group", () => dispatch(signalEvents.breakoutMoveToGroup()));
1515
1611
  socket.on("breakout_move_to_main", () => dispatch(signalEvents.breakoutMoveToMain()));
1516
1612
  socket.on("breakout_ending", () => dispatch(signalEvents.breakoutEnding()));
@@ -4553,6 +4649,378 @@ startAppListening({
4553
4649
  },
4554
4650
  });
4555
4651
 
4652
+ function isCustomElementName(value) {
4653
+ return typeof value === "string" && value === value.toLowerCase() && value.includes("-");
4654
+ }
4655
+ function isHttpsUrl(value) {
4656
+ if (typeof value !== "string") {
4657
+ return false;
4658
+ }
4659
+ try {
4660
+ return new URL(value).protocol === "https:";
4661
+ }
4662
+ catch (_a) {
4663
+ return false;
4664
+ }
4665
+ }
4666
+ function isValidProps(value) {
4667
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
4668
+ return false;
4669
+ }
4670
+ return Object.values(value).every((entry) => entry === null || ["string", "number", "boolean"].includes(typeof entry));
4671
+ }
4672
+ function parseMatcher(matcher) {
4673
+ if (typeof matcher !== "string") {
4674
+ return null;
4675
+ }
4676
+ const parts = matcher.match(/^\/([\s\S]*)\/([a-z]*)$/);
4677
+ if (!parts) {
4678
+ return null;
4679
+ }
4680
+ const flags = (parts[2] || "").replace(/[gy]/g, "");
4681
+ try {
4682
+ return new RegExp(parts[1], flags);
4683
+ }
4684
+ catch (_a) {
4685
+ return null;
4686
+ }
4687
+ }
4688
+ function parseRoomIntegration(response) {
4689
+ const { roomIntegrationId, name, title, description, type, icons, link, entrypoint, webview, isEmbeddable } = response || {};
4690
+ const matcher = parseMatcher(response === null || response === void 0 ? void 0 : response.matcher);
4691
+ if (roomIntegrationId === undefined ||
4692
+ roomIntegrationId === null ||
4693
+ !name ||
4694
+ !title ||
4695
+ !type ||
4696
+ !(icons === null || icons === void 0 ? void 0 : icons.small) ||
4697
+ !(icons === null || icons === void 0 ? void 0 : icons.large) ||
4698
+ !entrypoint ||
4699
+ !webview ||
4700
+ !matcher) {
4701
+ console.warn(`Ignoring malformed room integration: ${name || roomIntegrationId}`);
4702
+ return null;
4703
+ }
4704
+ return {
4705
+ roomIntegrationId: String(roomIntegrationId),
4706
+ name,
4707
+ title,
4708
+ description: description || "",
4709
+ type,
4710
+ contentTagName: roomIntegrationContentTagName(name),
4711
+ icons: { small: icons.small, large: icons.large },
4712
+ link: { href: (link === null || link === void 0 ? void 0 : link.href) || "", text: (link === null || link === void 0 ? void 0 : link.text) || "" },
4713
+ entrypoint,
4714
+ webview,
4715
+ matcher,
4716
+ isEmbeddable: isEmbeddable !== null && isEmbeddable !== void 0 ? isEmbeddable : false,
4717
+ };
4718
+ }
4719
+ function parseRoomIntegrationSession(event) {
4720
+ const { roomIntegrationId, roomIntegrationSessionId, breakoutGroupId, tagName, shareUrl, props, clientId, roomIntegrationSessionStartedAt, } = event || {};
4721
+ if (typeof roomIntegrationSessionId !== "string" ||
4722
+ roomIntegrationId === undefined ||
4723
+ roomIntegrationId === null ||
4724
+ typeof clientId !== "string" ||
4725
+ !isCustomElementName(tagName) ||
4726
+ !isHttpsUrl(shareUrl) ||
4727
+ !isValidProps(props)) {
4728
+ console.warn(`Ignoring malformed room integration session: ${roomIntegrationSessionId}`);
4729
+ return null;
4730
+ }
4731
+ return {
4732
+ roomIntegrationSessionId,
4733
+ roomIntegrationId: String(roomIntegrationId),
4734
+ breakoutGroupId: breakoutGroupId || "",
4735
+ tagName,
4736
+ shareUrl,
4737
+ props,
4738
+ clientId,
4739
+ roomIntegrationSessionStartedAt: typeof roomIntegrationSessionStartedAt === "number" && isFinite(roomIntegrationSessionStartedAt)
4740
+ ? roomIntegrationSessionStartedAt
4741
+ : null,
4742
+ };
4743
+ }
4744
+ const SIGNAL_ERROR_MESSAGES = {
4745
+ not_in_a_room: (action) => `Cannot ${action} a room integration: not in a room. The signal connection has a room session, but the server does not consider this client a participant of it.`,
4746
+ forbidden: (action) => `Not allowed to ${action} this room integration (forbidden)`,
4747
+ missing_parameters: (action) => `Could not ${action} the room integration: the request was missing parameters`,
4748
+ invalid_parameters: (action) => `Could not ${action} the room integration: the request had invalid parameters`,
4749
+ internal_server_error: (action) => `The server failed to ${action} the room integration`,
4750
+ };
4751
+ function roomIntegrationSignalError(error, action) {
4752
+ if (!isRoomIntegrationErrorCode(error)) {
4753
+ return { code: "unknown", message: `Could not ${action} the room integration: ${error}` };
4754
+ }
4755
+ return { code: error, message: SIGNAL_ERROR_MESSAGES[error](action) };
4756
+ }
4757
+ const roomIntegrationsSliceInitialState = {
4758
+ available: [],
4759
+ unavailable: [],
4760
+ enabled: [],
4761
+ running: [],
4762
+ isFetching: false,
4763
+ hasFetched: false,
4764
+ error: null,
4765
+ };
4766
+ const roomIntegrationsSlice = createSlice({
4767
+ name: "roomIntegrations",
4768
+ initialState: roomIntegrationsSliceInitialState,
4769
+ reducers: {
4770
+ setRoomIntegrationsError: (state, action) => {
4771
+ state.error = action.payload.error;
4772
+ },
4773
+ },
4774
+ extraReducers: (builder) => {
4775
+ builder.addCase(doFetchRoomIntegrations.pending, (state) => {
4776
+ state.isFetching = true;
4777
+ });
4778
+ builder.addCase(doFetchRoomIntegrations.fulfilled, (state, action) => {
4779
+ const { enabledRoomIntegrations, disabledRoomIntegrations, unavailableRoomIntegrations } = action.payload;
4780
+ const parse = (entries) => entries.map(parseRoomIntegration).filter((entry) => entry !== null);
4781
+ state.isFetching = false;
4782
+ state.hasFetched = true;
4783
+ state.error = null;
4784
+ state.available = [...parse(enabledRoomIntegrations), ...parse(disabledRoomIntegrations)];
4785
+ state.unavailable = parse(unavailableRoomIntegrations);
4786
+ state.enabled = enabledRoomIntegrations.map(({ roomIntegrationId }) => String(roomIntegrationId));
4787
+ });
4788
+ builder.addCase(doFetchRoomIntegrations.rejected, (state, action) => {
4789
+ state.isFetching = false;
4790
+ state.hasFetched = true;
4791
+ state.error = {
4792
+ code: "unknown",
4793
+ message: action.error.message || "Failed to fetch room integrations",
4794
+ };
4795
+ });
4796
+ builder.addCase(signalEvents.roomJoined, (state, action) => {
4797
+ if ("error" in action.payload) {
4798
+ return;
4799
+ }
4800
+ state.running = (action.payload.roomIntegrationSession || [])
4801
+ .map(parseRoomIntegrationSession)
4802
+ .filter((session) => session !== null);
4803
+ });
4804
+ builder.addCase(signalEvents.roomIntegrationStarted, (state, action) => {
4805
+ if ("error" in action.payload) {
4806
+ state.error = roomIntegrationSignalError(action.payload.error, "start");
4807
+ return;
4808
+ }
4809
+ const { roomIntegrationId, roomIntegrationSessionId, breakoutGroupId, roomIntegrationSessionStartedAt } = action.payload;
4810
+ const session = parseRoomIntegrationSession(Object.assign(Object.assign({}, action.payload.state), { roomIntegrationId,
4811
+ roomIntegrationSessionId,
4812
+ breakoutGroupId,
4813
+ roomIntegrationSessionStartedAt }));
4814
+ if (!session) {
4815
+ return;
4816
+ }
4817
+ const existing = state.running.findIndex((running) => running.roomIntegrationSessionId === session.roomIntegrationSessionId);
4818
+ if (existing >= 0) {
4819
+ state.running[existing] = session;
4820
+ return;
4821
+ }
4822
+ state.running.push(session);
4823
+ });
4824
+ builder.addCase(signalEvents.roomIntegrationStopped, (state, action) => {
4825
+ if ("error" in action.payload) {
4826
+ state.error = roomIntegrationSignalError(action.payload.error, "stop");
4827
+ return;
4828
+ }
4829
+ const { roomIntegrationSessionId } = action.payload;
4830
+ state.running = state.running.filter((running) => running.roomIntegrationSessionId !== roomIntegrationSessionId);
4831
+ });
4832
+ builder.addCase(signalEvents.roomIntegrationPropsUpdated, (state, action) => {
4833
+ if ("error" in action.payload) {
4834
+ state.error = roomIntegrationSignalError(action.payload.error, "update the props of");
4835
+ return;
4836
+ }
4837
+ const { roomIntegrationSessionId, props } = action.payload;
4838
+ const session = state.running.find((running) => running.roomIntegrationSessionId === roomIntegrationSessionId);
4839
+ if (!session || !isValidProps(props)) {
4840
+ return;
4841
+ }
4842
+ session.props = Object.assign(Object.assign({}, session.props), props);
4843
+ });
4844
+ builder.addCase(signalEvents.roomIntegrationEnabled, (state, action) => {
4845
+ const roomIntegrationId = String(action.payload.roomIntegrationId);
4846
+ if (!state.enabled.includes(roomIntegrationId)) {
4847
+ state.enabled.push(roomIntegrationId);
4848
+ }
4849
+ });
4850
+ builder.addCase(signalEvents.roomIntegrationDisabled, (state, action) => {
4851
+ const roomIntegrationId = String(action.payload.roomIntegrationId);
4852
+ state.enabled = state.enabled.filter((id) => id !== roomIntegrationId);
4853
+ });
4854
+ },
4855
+ });
4856
+ const { setRoomIntegrationsError } = roomIntegrationsSlice.actions;
4857
+ const doFetchRoomIntegrations = createAppAsyncThunk("roomIntegrations/doFetchRoomIntegrations", (_1, _a) => __awaiter(void 0, [_1, _a], void 0, function* (_, { extra, getState }) {
4858
+ const state = getState();
4859
+ const organizationId = selectOrganizationId(state);
4860
+ const roomName = selectAppRoomName(state);
4861
+ if (!organizationId || !roomName) {
4862
+ throw new Error("Cannot fetch room integrations before the organization and room are known");
4863
+ }
4864
+ return extra.services.roomIntegrationService.findRoomIntegrations({ organizationId, roomName });
4865
+ }));
4866
+ const doStartRoomIntegration = createRoomConnectedThunk((payload) => (dispatch, getState) => {
4867
+ var _a;
4868
+ const state = getState();
4869
+ const { roomIntegrationId, tagName, shareUrl, props = {} } = payload;
4870
+ const integration = selectRoomIntegrationsRaw(state).available.find((entry) => entry.roomIntegrationId === roomIntegrationId);
4871
+ if (!integration) {
4872
+ dispatch(setRoomIntegrationsError({
4873
+ error: {
4874
+ code: "unknown_integration",
4875
+ message: `Unknown room integration: ${roomIntegrationId}`,
4876
+ },
4877
+ }));
4878
+ return;
4879
+ }
4880
+ if (!selectRoomIntegrationsEnabled(state).includes(roomIntegrationId)) {
4881
+ dispatch(setRoomIntegrationsError({
4882
+ error: {
4883
+ code: "integration_not_enabled",
4884
+ message: `Room integration is not enabled for this room: ${integration.name}`,
4885
+ },
4886
+ }));
4887
+ return;
4888
+ }
4889
+ if (!isCustomElementName(tagName)) {
4890
+ dispatch(setRoomIntegrationsError({
4891
+ error: {
4892
+ code: "invalid_content",
4893
+ message: `tagName must be a valid custom element name, got: ${tagName}`,
4894
+ },
4895
+ }));
4896
+ return;
4897
+ }
4898
+ if (!isHttpsUrl(shareUrl)) {
4899
+ dispatch(setRoomIntegrationsError({
4900
+ error: {
4901
+ code: "invalid_content",
4902
+ message: `shareUrl must be an https url, got: ${shareUrl}`,
4903
+ },
4904
+ }));
4905
+ return;
4906
+ }
4907
+ if (!isValidProps(props)) {
4908
+ dispatch(setRoomIntegrationsError({
4909
+ error: {
4910
+ code: "invalid_content",
4911
+ message: "props must be a flat object of primitive values",
4912
+ },
4913
+ }));
4914
+ return;
4915
+ }
4916
+ const clientId = selectSelfId(state);
4917
+ if (!clientId) {
4918
+ return;
4919
+ }
4920
+ dispatch(setRoomIntegrationsError({ error: null }));
4921
+ const request = {
4922
+ roomIntegrationId: Number(roomIntegrationId),
4923
+ breakoutGroupId: selectBreakoutCurrentId(state) || null,
4924
+ state: { tagName, shareUrl, props, clientId },
4925
+ };
4926
+ (_a = selectSignalConnectionRaw(state).socket) === null || _a === void 0 ? void 0 : _a.emit("start_room_integration", request);
4927
+ });
4928
+ const ROOM_INTEGRATION_PICKER_MESSAGES = {
4929
+ FORM_SUBMIT: "whereby:formSubmit",
4930
+ FORM_CLOSE: "whereby:formClose",
4931
+ ERROR: "whereby:bootstrapError",
4932
+ };
4933
+ function roomIntegrationPickerUrl({ integration, parentOrigin, featureSource, }) {
4934
+ const url = new URL("bootstrap.html", integration.webview);
4935
+ url.searchParams.set("parentOrigin", parentOrigin);
4936
+ if (featureSource) {
4937
+ url.searchParams.set("featuresource", featureSource);
4938
+ }
4939
+ return url.href;
4940
+ }
4941
+ const doStopRoomIntegration = createRoomConnectedThunk((payload) => (dispatch, getState) => {
4942
+ var _a;
4943
+ const state = getState();
4944
+ const { roomIntegrationSessionId, intent = "stop" } = payload;
4945
+ const session = selectRunningRoomIntegrations(state).find((running) => running.roomIntegrationSessionId === roomIntegrationSessionId);
4946
+ if (!session) {
4947
+ dispatch(setRoomIntegrationsError({
4948
+ error: {
4949
+ code: "unknown_integration",
4950
+ message: `No running room integration with session id: ${roomIntegrationSessionId}`,
4951
+ },
4952
+ }));
4953
+ return;
4954
+ }
4955
+ if (!session.canStop) {
4956
+ dispatch(setRoomIntegrationsError({
4957
+ error: {
4958
+ code: "not_allowed_to_stop",
4959
+ message: "Only the participant who started a room integration, or a host, can stop it",
4960
+ },
4961
+ }));
4962
+ return;
4963
+ }
4964
+ dispatch(setRoomIntegrationsError({ error: null }));
4965
+ (_a = selectSignalConnectionRaw(state).socket) === null || _a === void 0 ? void 0 : _a.emit("stop_room_integration", { roomIntegrationSessionId, intent });
4966
+ });
4967
+ const doUpdateRoomIntegrationProps = createRoomConnectedThunk((payload) => (dispatch, getState) => {
4968
+ var _a;
4969
+ const state = getState();
4970
+ const { roomIntegrationSessionId, props } = payload;
4971
+ if (!isValidProps(props)) {
4972
+ dispatch(setRoomIntegrationsError({
4973
+ error: {
4974
+ code: "invalid_content",
4975
+ message: "props must be a flat object of primitive values",
4976
+ },
4977
+ }));
4978
+ return;
4979
+ }
4980
+ (_a = selectSignalConnectionRaw(state).socket) === null || _a === void 0 ? void 0 : _a.emit("update_room_integration_props", {
4981
+ roomIntegrationSessionId,
4982
+ props,
4983
+ });
4984
+ });
4985
+ const selectRoomIntegrationsRaw = (state) => state.roomIntegrations;
4986
+ const selectRoomIntegrationsEnabled = (state) => state.roomIntegrations.enabled;
4987
+ const selectAvailableRoomIntegrations = (state) => state.roomIntegrations.available;
4988
+ const selectEnabledRoomIntegrations = createSelector(selectAvailableRoomIntegrations, selectRoomIntegrationsEnabled, (available, enabled) => available.filter((integration) => enabled.includes(integration.roomIntegrationId)));
4989
+ const selectEmbeddableRoomIntegrations = createSelector(selectEnabledRoomIntegrations, (enabled) => enabled.filter((integration) => integration.isEmbeddable));
4990
+ const selectRunningRoomIntegrations = createSelector(selectRoomIntegrationsRaw, selectEnabledRoomIntegrations, selectBreakoutActive, selectBreakoutCurrentId, selectSelfId, selectRemoteParticipants, selectIsAuthorizedToManageRoomIntegration, (raw, enabledIntegrations, breakoutActive, breakoutCurrentId, selfId, remoteParticipants, canManageRoomIntegration) => {
4991
+ const currentGroupId = breakoutActive ? breakoutCurrentId : "";
4992
+ return raw.running.reduce((acc, session) => {
4993
+ var _a;
4994
+ if (session.breakoutGroupId !== currentGroupId) {
4995
+ return acc;
4996
+ }
4997
+ const integration = enabledIntegrations.find((entry) => entry.roomIntegrationId === session.roomIntegrationId);
4998
+ if (!integration) {
4999
+ return acc;
5000
+ }
5001
+ const isPresenter = !!selfId && session.clientId === selfId;
5002
+ acc.push(Object.assign(Object.assign({}, session), { integration,
5003
+ isPresenter, canStop: isPresenter || canManageRoomIntegration, presenterDisplayName: isPresenter
5004
+ ? null
5005
+ : ((_a = remoteParticipants.find((participant) => participant.id === session.clientId)) === null || _a === void 0 ? void 0 : _a.displayName) ||
5006
+ null }));
5007
+ return acc;
5008
+ }, []);
5009
+ });
5010
+ createSelector(selectRunningRoomIntegrations, (running) => running.length > 0);
5011
+ createSelector(selectEmbeddableRoomIntegrations, (integrations) => (url) => integrations.find((integration) => integration.matcher.test(url)) || null);
5012
+ const selectShouldFetchRoomIntegrations = createSelector(selectAppIsActive, selectRoomConnectionStatus, selectOrganizationId, selectAppRoomName, selectRoomIntegrationsRaw, (appIsActive, connectionStatus, organizationId, roomName, raw) => appIsActive &&
5013
+ connectionStatus === "connected" &&
5014
+ !!organizationId &&
5015
+ !!roomName &&
5016
+ !raw.hasFetched &&
5017
+ !raw.isFetching);
5018
+ createReactor([selectShouldFetchRoomIntegrations], ({ dispatch }, shouldFetchRoomIntegrations) => {
5019
+ if (shouldFetchRoomIntegrations) {
5020
+ dispatch(doFetchRoomIntegrations());
5021
+ }
5022
+ });
5023
+
4556
5024
  function createRtcAnalyticsCustomEvent(parameters) {
4557
5025
  return parameters;
4558
5026
  }
@@ -5164,6 +5632,7 @@ const appReducer = combineReducers({
5164
5632
  remoteParticipants: remoteParticipantsSlice.reducer,
5165
5633
  room: roomSlice.reducer,
5166
5634
  roomConnection: roomConnectionSlice.reducer,
5635
+ roomIntegrations: roomIntegrationsSlice.reducer,
5167
5636
  rtcAnalytics: rtcAnalyticsSlice.reducer,
5168
5637
  rtcConnection: rtcConnectionSlice.reducer,
5169
5638
  signalConnection: signalConnectionSlice.reducer,
@@ -5201,12 +5670,14 @@ const createStore = ({ preloadedState, injectServices, }) => {
5201
5670
  const CLIENT_VIEW_CHANGED = "grid:client-view-changed";
5202
5671
  const CLIENT_VIEW_SPOTLIGHTS_CHANGED = "grid:client-view-spotlights-changed";
5203
5672
  const NUMBER_OF_CLIENT_VIEWS_CHANGED = "grid:number-of-client-views-changed";
5673
+ const RUNNING_ROOM_INTEGRATIONS_CHANGED = "grid:running-room-integrations-changed";
5204
5674
 
5205
- const selectGridState = createSelector(selectAllClientViews, selectSpotlightedClientViews, selectNumClients, (allClientViews, spotlightedParticipants, numClients) => {
5675
+ const selectGridState = createSelector(selectAllClientViews, selectSpotlightedClientViews, selectNumClients, selectRunningRoomIntegrations, (allClientViews, spotlightedParticipants, numClients, runningRoomIntegrations) => {
5206
5676
  return {
5207
5677
  allClientViews,
5208
5678
  spotlightedParticipants,
5209
5679
  numParticipants: numClients,
5680
+ runningRoomIntegrations,
5210
5681
  };
5211
5682
  });
5212
5683
 
@@ -5245,6 +5716,7 @@ class GridClient extends BaseClient {
5245
5716
  this.clientViewSubscribers = new Set();
5246
5717
  this.spotlightedSubscribers = new Set();
5247
5718
  this.numberOfClientViewsSubscribers = new Set();
5719
+ this.runningRoomIntegrationsSubscribers = new Set();
5248
5720
  }
5249
5721
  handleStateChanges(state, previousState) {
5250
5722
  if (state.allClientViews !== previousState.allClientViews) {
@@ -5259,6 +5731,10 @@ class GridClient extends BaseClient {
5259
5731
  this.numberOfClientViewsSubscribers.forEach((cb) => cb(state.numParticipants));
5260
5732
  this.emit(NUMBER_OF_CLIENT_VIEWS_CHANGED, state.numParticipants);
5261
5733
  }
5734
+ if (state.runningRoomIntegrations !== previousState.runningRoomIntegrations) {
5735
+ this.runningRoomIntegrationsSubscribers.forEach((cb) => cb(state.runningRoomIntegrations));
5736
+ this.emit(RUNNING_ROOM_INTEGRATIONS_CHANGED, state.runningRoomIntegrations);
5737
+ }
5262
5738
  }
5263
5739
  getState() {
5264
5740
  return selectGridState(this.store.getState());
@@ -5275,6 +5751,10 @@ class GridClient extends BaseClient {
5275
5751
  this.numberOfClientViewsSubscribers.add(callback);
5276
5752
  return () => this.numberOfClientViewsSubscribers.delete(callback);
5277
5753
  }
5754
+ subscribeRunningRoomIntegrations(callback) {
5755
+ this.runningRoomIntegrationsSubscribers.add(callback);
5756
+ return () => this.runningRoomIntegrationsSubscribers.delete(callback);
5757
+ }
5278
5758
  spotlightParticipant(id) {
5279
5759
  this.store.dispatch(doSpotlightParticipant({ id }));
5280
5760
  }
@@ -5286,6 +5766,7 @@ class GridClient extends BaseClient {
5286
5766
  this.clientViewSubscribers.clear();
5287
5767
  this.spotlightedSubscribers.clear();
5288
5768
  this.numberOfClientViewsSubscribers.clear();
5769
+ this.runningRoomIntegrationsSubscribers.clear();
5289
5770
  this.removeAllListeners();
5290
5771
  }
5291
5772
  }
@@ -5549,7 +6030,7 @@ const SPOTLIGHT_PARTICIPANT_REMOVED = "spotlight:participant-removed";
5549
6030
  const ROOM_JOINED = "room:joined";
5550
6031
  const ROOM_JOINED_ERROR = "room:joined:error";
5551
6032
 
5552
- const selectRoomConnectionState = createSelector(selectChatMessages, selectFileUploads, selectCloudRecordingRaw, selectBreakoutCurrentGroup, selectBreakoutCurrentId, selectBreakoutActive, selectBreakoutGroupedParticipants, selectBreakoutGroups, selectBreakoutAssignments, selectBreakoutEnforceAssignment, selectBreakoutTimerSetting, selectBreakoutTimerDuration, selectBreakoutAutoMoveToGroup, selectBreakoutMoveToGroupGracePeriod, selectBreakoutAutoMoveToMain, selectBreakoutMoveToMainGracePeriod, selectBreakoutStartedAt, selectBreakoutEndTime, selectBreakoutMoveToGroupAt, selectBreakoutMoveToMainAt, selectBreakoutIsAvailable, selectBreakoutError, selectAllClientViewsInCurrentGroup, selectLiveCaptionsRaw, selectLiveTranscriptionRaw, selectLocalParticipantRaw, selectLocalMediaStream, selectLocalScreenshareRaw, selectRemoteParticipants, selectScreenshares, selectRoomConnectionStatus, selectRoomConnectionError, selectRoomConnectionKnockResponse, selectStreamingRaw, selectWaitingParticipants, selectNotificationsEmitter, selectSpotlightedClientViews, selectIsCameraEnabled, selectIsMicrophoneEnabled, (chatMessages, fileUploads, cloudRecording, breakoutCurrentGroup, breakoutCurrentId, breakoutActive, breakoutGroupedParticipants, breakoutGroups, breakoutAssignments, breakoutEnforceAssignment, breakoutTimerSetting, breakoutTimerDuration, breakoutAutoMoveToGroup, breakoutMoveToGroupGracePeriod, breakoutAutoMoveToMain, breakoutMoveToMainGracePeriod, breakoutStartedAt, breakoutEndTime, breakoutMoveToGroupAt, breakoutMoveToMainAt, breakoutIsAvailable, breakoutError, clientViewsInCurrentGroup, liveCaptions, liveTranscription, localParticipant, localMediaStream, localScreenshare, remoteParticipants, screenshares, connectionStatus, connectionError, knockResponse, streaming, waitingParticipants, notificationsEmitter, spotlightedClientViews, isCameraEnabled, isMicrophoneEnabled) => {
6033
+ const selectRoomConnectionState = createSelector(selectChatMessages, selectFileUploads, selectCloudRecordingRaw, selectBreakoutCurrentGroup, selectBreakoutCurrentId, selectBreakoutActive, selectBreakoutGroupedParticipants, selectBreakoutGroups, selectBreakoutAssignments, selectBreakoutEnforceAssignment, selectBreakoutTimerSetting, selectBreakoutTimerDuration, selectBreakoutAutoMoveToGroup, selectBreakoutMoveToGroupGracePeriod, selectBreakoutAutoMoveToMain, selectBreakoutMoveToMainGracePeriod, selectBreakoutStartedAt, selectBreakoutEndTime, selectBreakoutMoveToGroupAt, selectBreakoutMoveToMainAt, selectBreakoutIsAvailable, selectBreakoutError, selectAllClientViewsInCurrentGroup, selectLiveCaptionsRaw, selectLiveTranscriptionRaw, selectLocalParticipantRaw, selectLocalMediaStream, selectLocalScreenshareRaw, selectRemoteParticipants, selectScreenshares, selectRoomConnectionStatus, selectRoomConnectionError, selectRoomConnectionKnockResponse, selectStreamingRaw, selectWaitingParticipants, selectNotificationsEmitter, selectSpotlightedClientViews, selectIsCameraEnabled, selectIsMicrophoneEnabled, selectRoomIntegrationsRaw, selectEnabledRoomIntegrations, selectEmbeddableRoomIntegrations, selectRunningRoomIntegrations, (chatMessages, fileUploads, cloudRecording, breakoutCurrentGroup, breakoutCurrentId, breakoutActive, breakoutGroupedParticipants, breakoutGroups, breakoutAssignments, breakoutEnforceAssignment, breakoutTimerSetting, breakoutTimerDuration, breakoutAutoMoveToGroup, breakoutMoveToGroupGracePeriod, breakoutAutoMoveToMain, breakoutMoveToMainGracePeriod, breakoutStartedAt, breakoutEndTime, breakoutMoveToGroupAt, breakoutMoveToMainAt, breakoutIsAvailable, breakoutError, clientViewsInCurrentGroup, liveCaptions, liveTranscription, localParticipant, localMediaStream, localScreenshare, remoteParticipants, screenshares, connectionStatus, connectionError, knockResponse, streaming, waitingParticipants, notificationsEmitter, spotlightedClientViews, isCameraEnabled, isMicrophoneEnabled, roomIntegrationsRaw, enabledRoomIntegrations, embeddableRoomIntegrations, runningRoomIntegrations) => {
5553
6034
  const broadcastingParticipants = breakoutActive && breakoutCurrentId
5554
6035
  ? spotlightedClientViews.filter((c) => !c.breakoutGroup && c.isAudioEnabled && !c.isPresentation)
5555
6036
  : [];
@@ -5627,6 +6108,14 @@ const selectRoomConnectionState = createSelector(selectChatMessages, selectFileU
5627
6108
  : undefined,
5628
6109
  localParticipant: Object.assign(Object.assign({}, localParticipant), { isScreenSharing: localScreenshare.status === "active", stream: localMediaStream }),
5629
6110
  remoteParticipants: remoteParticipants.map((participant) => (Object.assign(Object.assign({}, participant), { breakoutGroupAssigned: (breakoutAssignments === null || breakoutAssignments === void 0 ? void 0 : breakoutAssignments[participant.deviceId]) || "" }))),
6111
+ roomIntegrations: {
6112
+ hasFetched: roomIntegrationsRaw.hasFetched,
6113
+ isFetching: roomIntegrationsRaw.isFetching,
6114
+ error: roomIntegrationsRaw.error,
6115
+ embeddable: embeddableRoomIntegrations,
6116
+ enabled: enabledRoomIntegrations,
6117
+ running: runningRoomIntegrations,
6118
+ },
5630
6119
  screenshares,
5631
6120
  waitingParticipants,
5632
6121
  spotlightedParticipants: spotlightedClientViews,
@@ -6011,6 +6500,15 @@ class RoomConnectionClient extends BaseClient {
6011
6500
  endMeeting(stayBehind = false) {
6012
6501
  this.store.dispatch(doEndMeeting({ stayBehind }));
6013
6502
  }
6503
+ startRoomIntegration(options) {
6504
+ this.store.dispatch(doStartRoomIntegration(options));
6505
+ }
6506
+ stopRoomIntegration(options) {
6507
+ this.store.dispatch(doStopRoomIntegration(options));
6508
+ }
6509
+ updateRoomIntegrationProps(options) {
6510
+ this.store.dispatch(doUpdateRoomIntegrationProps(options));
6511
+ }
6014
6512
  joinBreakoutGroup(group) {
6015
6513
  this.store.dispatch(doBreakoutJoin({ group }));
6016
6514
  }
@@ -6162,4 +6660,4 @@ class WherebyClient {
6162
6660
  }
6163
6661
  }
6164
6662
 
6165
- export { ACCEPTED_FILE_TYPES, ApiClient, BREAKOUT_CONFIG_CHANGED, BREAKOUT_GROUPS_MIN_MAX, BREAKOUT_UNAVAILABLE_ERROR, CAMERA_DEVICES_CHANGED, CAMERA_DEVICE_ERROR_CHANGED, CAMERA_ENABLED_CHANGED, CAMERA_STATE_CHANGED, CHAT_NEW_MESSAGE, CLIENT_VIEW_CHANGED, CLIENT_VIEW_SPOTLIGHTS_CHANGED, CLOUD_RECORDING_STATUS_CHANGED, CONNECTION_ERROR_CHANGED, CONNECTION_STATUS_CHANGED, CURRENT_CAMERA_CHANGED, CURRENT_MICROPHONE_CHANGED, CURRENT_SPEAKER_CHANGED, Credentials, CredentialsService, DEFAULT_BREAKOUT_TIMER_DURATION, GridClient, IS_SETTING_CAMERA_DEVICE, IS_SETTING_MICROPHONE_DEVICE, LIVE_CAPTIONS_STATUS_CHANGED, LIVE_TRANSCRIPTION_STATUS_CHANGED, LOCAL_MEDIA_STARTING, LOCAL_MEDIA_START_ERROR_CHANGED, LOCAL_PARTICIPANT_CHANGED, LOCAL_SCREENSHARE_CHANGED, LOCAL_SCREENSHARE_STATUS_CHANGED, LOCAL_STREAM_CHANGED, LiveCaption, LocalMediaClient, LocalParticipant, MAX_FILES_PER_UPLOAD, MAX_FILE_SIZE, MICROPHONE_DEVICES_CHANGED, MICROPHONE_DEVICE_ERROR_CHANGED, MICROPHONE_ENABLED_CHANGED, MICROPHONE_STATE_CHANGED, NUMBER_OF_CLIENT_VIEWS_CHANGED, Organization, OrganizationApiClient, OrganizationService, OrganizationServiceCache, REMOTE_PARTICIPANTS_CHANGED, ROOM_JOINED, ROOM_JOINED_ERROR, RoomConnectionClient, RoomService, SCREENSHARE_STARTED, SCREENSHARE_STOPPED, SPEAKER_DEVICES_CHANGED, SPOTLIGHT_PARTICIPANT_ADDED, SPOTLIGHT_PARTICIPANT_REMOVED, STREAMING_STARTED, STREAMING_STOPPED, WAITING_PARTICIPANT_JOINED, WAITING_PARTICIPANT_LEFT, WherebyClient, createBreakoutGroups, createServices, debounce, defaultBreakoutGroupName, getAudioTrack, getFakeMediaStream, getUsableCameraEffectPresets, getVideoTrack, hasValue, isAudioDenoiserSupported, parseUnverifiedRoomKeyData };
6663
+ export { ACCEPTED_FILE_TYPES, ApiClient, BREAKOUT_CONFIG_CHANGED, BREAKOUT_GROUPS_MIN_MAX, BREAKOUT_UNAVAILABLE_ERROR, CAMERA_DEVICES_CHANGED, CAMERA_DEVICE_ERROR_CHANGED, CAMERA_ENABLED_CHANGED, CAMERA_STATE_CHANGED, CHAT_NEW_MESSAGE, CLIENT_VIEW_CHANGED, CLIENT_VIEW_SPOTLIGHTS_CHANGED, CLOUD_RECORDING_STATUS_CHANGED, CONNECTION_ERROR_CHANGED, CONNECTION_STATUS_CHANGED, CURRENT_CAMERA_CHANGED, CURRENT_MICROPHONE_CHANGED, CURRENT_SPEAKER_CHANGED, Credentials, CredentialsService, DEFAULT_BREAKOUT_TIMER_DURATION, GridClient, IS_SETTING_CAMERA_DEVICE, IS_SETTING_MICROPHONE_DEVICE, LIVE_CAPTIONS_STATUS_CHANGED, LIVE_TRANSCRIPTION_STATUS_CHANGED, LOCAL_MEDIA_STARTING, LOCAL_MEDIA_START_ERROR_CHANGED, LOCAL_PARTICIPANT_CHANGED, LOCAL_SCREENSHARE_CHANGED, LOCAL_SCREENSHARE_STATUS_CHANGED, LOCAL_STREAM_CHANGED, LiveCaption, LocalMediaClient, LocalParticipant, MAX_FILES_PER_UPLOAD, MAX_FILE_SIZE, MICROPHONE_DEVICES_CHANGED, MICROPHONE_DEVICE_ERROR_CHANGED, MICROPHONE_ENABLED_CHANGED, MICROPHONE_STATE_CHANGED, NUMBER_OF_CLIENT_VIEWS_CHANGED, Organization, OrganizationApiClient, OrganizationService, OrganizationServiceCache, REMOTE_PARTICIPANTS_CHANGED, ROOM_INTEGRATION_PICKER_MESSAGES, ROOM_JOINED, ROOM_JOINED_ERROR, RUNNING_ROOM_INTEGRATIONS_CHANGED, RoomConnectionClient, RoomIntegrationService, RoomService, SCREENSHARE_STARTED, SCREENSHARE_STOPPED, SPEAKER_DEVICES_CHANGED, SPOTLIGHT_PARTICIPANT_ADDED, SPOTLIGHT_PARTICIPANT_REMOVED, STREAMING_STARTED, STREAMING_STOPPED, WAITING_PARTICIPANT_JOINED, WAITING_PARTICIPANT_LEFT, WherebyClient, createBreakoutGroups, createServices, debounce, defaultBreakoutGroupName, getAudioTrack, getFakeMediaStream, getUsableCameraEffectPresets, getVideoTrack, hasValue, isAudioDenoiserSupported, miro, parseUnverifiedRoomKeyData, roomIntegrationContent, roomIntegrationContentTagName, roomIntegrationPickerUrl, youtube };