Handles the switching of the audio stream upon successful stream connection.
The options for the audio stream success switch.
A promise that resolves when the audio stream switch is complete.
const options = {
stream: newAudioStream, // MediaStream object containing the new audio track
parameters: {
audioProducer: currentAudioProducer,
localAudioProducer: localAudioProducerInstance,
localSocket: localSocketInstance,
socket: socketInstance,
roomName: "Room1",
localStream: null,
localStreamAudio: null,
audioParams: audioProducerOptions,
audioPaused: false,
audioAlreadyOn: true,
transportCreated: false,
audioParamse: additionalAudioParams,
defAudioID: "default-audio-device-id",
userDefaultAudioInputDevice: "user-input-device-id",
hostLabel: "Host",
islevel: "1",
videoAlreadyOn: false,
lock_screen: false,
shared: false,
updateAudioProducer: updateAudioProducerFunction,
updateLocalAudioProducer: updateLocalAudioProducerFunction,
updateLocalStream: updateLocalStreamFunction,
updateAudioParams: updateAudioParamsFunction,
updateDefAudioID: updateDefAudioIDFunction,
updateUserDefaultAudioInputDevice: updateUserDefaultAudioInputDeviceFunction,
updateUpdateMainWindow: updateMainWindowFunction,
sleep: sleepFunction,
prepopulateUserMedia: prepopulateUserMediaFunction,
createSendTransport: createSendTransportFunction,
connectSendTransportAudio: connectSendTransportAudioFunction,
},
};
streamSuccessAudioSwitch(options)
.then(() => {
console.log('Audio stream switched successfully');
})
.catch(error => {
console.error('Error switching audio stream:', error);
});
Handles the switching of the audio stream upon successful stream connection.
Param: options
The options for the audio stream success switch.
Param: options.stream
The new media stream containing the audio track.
Param: options.parameters
The parameters required for setting up the audio stream.
Param: options.parameters.audioProducer
The current audio producer.
Param: options.parameters.localAudioProducer
The local audio producer.
Param: options.parameters.socket
The socket connection for communication.
Param: options.parameters.localSocket
The local socket connection for communication.
Param: options.parameters.roomName
The name of the room.
Param: options.parameters.localStream
The local media stream.
Param: options.parameters.localStreamAudio
The local audio stream.
Param: options.parameters.audioParams
The audio parameters.
Param: options.parameters.audioPaused
Indicates if the audio is paused.
Param: options.parameters.audioAlreadyOn
Indicates if the audio is already on.
Param: options.parameters.transportCreated
Indicates if the transport is created.
Param: options.parameters.audioParamse
Additional audio parameters.
Param: options.parameters.defAudioID
The default audio device ID.
Param: options.parameters.userDefaultAudioInputDevice
The user default audio input device.
Param: options.parameters.hostLabel
The label of the host.
Param: options.parameters.updateMainWindow
Indicates if the main window should be updated.
Param: options.parameters.videoAlreadyOn
Indicates if the video is already on.
Param: options.parameters.islevel
The level of the participant.
Param: options.parameters.lock_screen
Indicates if the screen is locked.
Param: options.parameters.shared
Indicates if the screen is shared.
Param: options.parameters.updateAudioProducer
Function to update the audio producer.
Param: options.parameters.updateLocalAudioProducer
Function to update the local audio producer.
Param: options.parameters.updateLocalStream
Function to update the local stream.
Param: options.parameters.updateAudioParams
Function to update the audio parameters.
Param: options.parameters.updateDefAudioID
Function to update the default audio device ID.
Param: options.parameters.updateUserDefaultAudioInputDevice
Function to update the user default audio input device.
Param: options.parameters.updateUpdateMainWindow
Function to update the main window.
Param: options.parameters.sleep
Function to pause execution for a specified time.
Param: options.parameters.prepopulateUserMedia
Function to prepopulate user media.
Param: options.parameters.createSendTransport
Function to create a send transport.
Param: options.parameters.connectSendTransportAudio
Function to connect the send transport for audio.
Returns
A promise that resolves when the audio stream switch is complete.
Example