@whereby.com/core 1.13.0 → 1.14.1

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,8 +1,9 @@
1
1
  import nodeBtoa from 'btoa';
2
- import { assert, fromLocation, ServerSocket, 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 } from '@whereby.com/media';
3
3
  import axios from 'axios';
4
4
  import { EventEmitter } from 'events';
5
- import { createListenerMiddleware, createSlice, createAction, createSelector, createAsyncThunk, isAnyOf, combineReducers, configureStore, addListener } from '@reduxjs/toolkit';
5
+ import { createListenerMiddleware, addListener, createSlice, createAction, createSelector, createAsyncThunk, isAnyOf, combineReducers, configureStore } from '@reduxjs/toolkit';
6
+ import { v4 } from 'uuid';
6
7
 
7
8
  class Response {
8
9
  constructor(initialValues = {}) {
@@ -1195,6 +1196,7 @@ function parseUnverifiedRoomKeyData(roomKey) {
1195
1196
 
1196
1197
  const listenerMiddleware = createListenerMiddleware();
1197
1198
  const startAppListening = listenerMiddleware.startListening;
1199
+ const addAppListener = addListener;
1198
1200
  const createReactor = (selectors, callback) => {
1199
1201
  return startAppListening({
1200
1202
  predicate: (_, currentState, previousState) => {
@@ -1213,7 +1215,7 @@ const createReactor = (selectors, callback) => {
1213
1215
  });
1214
1216
  };
1215
1217
 
1216
- const coreVersion = "1.13.0";
1218
+ const coreVersion = "1.14.1";
1217
1219
 
1218
1220
  const initialState$2 = {
1219
1221
  displayName: null,
@@ -1266,6 +1268,7 @@ const signalEvents = {
1266
1268
  breakoutSessionUpdated: createSignalEventAction("breakoutSessionUpdated"),
1267
1269
  chatMessage: createSignalEventAction("chatMessage"),
1268
1270
  chatMessageRemoved: createSignalEventAction("chatMessageRemoved"),
1271
+ fileSharingError: createSignalEventAction("fileSharingError"),
1269
1272
  clientLeft: createSignalEventAction("clientLeft"),
1270
1273
  clientKicked: createSignalEventAction("clientKicked"),
1271
1274
  clientMetadataReceived: createSignalEventAction("clientMetadataReceived"),
@@ -1446,7 +1449,13 @@ function forwardSocketEvents(socket, dispatch) {
1446
1449
  socket.on("video_enabled", (payload) => dispatch(signalEvents.videoEnabled(payload)));
1447
1450
  socket.on("audio_enable_requested", (payload) => dispatch(signalEvents.audioEnableRequested(payload)));
1448
1451
  socket.on("client_metadata_received", (payload) => dispatch(signalEvents.clientMetadataReceived(payload)));
1449
- socket.on("chat_message", (payload) => dispatch(signalEvents.chatMessage(payload)));
1452
+ socket.on("chat_message", (payload) => {
1453
+ if (isFileShareError(payload)) {
1454
+ dispatch(signalEvents.fileSharingError(payload));
1455
+ return;
1456
+ }
1457
+ dispatch(signalEvents.chatMessage(payload));
1458
+ });
1450
1459
  socket.on("chat_message_removed", (payload) => dispatch(signalEvents.chatMessageRemoved(payload)));
1451
1460
  socket.on("disconnect", () => dispatch(signalEvents.disconnect()));
1452
1461
  socket.on("room_knocked", (payload) => dispatch(signalEvents.roomKnocked(payload)));
@@ -2277,15 +2286,7 @@ const chatSlice = createSlice({
2277
2286
  reducers: {},
2278
2287
  extraReducers(builder) {
2279
2288
  builder.addCase(signalEvents.chatMessage, (state, action) => {
2280
- const message = {
2281
- id: action.payload.id,
2282
- senderId: action.payload.senderId,
2283
- parentId: action.payload.parentId,
2284
- timestamp: action.payload.timestamp,
2285
- text: action.payload.text,
2286
- sig: action.payload.sig,
2287
- removed: false,
2288
- };
2289
+ const message = Object.assign({ id: action.payload.id, senderId: action.payload.senderId, parentId: action.payload.parentId, timestamp: action.payload.timestamp, text: action.payload.text, sig: action.payload.sig, removed: false }, (action.payload.file && { file: action.payload.file }));
2289
2290
  return Object.assign(Object.assign({}, state), { chatMessages: [...state.chatMessages, message] });
2290
2291
  });
2291
2292
  builder.addCase(signalEvents.chatMessageRemoved, (state, action) => {
@@ -3384,6 +3385,175 @@ createReactor([selectShouldStopConnectionMonitor], ({ dispatch }, shouldStartCon
3384
3385
  }
3385
3386
  });
3386
3387
 
3388
+ const MAX_FILES_PER_UPLOAD = 10;
3389
+ const MAX_FILE_SIZE = 15 * 1024 * 1024;
3390
+ const ACCEPTED_FILE_TYPES = {
3391
+ "application/doc": [".doc", ".docx"],
3392
+ "application/msword": [".doc", ".docx"],
3393
+ "application/pdf": [".pdf"],
3394
+ "application/rtf": [".rtf"],
3395
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": [".xlsx"],
3396
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document": [".docx"],
3397
+ "audio/mpeg": [".mp3"],
3398
+ "audio/wav": [".wav"],
3399
+ "image/gif": [".gif"],
3400
+ "image/jpeg": [".jpeg", ".jpg"],
3401
+ "image/png": [".png"],
3402
+ "image/webp": [".webp"],
3403
+ "text/csv": [".csv"],
3404
+ "text/plain": [".txt"],
3405
+ "video/mp4": [".mp4"],
3406
+ "video/quicktime": [".mov"],
3407
+ "video/webm": [".webm"],
3408
+ "video/x-matroska": [".mkv"],
3409
+ };
3410
+ function isAcceptedFileType(file) {
3411
+ if (file.type && ACCEPTED_FILE_TYPES[file.type]) {
3412
+ return true;
3413
+ }
3414
+ const dot = file.name.lastIndexOf(".");
3415
+ if (dot < 0) {
3416
+ return false;
3417
+ }
3418
+ const extension = file.name.slice(dot).toLowerCase();
3419
+ return Object.values(ACCEPTED_FILE_TYPES).some((extensions) => extensions.includes(extension));
3420
+ }
3421
+ function validateFile(file) {
3422
+ if (!isAcceptedFileType(file)) {
3423
+ return "unsupported_file_type";
3424
+ }
3425
+ if (file.size > MAX_FILE_SIZE) {
3426
+ return "file_too_large";
3427
+ }
3428
+ return undefined;
3429
+ }
3430
+ const fileShareSliceInitialState = {
3431
+ uploads: [],
3432
+ requestInFlight: false,
3433
+ };
3434
+ const fileShareSlice = createSlice({
3435
+ name: "fileShare",
3436
+ initialState: fileShareSliceInitialState,
3437
+ reducers: {
3438
+ fileUploadsStarted: (state, action) => {
3439
+ state.uploads.push(...action.payload);
3440
+ state.requestInFlight = true;
3441
+ },
3442
+ fileShareRequestSettled: (state) => {
3443
+ state.requestInFlight = false;
3444
+ },
3445
+ fileUploadSucceeded: (state, action) => {
3446
+ const upload = state.uploads.find((u) => u.id === action.payload.id);
3447
+ if (upload) {
3448
+ upload.status = "sent";
3449
+ }
3450
+ },
3451
+ fileUploadFailed: (state, action) => {
3452
+ const upload = state.uploads.find((u) => u.id === action.payload.id);
3453
+ if (upload) {
3454
+ upload.status = "error";
3455
+ upload.error = action.payload.error;
3456
+ }
3457
+ },
3458
+ clearFileUploads: (state) => {
3459
+ state.uploads = [];
3460
+ },
3461
+ },
3462
+ });
3463
+ const { fileUploadsStarted, fileShareRequestSettled, fileUploadSucceeded, fileUploadFailed, clearFileUploads } = fileShareSlice.actions;
3464
+ function uploadFile(file, uploadUrl) {
3465
+ const form = new FormData();
3466
+ form.append("Content-Type", file.type);
3467
+ Object.entries(uploadUrl.fields).forEach(([key, value]) => form.append(key, value));
3468
+ form.append("file", file);
3469
+ return fetch(uploadUrl.url, { method: "POST", body: form });
3470
+ }
3471
+ const doSendFiles = createAsyncRoomConnectedThunk("fileShare/sendFiles", (payload_1, _a) => __awaiter(void 0, [payload_1, _a], void 0, function* (payload, { dispatch, getState }) {
3472
+ const state = getState();
3473
+ if (state.fileShare.requestInFlight) {
3474
+ return Promise.reject(new Error("A file upload request is already in flight"));
3475
+ }
3476
+ const socket = selectSignalConnectionRaw(state).socket;
3477
+ if (!socket) {
3478
+ return Promise.reject(new Error("No signal connection"));
3479
+ }
3480
+ const breakoutCurrentId = selectBreakoutCurrentId(state);
3481
+ const { files } = payload;
3482
+ if (!files.length) {
3483
+ return;
3484
+ }
3485
+ const tooManyFiles = files.length > MAX_FILES_PER_UPLOAD;
3486
+ const entries = files.map((file) => {
3487
+ const error = tooManyFiles ? "too_many_files" : validateFile(file);
3488
+ const upload = Object.assign({ id: v4(), name: file.name, size: file.size, type: file.type, status: error ? "error" : "uploading" }, (error && { error }));
3489
+ return { file, upload };
3490
+ });
3491
+ dispatch(fileUploadsStarted(entries.map((entry) => entry.upload)));
3492
+ const accepted = entries.filter((entry) => entry.upload.status === "uploading");
3493
+ if (!accepted.length) {
3494
+ dispatch(fileShareRequestSettled());
3495
+ return;
3496
+ }
3497
+ const acceptedFiles = accepted.map((entry) => entry.file);
3498
+ const outcome = yield new Promise((resolve) => {
3499
+ let settled = false;
3500
+ const removeListener = dispatch(addAppListener({
3501
+ actionCreator: signalEvents.fileSharingError,
3502
+ effect: (action, listenerApi) => {
3503
+ if (settled)
3504
+ return;
3505
+ settled = true;
3506
+ listenerApi.unsubscribe();
3507
+ resolve({ error: action.payload.error });
3508
+ },
3509
+ }));
3510
+ socket.emit("request_file_upload_url", { files: acceptedFiles.map((f) => ({ name: f.name, size: f.size, type: f.type })) }, (urls) => {
3511
+ if (settled)
3512
+ return;
3513
+ settled = true;
3514
+ removeListener({ cancelActive: true });
3515
+ resolve({ urls });
3516
+ });
3517
+ });
3518
+ dispatch(fileShareRequestSettled());
3519
+ if ("error" in outcome) {
3520
+ accepted.forEach((entry) => dispatch(fileUploadFailed({ id: entry.upload.id, error: outcome.error })));
3521
+ return;
3522
+ }
3523
+ yield Promise.all(accepted.map((_a, index_1) => __awaiter(void 0, [_a, index_1], void 0, function* ({ file, upload }, index) {
3524
+ const urls = outcome.urls[index];
3525
+ if (!urls) {
3526
+ dispatch(fileUploadFailed({ id: upload.id, error: "upload_failed" }));
3527
+ return;
3528
+ }
3529
+ try {
3530
+ const response = yield uploadFile(file, urls.uploadUrl);
3531
+ if (!response.ok) {
3532
+ throw new Error(`S3 upload failed with status ${response.status}`);
3533
+ }
3534
+ socket.emit("chat_message", Object.assign({ text: "", file: {
3535
+ downloadUrl: urls.downloadUrl,
3536
+ name: file.name,
3537
+ size: file.size,
3538
+ type: file.type,
3539
+ key: urls.uploadUrl.fields.key,
3540
+ } }, (breakoutCurrentId && { breakoutGroup: breakoutCurrentId })));
3541
+ dispatch(fileUploadSucceeded({ id: upload.id }));
3542
+ }
3543
+ catch (_b) {
3544
+ dispatch(fileUploadFailed({ id: upload.id, error: "upload_failed" }));
3545
+ }
3546
+ })));
3547
+ }));
3548
+ const doDownloadFile = createAppAsyncThunk("fileShare/downloadFile", (payload) => __awaiter(void 0, void 0, void 0, function* () {
3549
+ const response = yield fetch(payload.file.downloadUrl, { mode: "cors", cache: "no-cache" });
3550
+ if (!response.ok) {
3551
+ throw new Error(`Failed to download file: ${response.status}`);
3552
+ }
3553
+ return response.blob();
3554
+ }));
3555
+ const selectFileUploads = (state) => state.fileShare.uploads;
3556
+
3387
3557
  const initialLiveTranscriptionState = {
3388
3558
  isInitiator: false,
3389
3559
  isTranscribing: false,
@@ -4502,6 +4672,7 @@ const appReducer = combineReducers({
4502
4672
  cloudRecording: cloudRecordingSlice.reducer,
4503
4673
  connectionMonitor: connectionMonitorSlice.reducer,
4504
4674
  deviceCredentials: deviceCredentialsSlice.reducer,
4675
+ fileShare: fileShareSlice.reducer,
4505
4676
  liveTranscription: liveTranscriptionSlice.reducer,
4506
4677
  localMedia: localMediaSlice.reducer,
4507
4678
  localParticipant: localParticipantSlice.reducer,
@@ -4870,9 +5041,10 @@ const SPOTLIGHT_PARTICIPANT_REMOVED = "spotlight:participant-removed";
4870
5041
  const ROOM_JOINED = "room:joined";
4871
5042
  const ROOM_JOINED_ERROR = "room:joined:error";
4872
5043
 
4873
- const selectRoomConnectionState = createSelector(selectChatMessages, selectCloudRecordingRaw, selectBreakoutCurrentGroup, selectBreakoutActive, selectBreakoutGroupedParticipants, selectAllClientViewsInCurrentGroup, selectLiveTranscriptionRaw, selectLocalParticipantRaw, selectLocalMediaStream, selectRemoteParticipants, selectScreenshares, selectRoomConnectionStatus, selectRoomConnectionError, selectStreamingRaw, selectWaitingParticipants, selectNotificationsEmitter, selectSpotlightedClientViews, selectIsCameraEnabled, selectIsMicrophoneEnabled, (chatMessages, cloudRecording, breakoutCurrentGroup, breakoutActive, breakoutGroupedParticipants, clientViewsInCurrentGroup, liveTranscription, localParticipant, localMediaStream, remoteParticipants, screenshares, connectionStatus, connectionError, streaming, waitingParticipants, notificationsEmitter, spotlightedClientViews, isCameraEnabled, isMicrophoneEnabled) => {
5044
+ const selectRoomConnectionState = createSelector(selectChatMessages, selectFileUploads, selectCloudRecordingRaw, selectBreakoutCurrentGroup, selectBreakoutActive, selectBreakoutGroupedParticipants, selectAllClientViewsInCurrentGroup, selectLiveTranscriptionRaw, selectLocalParticipantRaw, selectLocalMediaStream, selectRemoteParticipants, selectScreenshares, selectRoomConnectionStatus, selectRoomConnectionError, selectStreamingRaw, selectWaitingParticipants, selectNotificationsEmitter, selectSpotlightedClientViews, selectIsCameraEnabled, selectIsMicrophoneEnabled, (chatMessages, fileUploads, cloudRecording, breakoutCurrentGroup, breakoutActive, breakoutGroupedParticipants, clientViewsInCurrentGroup, liveTranscription, localParticipant, localMediaStream, remoteParticipants, screenshares, connectionStatus, connectionError, streaming, waitingParticipants, notificationsEmitter, spotlightedClientViews, isCameraEnabled, isMicrophoneEnabled) => {
4874
5045
  const state = {
4875
5046
  chatMessages,
5047
+ fileUploads,
4876
5048
  cloudRecording: cloudRecording.status
4877
5049
  ? {
4878
5050
  error: cloudRecording.error,
@@ -4921,6 +5093,7 @@ class RoomConnectionClient extends BaseClient {
4921
5093
  this.breakoutSubscribers = new Set();
4922
5094
  this.cameraStateSubscribers = new Set();
4923
5095
  this.chatMessageSubscribers = new Set();
5096
+ this.fileUploadsSubscribers = new Set();
4924
5097
  this.cloudRecordingSubscribers = new Set();
4925
5098
  this.connectionErrorSubscribers = new Set();
4926
5099
  this.connectionStatusSubscribers = new Set();
@@ -4941,6 +5114,9 @@ class RoomConnectionClient extends BaseClient {
4941
5114
  if (state.chatMessages !== previousState.chatMessages) {
4942
5115
  this.chatMessageSubscribers.forEach((cb) => cb(state.chatMessages));
4943
5116
  }
5117
+ if (state.fileUploads !== previousState.fileUploads) {
5118
+ this.fileUploadsSubscribers.forEach((cb) => cb(state.fileUploads));
5119
+ }
4944
5120
  if (state.cloudRecording !== previousState.cloudRecording) {
4945
5121
  this.cloudRecordingSubscribers.forEach((cb) => cb(state.cloudRecording));
4946
5122
  this.emit(CLOUD_RECORDING_STATUS_CHANGED, state.cloudRecording);
@@ -5051,6 +5227,10 @@ class RoomConnectionClient extends BaseClient {
5051
5227
  this.chatMessageSubscribers.add(callback);
5052
5228
  return () => this.chatMessageSubscribers.delete(callback);
5053
5229
  }
5230
+ subscribeToFileUploads(callback) {
5231
+ this.fileUploadsSubscribers.add(callback);
5232
+ return () => this.fileUploadsSubscribers.delete(callback);
5233
+ }
5054
5234
  subscribeToCloudRecording(callback) {
5055
5235
  this.cloudRecordingSubscribers.add(callback);
5056
5236
  return () => this.cloudRecordingSubscribers.delete(callback);
@@ -5161,6 +5341,12 @@ class RoomConnectionClient extends BaseClient {
5161
5341
  removeChatMessage(id, sig) {
5162
5342
  this.store.dispatch(doRemoveChatMessage({ id, sig }));
5163
5343
  }
5344
+ sendFiles(files) {
5345
+ this.store.dispatch(doSendFiles({ files }));
5346
+ }
5347
+ downloadFile(file) {
5348
+ return this.store.dispatch(doDownloadFile({ file })).unwrap();
5349
+ }
5164
5350
  knock() {
5165
5351
  this.store.dispatch(doKnockRoom());
5166
5352
  }
@@ -5318,6 +5504,7 @@ class RoomConnectionClient extends BaseClient {
5318
5504
  this.breakoutSubscribers.clear();
5319
5505
  this.cameraStateSubscribers.clear();
5320
5506
  this.chatMessageSubscribers.clear();
5507
+ this.fileUploadsSubscribers.clear();
5321
5508
  this.cloudRecordingSubscribers.clear();
5322
5509
  this.connectionErrorSubscribers.clear();
5323
5510
  this.connectionStatusSubscribers.clear();
@@ -5359,4 +5546,4 @@ class WherebyClient {
5359
5546
  }
5360
5547
  }
5361
5548
 
5362
- export { ApiClient, BREAKOUT_CONFIG_CHANGED, CAMERA_DEVICES_CHANGED, CAMERA_DEVICE_ERROR_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, GridClient, IS_SETTING_CAMERA_DEVICE, IS_SETTING_MICROPHONE_DEVICE, LIVE_TRANSCRIPTION_STATUS_CHANGED, LOCAL_MEDIA_STARTING, LOCAL_MEDIA_START_ERROR_CHANGED, LOCAL_PARTICIPANT_CHANGED, LOCAL_SCREENSHARE_STATUS_CHANGED, LOCAL_STREAM_CHANGED, LocalMediaClient, LocalParticipant, MICROPHONE_DEVICES_CHANGED, MICROPHONE_DEVICE_ERROR_CHANGED, MICROPHONE_STATE_CHANGED, NUMBER_OF_CLIENT_VIEWS_CHANGED, 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, createServices, debounce, getAudioTrack, getFakeMediaStream, getUsableCameraEffectPresets, getVideoTrack, hasValue, isAudioDenoiserSupported, parseUnverifiedRoomKeyData };
5549
+ export { ACCEPTED_FILE_TYPES, ApiClient, BREAKOUT_CONFIG_CHANGED, CAMERA_DEVICES_CHANGED, CAMERA_DEVICE_ERROR_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, GridClient, IS_SETTING_CAMERA_DEVICE, IS_SETTING_MICROPHONE_DEVICE, LIVE_TRANSCRIPTION_STATUS_CHANGED, LOCAL_MEDIA_STARTING, LOCAL_MEDIA_START_ERROR_CHANGED, LOCAL_PARTICIPANT_CHANGED, LOCAL_SCREENSHARE_STATUS_CHANGED, LOCAL_STREAM_CHANGED, LocalMediaClient, LocalParticipant, MAX_FILES_PER_UPLOAD, MAX_FILE_SIZE, MICROPHONE_DEVICES_CHANGED, MICROPHONE_DEVICE_ERROR_CHANGED, MICROPHONE_STATE_CHANGED, NUMBER_OF_CLIENT_VIEWS_CHANGED, 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, createServices, debounce, getAudioTrack, getFakeMediaStream, getUsableCameraEffectPresets, getVideoTrack, hasValue, isAudioDenoiserSupported, parseUnverifiedRoomKeyData };
@@ -2,6 +2,7 @@
2
2
 
3
3
  var toolkit = require('@reduxjs/toolkit');
4
4
  var media = require('@whereby.com/media');
5
+ var uuid = require('uuid');
5
6
  var events$1 = require('events');
6
7
  var nodeBtoa = require('btoa');
7
8
  var axios = require('axios');
@@ -75,7 +76,7 @@ const createReactor = (selectors, callback) => {
75
76
  });
76
77
  };
77
78
 
78
- const coreVersion = "1.13.0";
79
+ const coreVersion = "1.14.1";
79
80
 
80
81
  const initialState$2 = {
81
82
  displayName: null,
@@ -130,6 +131,7 @@ const signalEvents = {
130
131
  breakoutSessionUpdated: createSignalEventAction("breakoutSessionUpdated"),
131
132
  chatMessage: createSignalEventAction("chatMessage"),
132
133
  chatMessageRemoved: createSignalEventAction("chatMessageRemoved"),
134
+ fileSharingError: createSignalEventAction("fileSharingError"),
133
135
  clientLeft: createSignalEventAction("clientLeft"),
134
136
  clientKicked: createSignalEventAction("clientKicked"),
135
137
  clientMetadataReceived: createSignalEventAction("clientMetadataReceived"),
@@ -307,7 +309,13 @@ function forwardSocketEvents(socket, dispatch) {
307
309
  socket.on("video_enabled", (payload) => dispatch(signalEvents.videoEnabled(payload)));
308
310
  socket.on("audio_enable_requested", (payload) => dispatch(signalEvents.audioEnableRequested(payload)));
309
311
  socket.on("client_metadata_received", (payload) => dispatch(signalEvents.clientMetadataReceived(payload)));
310
- socket.on("chat_message", (payload) => dispatch(signalEvents.chatMessage(payload)));
312
+ socket.on("chat_message", (payload) => {
313
+ if (media.isFileShareError(payload)) {
314
+ dispatch(signalEvents.fileSharingError(payload));
315
+ return;
316
+ }
317
+ dispatch(signalEvents.chatMessage(payload));
318
+ });
311
319
  socket.on("chat_message_removed", (payload) => dispatch(signalEvents.chatMessageRemoved(payload)));
312
320
  socket.on("disconnect", () => dispatch(signalEvents.disconnect()));
313
321
  socket.on("room_knocked", (payload) => dispatch(signalEvents.roomKnocked(payload)));
@@ -1160,15 +1168,7 @@ const chatSlice = toolkit.createSlice({
1160
1168
  reducers: {},
1161
1169
  extraReducers(builder) {
1162
1170
  builder.addCase(signalEvents.chatMessage, (state, action) => {
1163
- const message = {
1164
- id: action.payload.id,
1165
- senderId: action.payload.senderId,
1166
- parentId: action.payload.parentId,
1167
- timestamp: action.payload.timestamp,
1168
- text: action.payload.text,
1169
- sig: action.payload.sig,
1170
- removed: false,
1171
- };
1171
+ const message = Object.assign({ id: action.payload.id, senderId: action.payload.senderId, parentId: action.payload.parentId, timestamp: action.payload.timestamp, text: action.payload.text, sig: action.payload.sig, removed: false }, (action.payload.file && { file: action.payload.file }));
1172
1172
  return Object.assign(Object.assign({}, state), { chatMessages: [...state.chatMessages, message] });
1173
1173
  });
1174
1174
  builder.addCase(signalEvents.chatMessageRemoved, (state, action) => {
@@ -2277,6 +2277,177 @@ createReactor([selectShouldStopConnectionMonitor], ({ dispatch }, shouldStartCon
2277
2277
  }
2278
2278
  });
2279
2279
 
2280
+ const MAX_FILES_PER_UPLOAD = 10;
2281
+ const MAX_FILE_SIZE = 15 * 1024 * 1024;
2282
+ const ACCEPTED_FILE_TYPES = {
2283
+ "application/doc": [".doc", ".docx"],
2284
+ "application/msword": [".doc", ".docx"],
2285
+ "application/pdf": [".pdf"],
2286
+ "application/rtf": [".rtf"],
2287
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": [".xlsx"],
2288
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document": [".docx"],
2289
+ "audio/mpeg": [".mp3"],
2290
+ "audio/wav": [".wav"],
2291
+ "image/gif": [".gif"],
2292
+ "image/jpeg": [".jpeg", ".jpg"],
2293
+ "image/png": [".png"],
2294
+ "image/webp": [".webp"],
2295
+ "text/csv": [".csv"],
2296
+ "text/plain": [".txt"],
2297
+ "video/mp4": [".mp4"],
2298
+ "video/quicktime": [".mov"],
2299
+ "video/webm": [".webm"],
2300
+ "video/x-matroska": [".mkv"],
2301
+ };
2302
+ function isAcceptedFileType(file) {
2303
+ if (file.type && ACCEPTED_FILE_TYPES[file.type]) {
2304
+ return true;
2305
+ }
2306
+ const dot = file.name.lastIndexOf(".");
2307
+ if (dot < 0) {
2308
+ return false;
2309
+ }
2310
+ const extension = file.name.slice(dot).toLowerCase();
2311
+ return Object.values(ACCEPTED_FILE_TYPES).some((extensions) => extensions.includes(extension));
2312
+ }
2313
+ function validateFile(file) {
2314
+ if (!isAcceptedFileType(file)) {
2315
+ return "unsupported_file_type";
2316
+ }
2317
+ if (file.size > MAX_FILE_SIZE) {
2318
+ return "file_too_large";
2319
+ }
2320
+ return undefined;
2321
+ }
2322
+ const fileShareSliceInitialState = {
2323
+ uploads: [],
2324
+ requestInFlight: false,
2325
+ };
2326
+ const fileShareSlice = toolkit.createSlice({
2327
+ name: "fileShare",
2328
+ initialState: fileShareSliceInitialState,
2329
+ reducers: {
2330
+ fileUploadsStarted: (state, action) => {
2331
+ state.uploads.push(...action.payload);
2332
+ state.requestInFlight = true;
2333
+ },
2334
+ fileShareRequestSettled: (state) => {
2335
+ state.requestInFlight = false;
2336
+ },
2337
+ fileUploadSucceeded: (state, action) => {
2338
+ const upload = state.uploads.find((u) => u.id === action.payload.id);
2339
+ if (upload) {
2340
+ upload.status = "sent";
2341
+ }
2342
+ },
2343
+ fileUploadFailed: (state, action) => {
2344
+ const upload = state.uploads.find((u) => u.id === action.payload.id);
2345
+ if (upload) {
2346
+ upload.status = "error";
2347
+ upload.error = action.payload.error;
2348
+ }
2349
+ },
2350
+ clearFileUploads: (state) => {
2351
+ state.uploads = [];
2352
+ },
2353
+ },
2354
+ });
2355
+ const { fileUploadsStarted, fileShareRequestSettled, fileUploadSucceeded, fileUploadFailed, clearFileUploads } = fileShareSlice.actions;
2356
+ function uploadFile(file, uploadUrl) {
2357
+ const form = new FormData();
2358
+ form.append("Content-Type", file.type);
2359
+ Object.entries(uploadUrl.fields).forEach(([key, value]) => form.append(key, value));
2360
+ form.append("file", file);
2361
+ return fetch(uploadUrl.url, { method: "POST", body: form });
2362
+ }
2363
+ const doSendFiles = createAsyncRoomConnectedThunk("fileShare/sendFiles", (payload_1, _a) => __awaiter(void 0, [payload_1, _a], void 0, function* (payload, { dispatch, getState }) {
2364
+ const state = getState();
2365
+ if (state.fileShare.requestInFlight) {
2366
+ return Promise.reject(new Error("A file upload request is already in flight"));
2367
+ }
2368
+ const socket = selectSignalConnectionRaw(state).socket;
2369
+ if (!socket) {
2370
+ return Promise.reject(new Error("No signal connection"));
2371
+ }
2372
+ const breakoutCurrentId = selectBreakoutCurrentId(state);
2373
+ const { files } = payload;
2374
+ if (!files.length) {
2375
+ return;
2376
+ }
2377
+ const tooManyFiles = files.length > MAX_FILES_PER_UPLOAD;
2378
+ const entries = files.map((file) => {
2379
+ const error = tooManyFiles ? "too_many_files" : validateFile(file);
2380
+ const upload = Object.assign({ id: uuid.v4(), name: file.name, size: file.size, type: file.type, status: error ? "error" : "uploading" }, (error && { error }));
2381
+ return { file, upload };
2382
+ });
2383
+ dispatch(fileUploadsStarted(entries.map((entry) => entry.upload)));
2384
+ const accepted = entries.filter((entry) => entry.upload.status === "uploading");
2385
+ if (!accepted.length) {
2386
+ dispatch(fileShareRequestSettled());
2387
+ return;
2388
+ }
2389
+ const acceptedFiles = accepted.map((entry) => entry.file);
2390
+ const outcome = yield new Promise((resolve) => {
2391
+ let settled = false;
2392
+ const removeListener = dispatch(addAppListener({
2393
+ actionCreator: signalEvents.fileSharingError,
2394
+ effect: (action, listenerApi) => {
2395
+ if (settled)
2396
+ return;
2397
+ settled = true;
2398
+ listenerApi.unsubscribe();
2399
+ resolve({ error: action.payload.error });
2400
+ },
2401
+ }));
2402
+ socket.emit("request_file_upload_url", { files: acceptedFiles.map((f) => ({ name: f.name, size: f.size, type: f.type })) }, (urls) => {
2403
+ if (settled)
2404
+ return;
2405
+ settled = true;
2406
+ removeListener({ cancelActive: true });
2407
+ resolve({ urls });
2408
+ });
2409
+ });
2410
+ dispatch(fileShareRequestSettled());
2411
+ if ("error" in outcome) {
2412
+ accepted.forEach((entry) => dispatch(fileUploadFailed({ id: entry.upload.id, error: outcome.error })));
2413
+ return;
2414
+ }
2415
+ yield Promise.all(accepted.map((_a, index_1) => __awaiter(void 0, [_a, index_1], void 0, function* ({ file, upload }, index) {
2416
+ const urls = outcome.urls[index];
2417
+ if (!urls) {
2418
+ dispatch(fileUploadFailed({ id: upload.id, error: "upload_failed" }));
2419
+ return;
2420
+ }
2421
+ try {
2422
+ const response = yield uploadFile(file, urls.uploadUrl);
2423
+ if (!response.ok) {
2424
+ throw new Error(`S3 upload failed with status ${response.status}`);
2425
+ }
2426
+ socket.emit("chat_message", Object.assign({ text: "", file: {
2427
+ downloadUrl: urls.downloadUrl,
2428
+ name: file.name,
2429
+ size: file.size,
2430
+ type: file.type,
2431
+ key: urls.uploadUrl.fields.key,
2432
+ } }, (breakoutCurrentId && { breakoutGroup: breakoutCurrentId })));
2433
+ dispatch(fileUploadSucceeded({ id: upload.id }));
2434
+ }
2435
+ catch (_b) {
2436
+ dispatch(fileUploadFailed({ id: upload.id, error: "upload_failed" }));
2437
+ }
2438
+ })));
2439
+ }));
2440
+ const doDownloadFile = createAppAsyncThunk("fileShare/downloadFile", (payload) => __awaiter(void 0, void 0, void 0, function* () {
2441
+ const response = yield fetch(payload.file.downloadUrl, { mode: "cors", cache: "no-cache" });
2442
+ if (!response.ok) {
2443
+ throw new Error(`Failed to download file: ${response.status}`);
2444
+ }
2445
+ return response.blob();
2446
+ }));
2447
+ const selectFileShareRaw = (state) => state.fileShare;
2448
+ const selectFileUploads = (state) => state.fileShare.uploads;
2449
+ const selectFileShareRequestInFlight = (state) => state.fileShare.requestInFlight;
2450
+
2280
2451
  const initialLiveTranscriptionState = {
2281
2452
  isInitiator: false,
2282
2453
  isTranscribing: false,
@@ -3409,6 +3580,7 @@ const appReducer = toolkit.combineReducers({
3409
3580
  cloudRecording: cloudRecordingSlice.reducer,
3410
3581
  connectionMonitor: connectionMonitorSlice.reducer,
3411
3582
  deviceCredentials: deviceCredentialsSlice.reducer,
3583
+ fileShare: fileShareSlice.reducer,
3412
3584
  liveTranscription: liveTranscriptionSlice.reducer,
3413
3585
  localMedia: localMediaSlice.reducer,
3414
3586
  localParticipant: localParticipantSlice.reducer,
@@ -4185,6 +4357,9 @@ function createServices() {
4185
4357
  };
4186
4358
  }
4187
4359
 
4360
+ exports.ACCEPTED_FILE_TYPES = ACCEPTED_FILE_TYPES;
4361
+ exports.MAX_FILES_PER_UPLOAD = MAX_FILES_PER_UPLOAD;
4362
+ exports.MAX_FILE_SIZE = MAX_FILE_SIZE;
4188
4363
  exports.addAppListener = addAppListener;
4189
4364
  exports.addSpotlight = addSpotlight;
4190
4365
  exports.appSlice = appSlice;
@@ -4194,6 +4369,7 @@ exports.breakoutSlice = breakoutSlice;
4194
4369
  exports.breakoutSliceInitialState = breakoutSliceInitialState;
4195
4370
  exports.chatSlice = chatSlice;
4196
4371
  exports.chatSliceInitialState = chatSliceInitialState;
4372
+ exports.clearFileUploads = clearFileUploads;
4197
4373
  exports.cloudRecordingSlice = cloudRecordingSlice;
4198
4374
  exports.connectionMonitorSlice = connectionMonitorSlice;
4199
4375
  exports.connectionMonitorSliceInitialState = connectionMonitorSliceInitialState;
@@ -4224,6 +4400,7 @@ exports.doClearNotifications = doClearNotifications;
4224
4400
  exports.doConnectRoom = doConnectRoom;
4225
4401
  exports.doConnectRtc = doConnectRtc;
4226
4402
  exports.doDisconnectRtc = doDisconnectRtc;
4403
+ exports.doDownloadFile = doDownloadFile;
4227
4404
  exports.doEnableAudio = doEnableAudio;
4228
4405
  exports.doEnableVideo = doEnableVideo;
4229
4406
  exports.doEndMeeting = doEndMeeting;
@@ -4247,6 +4424,7 @@ exports.doRtcManagerInitialize = doRtcManagerInitialize;
4247
4424
  exports.doRtcReportStreamResolution = doRtcReportStreamResolution;
4248
4425
  exports.doSendChatMessage = doSendChatMessage;
4249
4426
  exports.doSendClientMetadata = doSendClientMetadata;
4427
+ exports.doSendFiles = doSendFiles;
4250
4428
  exports.doSetDevice = doSetDevice;
4251
4429
  exports.doSetDisplayName = doSetDisplayName;
4252
4430
  exports.doSetLocalStickyReaction = doSetLocalStickyReaction;
@@ -4269,6 +4447,12 @@ exports.doSwitchLocalStream = doSwitchLocalStream;
4269
4447
  exports.doToggleCamera = doToggleCamera;
4270
4448
  exports.doTriggerLocalStreamRefresh = doTriggerLocalStreamRefresh;
4271
4449
  exports.doUpdateDeviceList = doUpdateDeviceList;
4450
+ exports.fileShareRequestSettled = fileShareRequestSettled;
4451
+ exports.fileShareSlice = fileShareSlice;
4452
+ exports.fileShareSliceInitialState = fileShareSliceInitialState;
4453
+ exports.fileUploadFailed = fileUploadFailed;
4454
+ exports.fileUploadSucceeded = fileUploadSucceeded;
4455
+ exports.fileUploadsStarted = fileUploadsStarted;
4272
4456
  exports.initialCloudRecordingState = initialCloudRecordingState;
4273
4457
  exports.initialLiveTranscriptionState = initialLiveTranscriptionState;
4274
4458
  exports.initialLocalMediaState = initialLocalMediaState;
@@ -4354,6 +4538,9 @@ exports.selectCurrentMicrophoneDeviceId = selectCurrentMicrophoneDeviceId;
4354
4538
  exports.selectCurrentSpeakerDeviceId = selectCurrentSpeakerDeviceId;
4355
4539
  exports.selectDeviceCredentialsRaw = selectDeviceCredentialsRaw;
4356
4540
  exports.selectDeviceId = selectDeviceId;
4541
+ exports.selectFileShareRaw = selectFileShareRaw;
4542
+ exports.selectFileShareRequestInFlight = selectFileShareRequestInFlight;
4543
+ exports.selectFileUploads = selectFileUploads;
4357
4544
  exports.selectHasFetchedDeviceCredentials = selectHasFetchedDeviceCredentials;
4358
4545
  exports.selectIsAcceptingStreams = selectIsAcceptingStreams;
4359
4546
  exports.selectIsAuthorizedToAskToSpeak = selectIsAuthorizedToAskToSpeak;