mediasfu-reactnative
Version:
MediaSFU Prebuilt React Native SDK
108 lines • 5.45 kB
JavaScript
const disconnectLocalSendTransportVideo = async ({ parameters, }) => {
try {
const { localVideoProducer, localSocket, roomName, updateLocalVideoProducer, } = parameters;
if (localSocket && localSocket.id) {
// continue
}
else {
return;
}
// Close the local video producer and notify the server
if (localVideoProducer) {
localVideoProducer.close();
updateLocalVideoProducer === null || updateLocalVideoProducer === void 0 ? void 0 : updateLocalVideoProducer(null);
}
localSocket.emit('pauseProducerMedia', { mediaTag: 'video', roomName: roomName });
}
catch (error) {
console.error('Error disconnecting local video send transport:', error);
throw error; // Re-throw to propagate the error
}
};
/**
* Disconnects the send transport for video, closes the video producer, and updates the state.
*
* This function supports both a primary and a local video producer, delegating local handling to a separate function.
*
* @param {DisconnectSendTransportVideoOptions} options - The options for disconnecting the send transport.
* @param {DisconnectSendTransportVideoParameters} options.parameters - The parameters required for disconnecting the send transport.
* @param {Producer | null} options.parameters.videoProducer - The primary video producer object.
* @param {Producer | null} [options.parameters.localVideoProducer] - The local video producer object (optional).
* @param {Socket} options.parameters.socket - The primary socket object.
* @param {Socket} [options.parameters.localSocket] - The local socket object (optional).
* @param {string} options.parameters.islevel - The participant's level.
* @param {string} options.parameters.roomName - The name of the room.
* @param {boolean} options.parameters.updateMainWindow - The flag to update the main window.
* @param {boolean} options.parameters.lock_screen - The flag to lock the screen.
* @param {Function} options.parameters.updateUpdateMainWindow - The function to update the main window state.
* @param {Function} options.parameters.updateVideoProducer - The function to update the video producer state.
* @param {Function} [options.parameters.updateLocalVideoProducer] - The function to update the local video producer state (optional).
* @param {ReorderStreamsType} options.parameters.reorderStreams - The function to reorder streams.
* @param {Function} [options.parameters.updateLocalProducerTransport] - The function to update the local producer transport state (optional).
* @param {Function} [options.parameters.updateProducerTransport] - The function to update the producer transport state (optional).
*
* @returns {Promise<void>} A promise that resolves when the disconnection process is complete.
*
* @throws {Error} Throws an error if the disconnection process fails.
*
* @example
* const options = {
* parameters: {
* videoProducer: videoProducerInstance,
* localVideoProducer: localVideoProducerInstance,
* socket: socketInstance,
* localSocket: localSocketInstance,
* islevel: '2',
* roomName: 'Room A',
* updateMainWindow: false,
* lock_screen: false,
* updateUpdateMainWindow: (state) => console.log('Main window updated:', state),
* updateVideoProducer: (producer) => console.log('Video producer updated:', producer),
* updateLocalVideoProducer: (producer) => console.log('Local video producer updated:', producer),
* reorderStreams: reorderStreamsFunction,
* },
* };
*
* disconnectSendTransportVideo(options)
* .then(() => console.log('Video send transport disconnected successfully'))
* .catch((error) => console.error('Error disconnecting video send transport:', error));
*/
export const disconnectSendTransportVideo = async ({ parameters, }) => {
try {
let { videoProducer, socket, islevel, roomName, updateMainWindow, lock_screen, updateUpdateMainWindow, updateVideoProducer, reorderStreams, } = parameters;
// Close the primary video producer and notify the server
if (videoProducer) {
videoProducer.close();
updateVideoProducer(null);
}
socket.emit('pauseProducerMedia', { mediaTag: 'video', roomName: roomName });
// Update the UI based on the participant's level and screen lock status
if (islevel === '2') {
updateMainWindow = true;
updateUpdateMainWindow(updateMainWindow);
}
if (lock_screen) {
await reorderStreams({ add: true, screenChanged: true, parameters });
}
else {
await reorderStreams({ add: false, screenChanged: true, parameters });
}
// Handle local video transport regardless of primary success or failure
try {
await disconnectLocalSendTransportVideo({ parameters });
}
catch (localError) {
console.error('Error disconnecting local video send transport:', localError);
}
}
catch (error) {
// Handle errors during the disconnection process
if (error instanceof Error) {
console.log('Error disconnecting send transport for video:', error.message);
}
else {
console.log('Error disconnecting send transport for video:', error);
}
}
};
//# sourceMappingURL=disconnectSendTransportVideo.js.map