disconnectLocalSendTransportVideo function
Disconnects the local send transport for video by closing the local video producer and notifying the server.
Parameters:
options
(DisconnectSendTransportVideoOptions
): Contains the parameters required for disconnecting the local video transport.
Workflow:
- Close Local Video Producer:
- If an active local video producer exists, it is closed.
- The local state is updated to reflect the closed producer.
- Notify Server:
- Emits
pauseProducerMedia
event withmediaTag
asvideo
to notify about the paused local video producer.
- Emits
Returns:
- A
Future<void>
that completes when the local video transport is successfully disconnected.
Error Handling:
- Logs errors to the console in debug mode and rethrows them for higher-level handling.
Example Usage:
final options = DisconnectSendTransportVideoOptions(
parameters: myDisconnectSendTransportVideoParameters,
);
disconnectLocalSendTransportVideo(options)
.then(() => print('Local video send transport disconnected successfully'))
.catchError((error) => print('Error disconnecting local video send transport: $error'));
Implementation
Future<void> disconnectLocalSendTransportVideo(
DisconnectSendTransportVideoOptions options) async {
try {
final parameters = options.parameters;
final Producer? localVideoProducer = parameters.localVideoProducer;
final io.Socket? localSocket = parameters.localSocket;
final String roomName = parameters.roomName;
final void Function(Producer? localVideoProducer)?
updateLocalVideoProducer = parameters.updateLocalVideoProducer;
if (localSocket == null || localSocket.id == null) {
// Local socket is not connected; nothing to disconnect
return;
}
// Close the local video producer and update the state
if (localVideoProducer != null) {
localVideoProducer.close();
updateLocalVideoProducer?.call(null); // Set to null after closing
}
// Notify the server about closing the local video producer and pausing video sharing
localSocket.emit('pauseProducerMedia', {
'mediaTag': 'video',
'roomName': roomName,
});
} catch (error) {
if (kDebugMode) {
print('Error disconnecting local send transport for video: $error');
}
rethrow; // Re-throw to propagate the error
}
}