injectMedia method
Inject media stream from outside only
Implementation
Future<MediaStream?> injectMedia(MediaStream? injectedLocalStream,
{bool? useDisplayMediaDevices = false,
Map<String, dynamic>? mediaConstraints,}) async {
await _disposeMediaStreams(ignoreRemote: true);
_context._logger.fine(mediaConstraints);
if (webRTCHandle != null) {
if (useDisplayMediaDevices == true) {
webRTCHandle!.localStream = injectedLocalStream;
} else {
webRTCHandle!.localStream = injectedLocalStream;
}
if (_context._isUnifiedPlan && !_context._usePlanB) {
_context._logger.finest('using unified plan');
webRTCHandle!.localStream!.getTracks().forEach((element) async {
_context._logger.finest('adding track in peerconnection');
_context._logger.finest(element.toString());
await webRTCHandle!.peerConnection!
.addTrack(element, webRTCHandle!.localStream!);
});
} else {
_localStreamController!.sink.add(webRTCHandle!.localStream);
await webRTCHandle!.peerConnection!
.addStream(webRTCHandle!.localStream!);
}
return webRTCHandle!.localStream;
} else {
_context._logger.severe("error webrtchandle cant be null");
return null;
}
}