UNPKG

mediasfu-reactnative

Version:
256 lines 12.8 kB
/** * Closes and resizes the video and audio elements based on the provided options. * * @param {CloseAndResizeOptions} options - The options for closing and resizing. * @param {string} options.producerId - The ID of the producer. * @param {string} options.kind - The kind of media (audio, video, screenshare, or screen). * @param {object} options.parameters - The parameters for the operation. * @param {function} options.parameters.getUpdatedAllParams - Function to get updated parameters. * @param {Array} options.parameters.allAudioStreams - Array of all audio streams. * @param {Array} options.parameters.allVideoStreams - Array of all video streams. * @param {Array} options.parameters.activeNames - Array of active participant names. * @param {Array} options.parameters.participants - Array of participants. * @param {Array} options.parameters.streamNames - Array of stream names. * @param {string} options.parameters.recordingDisplayType - Type of recording display. * @param {boolean} options.parameters.recordingVideoOptimized - Whether recording is video optimized. * @param {string} options.parameters.adminIDStream - ID of the admin stream. * @param {Array} options.parameters.newLimitedStreams - Array of new limited streams. * @param {Array} options.parameters.newLimitedStreamsIDs - Array of new limited stream IDs. * @param {Array} options.parameters.oldAllStreams - Array of old all streams. * @param {boolean} options.parameters.shareScreenStarted - Whether screen sharing has started. * @param {boolean} options.parameters.shared - Whether sharing is active. * @param {string} options.parameters.meetingDisplayType - Type of meeting display. * @param {boolean} options.parameters.defer_receive - Whether to defer receiving. * @param {boolean} options.parameters.lock_screen - Whether the screen is locked. * @param {boolean} options.parameters.firstAll - Whether it is the first all. * @param {boolean} options.parameters.first_round - Whether it is the first round. * @param {boolean} options.parameters.gotAllVids - Whether all videos are received. * @param {string} options.parameters.eventType - Type of event. * @param {string} options.parameters.hostLabel - Label of the host. * @param {boolean} options.parameters.shareEnded - Whether sharing has ended. * @param {boolean} options.parameters.updateMainWindow - Whether to update the main window. * @param {function} options.parameters.updateActiveNames - Function to update active names. * @param {function} options.parameters.updateAllAudioStreams - Function to update all audio streams. * @param {function} options.parameters.updateAllVideoStreams - Function to update all video streams. * @param {function} options.parameters.updateShareScreenStarted - Function to update share screen started status. * @param {function} options.parameters.updateUpdateMainWindow - Function to update main window status. * @param {function} options.parameters.updateNewLimitedStreams - Function to update new limited streams. * @param {function} options.parameters.updateOldAllStreams - Function to update old all streams. * @param {function} options.parameters.updateDefer_receive - Function to update defer receive status. * @param {function} options.parameters.updateMainHeightWidth - Function to update main height and width. * @param {function} options.parameters.updateShareEnded - Function to update share ended status. * @param {function} options.parameters.updateLock_screen - Function to update lock screen status. * @param {function} options.parameters.updateFirstAll - Function to update first all status. * @param {function} options.parameters.updateFirst_round - Function to update first round status. * @param {function} options.parameters.reorderStreams - Function to reorder streams. * @param {function} options.parameters.prepopulateUserMedia - Function to prepopulate user media. * @param {function} options.parameters.getVideos - Function to get videos. * @param {function} options.parameters.rePort - Function to report. * * @returns {Promise<void>} A promise that resolves when the operation is complete. * * @example * const options = { * producerId: 'producerId', * kind: 'video', * parameters: { * getUpdatedAllParams: getUpdatedAllParamsFunction, * allAudioStreams: [], * allVideoStreams: [], * activeNames: [], * participants: [], * streamNames: [], * recordingDisplayType: 'video', * recordingVideoOptimized: true, * adminIDStream: 'adminId', * newLimitedStreams: [], * newLimitedStreamsIDs: [], * oldAllStreams: [], * shareScreenStarted: false, * shared: false, * meetingDisplayType: 'video', * defer_receive: false, * lock_screen: false, * firstAll: false, * first_round: false, * gotAllVids: false, * eventType: 'conference', * hostLabel: 'host', * shareEnded: false, * updateMainWindow: true, * updateActiveNames: updateActiveNamesFunction, * updateAllAudioStreams: updateAllAudioStreamsFunction, * updateAllVideoStreams: updateAllVideoStreamsFunction, * updateShareScreenStarted: updateShareScreenStartedFunction, * updateUpdateMainWindow: updateUpdateMainWindowFunction, * updateNewLimitedStreams: updateNewLimitedStreamsFunction, * updateOldAllStreams: updateOldAllStreamsFunction, * updateDefer_receive: updateDefer_receiveFunction, * updateMainHeightWidth: updateMainHeightWidthFunction, * updateShareEnded: updateShareEndedFunction, * updateLock_screen: updateLock_screenFunction, * updateFirstAll: updateFirstAllFunction, * updateFirst_round: updateFirst_roundFunction, * reorderStreams: reorderStreamsFunction, * prepopulateUserMedia: prepopulateUserMediaFunction, * getVideos: getVideosFunction, * rePort: rePortFunction, * }, * }; * * closeAndResize(options) * .then(() => { * console.log('Closed and resized successfully'); * }); */ export const closeAndResize = async ({ producerId, kind, parameters }) => { const { getUpdatedAllParams } = parameters; parameters = getUpdatedAllParams(); let { allAudioStreams, allVideoStreams, activeNames, participants, streamNames, recordingDisplayType, recordingVideoOptimized, adminIDStream, newLimitedStreams, newLimitedStreamsIDs, oldAllStreams, shareScreenStarted, shared, meetingDisplayType, defer_receive, lock_screen, firstAll, first_round, gotAllVids, eventType, hostLabel, shareEnded, updateMainWindow, updateActiveNames, updateAllAudioStreams, updateAllVideoStreams, updateShareScreenStarted, updateUpdateMainWindow, updateNewLimitedStreams, updateOldAllStreams, updateDefer_receive, updateMainHeightWidth, updateShareEnded, updateLock_screen, updateFirstAll, updateFirst_round, // mediasfu functions reorderStreams, prepopulateUserMedia, getVideos, rePort, } = parameters; // function to close and resize the video and audio elements let participant; if (kind === 'audio') { // stop the audio by removing the miniAudio with id = producerId // remove the audio from the allAudioStreams array allAudioStreams = allAudioStreams.filter((audioStream) => audioStream.producerId !== producerId); updateAllAudioStreams(allAudioStreams); if (recordingDisplayType == 'video' && recordingVideoOptimized == true) { // optimize the video display } else { // get the name of the participant with the producerId participant = participants.find((obj) => obj.audioID === producerId); if (participant) { // check if the participants videoID is not null or "" if (participant.videoID !== null && participant.videoID !== '') { // found a participant with the producerId } else { // remove the participant from the activeNames array activeNames = activeNames.filter((name) => name !== participant.name); updateActiveNames(activeNames); } } } let checker = false; let alt_checker = false; if (meetingDisplayType == 'video') { checker = participant[0].videoID != null && participant[0].videoID != '' && participant[0].videoID != undefined; } else { checker = true; alt_checker = true; } if (checker) { if (shareScreenStarted || shared) { if (!alt_checker) { await reorderStreams({ parameters }); } } else if (alt_checker && meetingDisplayType != 'video') { await reorderStreams({ add: false, screenChanged: true, parameters }); } } } else if (kind === 'video') { // update the video elements by removing the miniVideo with id = producerId // remove the video from the allVideoStreams array // check if producerId == adminidstream if (producerId == adminIDStream) { updateMainWindow = true; updateUpdateMainWindow(updateMainWindow); } try { allVideoStreams = allVideoStreams.filter((videoStream) => videoStream.producerId !== producerId); updateAllVideoStreams(allVideoStreams); try { // try remove it from oldVideoStreams oldAllStreams = oldAllStreams.filter((videoStream) => videoStream.producerId !== producerId); updateOldAllStreams(oldAllStreams); } catch ( // Handle error _a) { // Handle error } try { // try remove it from newLimitedStreams newLimitedStreams = newLimitedStreams.filter((videoStream) => videoStream.producerId !== producerId); updateNewLimitedStreams(newLimitedStreams); } catch (_b) { // Handle error } } catch (_c) { try { // try remove it from oldVideoStreams oldAllStreams = oldAllStreams.filter((videoStream) => videoStream.producerId !== producerId); updateOldAllStreams(oldAllStreams); } catch (_d) { // Handle error } } try { // remove the participant from activeNames activeNames = activeNames.filter((name) => { // get the participant with the producerId const participant = streamNames.find((obj) => obj.producerId === producerId); return name !== participant.name; }); updateActiveNames(activeNames); } catch (_e) { // Handle error } if (lock_screen) { defer_receive = true; // check if the video is the one being displayed (i.e. (newLimitedStreamsIDs)) if (newLimitedStreamsIDs.includes(producerId)) { await prepopulateUserMedia({ name: hostLabel, parameters }); await reorderStreams({ add: false, screenChanged: true, parameters }); } } else { await prepopulateUserMedia({ name: hostLabel, parameters }); await reorderStreams({ add: false, screenChanged: true, parameters }); } } else if (kind === 'screenshare' || kind === 'screen') { // update the video elements by removing the mainVideo with id = producerId updateMainWindow = true; // screenshare stuff shareScreenStarted = false; shareEnded = true; lock_screen = false; firstAll = false; first_round = false; updateUpdateMainWindow(updateMainWindow); updateShareScreenStarted(shareScreenStarted); updateShareEnded(shareEnded); updateLock_screen(lock_screen); updateFirstAll(firstAll); updateFirst_round(first_round); if (!gotAllVids || defer_receive) { defer_receive = false; updateDefer_receive(defer_receive); await getVideos({ participants, allVideoStreams, oldAllStreams, updateAllVideoStreams, updateOldAllStreams, }); await rePort({ parameters }); } if (eventType == 'conference') { updateMainHeightWidth(0); } await prepopulateUserMedia({ name: hostLabel, parameters }); await reorderStreams({ add: false, screenChanged: true, parameters }); } }; //# sourceMappingURL=closeAndResize.js.map