resumeSendTransportAudio function
- {required ResumeSendTransportAudioOptions options}
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 local handling to a separate function.
Parameters:
options
(ResumeSendTransportAudioOptions
): Contains the parameters required for resuming the send transport.
Workflow:
- Resume Primary Audio Producer:
- If an active primary audio producer exists, it is resumed.
- The primary state is updated to reflect the resumed producer.
- Update UI:
- Based on conditions (
videoAlreadyOn
,islevel
,lockScreen
,shared
), updates the main window state. - If no video is active and specific conditions are met, user media is prepopulated using
prepopulateUserMedia
.
- Based on conditions (
- Update Audio Producer State:
- Updates the audio producer state to reflect the resumed producer.
- Handle Local Audio Transport Resumption:
- Invokes
resumeLocalSendTransportAudio
to handle the local audio transport resumption. - Errors during local resumption are caught and logged without interrupting the main flow.
- Invokes
Returns:
- A
Future<void>
that completes when the audio send transport(s) are successfully resumed.
Error Handling:
- Catches and logs any errors encountered during the resumption process.
- Errors are printed to the console in debug mode to aid troubleshooting.
Example Usage:
final options = ResumeSendTransportAudioOptions(
parameters: MyResumeSendTransportAudioParameters(
audioProducer: myAudioProducer,
localAudioProducer: myLocalAudioProducer,
islevel: '2',
hostLabel: 'Host123',
lockScreen: false,
shared: false,
videoAlreadyOn: false,
updateAudioProducer: (producer) => setAudioProducer(producer),
updateLocalAudioProducer: (producer) => setLocalAudioProducer(producer),
updateUpdateMainWindow: (state) => setMainWindowState(state),
prepopulateUserMedia: prepopulateUserMediaFunction,
getUpdatedAllParams: () => updatedParameters,
),
);
await resumeSendTransportAudio(options: options);
Implementation
Future<void> resumeSendTransportAudio(
{required ResumeSendTransportAudioOptions options}) async {
final parameters = options.parameters;
final audioProducer = parameters.audioProducer;
final islevel = parameters.islevel;
final hostLabel = parameters.hostLabel;
final lockScreen = parameters.lockScreen;
final shared = parameters.shared;
final videoAlreadyOn = parameters.videoAlreadyOn;
final updateAudioProducer = parameters.updateAudioProducer;
final updateUpdateMainWindow = parameters.updateUpdateMainWindow;
final prepopulateUserMedia = parameters.prepopulateUserMedia;
try {
// Resume audio producer if available
audioProducer?.resume();
if (!videoAlreadyOn && islevel == '2') {
if (!lockScreen && !shared) {
updateUpdateMainWindow(true);
final optionsPrepopulate = PrepopulateUserMediaOptions(
name: hostLabel,
parameters: parameters,
);
prepopulateUserMedia(optionsPrepopulate);
updateUpdateMainWindow(false);
}
}
updateAudioProducer(audioProducer);
// Handle local audio transport resumption
try {
await resumeLocalSendTransportAudio(options);
} catch (localError) {
if (kDebugMode) {
print('Error resuming local audio send transport: $localError');
}
// Optionally, handle the local error (e.g., show a notification)
}
} catch (error) {
if (kDebugMode) {
print('Error during resuming audio send transport: $error');
}
}
}