mediasfu-reactnative
Version:
MediaSFU Prebuilt React Native SDK
89 lines • 4.31 kB
JavaScript
const resumeLocalSendTransportAudio = async ({ parameters, }) => {
try {
const { localAudioProducer, updateLocalAudioProducer, } = parameters;
// Resume local audio producer
if (localAudioProducer) {
localAudioProducer.resume();
updateLocalAudioProducer === null || updateLocalAudioProducer === void 0 ? void 0 : updateLocalAudioProducer(localAudioProducer);
}
}
catch (error) {
console.error('Error resuming local audio send transport:', error);
throw error; // Re-throw to propagate the error
}
};
/**
* Resumes the send transport for audio and updates the UI and audio producer state accordingly.
*
* This function supports both a primary and a local audio producer, delegating the local logic to a separate function.
*
* @param {ResumeSendTransportAudioOptions} options - The options for resuming the send transport.
* @param {ResumeSendTransportAudioParameters} options.parameters - The parameters for resuming the send transport.
* @param {Producer} options.parameters.audioProducer - The primary audio producer to resume.
* @param {Producer} [options.parameters.localAudioProducer] - The local audio producer to resume.
* @param {string} options.parameters.islevel - The level of the audio producer.
* @param {string} options.parameters.hostLabel - The label for the host.
* @param {boolean} options.parameters.lock_screen - Indicates if the screen is locked.
* @param {boolean} options.parameters.shared - Indicates if the screen is shared.
* @param {boolean} options.parameters.videoAlreadyOn - Indicates if the video is already on.
* @param {Function} options.parameters.updateAudioProducer - Function to update the audio producer state.
* @param {Function} [options.parameters.updateLocalAudioProducer] - Function to update the local audio producer state.
* @param {Function} options.parameters.updateUpdateMainWindow - Function to update the main window.
* @param {Function} options.parameters.prepopulateUserMedia - Function to prepopulate user media.
* @returns {Promise<void>} A promise that resolves when the send transport is resumed and the UI is updated.
*
* @throws {Error} Throws an error if there is an issue during the process of resuming the audio send transport.
*
* @example
* ```typescript
* await resumeSendTransportAudio({
* parameters: {
* audioProducer: producer,
* localAudioProducer: localProducer,
* islevel: '1',
* hostLabel: 'Host',
* lock_screen: false,
* shared: false,
* updateAudioProducer: updateProducerFunction,
* updateLocalAudioProducer: updateLocalProducerFunction,
* videoAlreadyOn: false,
* updateUpdateMainWindow: updateWindowFunction,
* prepopulateUserMedia: prepopulateFunction,
* prepopulateLocalUserMedia: prepopulateLocalFunction,
* },
* });
* ```
*/
export const resumeSendTransportAudio = async ({ parameters, }) => {
try {
const { audioProducer, islevel, hostLabel, lock_screen, shared, updateAudioProducer, videoAlreadyOn, updateUpdateMainWindow,
//mediasfu functions
prepopulateUserMedia, } = parameters;
// Resume send transport for audio
audioProducer.resume();
// Update UI for primary producer
if (!videoAlreadyOn && islevel === '2') {
if (!lock_screen && !shared) {
let updatedMainWindow = true;
updateUpdateMainWindow(updatedMainWindow);
await prepopulateUserMedia({ name: hostLabel, parameters });
updatedMainWindow = false;
updateUpdateMainWindow(updatedMainWindow);
}
}
// Update audio producer state
updateAudioProducer(audioProducer);
// Attempt to handle local audio producer if primary fails
try {
await resumeLocalSendTransportAudio({ parameters });
}
catch (localError) {
console.error('local audio send transport resuming failed:', localError);
}
}
catch (error) {
// Handle errors during the process of resuming the audio send transport
throw new Error(`Error during resuming audio send transport: ${error.message}`);
}
};
//# sourceMappingURL=resumeSendTransportAudio.js.map