Description
Describe the bug
Receive the following error, when calling the code in 'To Reproduce' Section.
TypeError: Failed to execute 'addTransceiver' on 'RTCPeerConnection': The argument provided as parameter 1 is not a valid MediaStreamTrack
kind ('audio' or 'video').
To Reproduce
Calling the following code on a properly instantiated(createOffer etc.) peer connection in Chrome - Version 87.0.4280.88 (Official Build) (64-bit):
peerConnection.addTransceiver(
kind: RTCRtpMediaType.RTCRtpMediaTypeAudio,
init: RTCRtpTransceiverInit(
direction: TransceiverDirection.RecvOnly
)
);
Expected behavior
The transceiver should be added to the peer connection. In android this works as expected.
The error occurs, because the implementation web/rtc_peerconnection_impl.dart -> addTransceiver (lines: 341-352), fails to convert the RTCRtpMediaType to string.
The mapping exists ('typeRTCRtpMediaTypetoString') in enums.dart, but is not called.
I also found that the error is fixed in branch 'add-unfied-plan-for-flutter-web'.
I suggest a quick fix, independent of that branch.
The following should work:
//'audio|video', { 'direction': 'recvonly|sendonly|sendrecv' }
@override
Future<RTCRtpTransceiver> addTransceiver(
{MediaStreamTrack track,
RTCRtpMediaType kind,
RTCRtpTransceiverInit init}) async {
var kindOrTrack = kind == null?null : typeRTCRtpMediaTypetoString[kind];
if(kindOrTrack == null) {
kindOrTrack = (track as MediaStreamTrackWeb).jsTrack;
}
final jsOptions = jsutil
.jsify(init != null ? RTCRtpTransceiverInitWeb.initToMap(init) : {});
var transceiver =
jsutil.callMethod(_jsPc, 'addTransceiver', [kindOrTrack, jsOptions]);
return RTCRtpTransceiverWeb.fromJsObject(transceiver,
peerConnectionId: _peerConnectionId);
}
Platform information
- Flutter version
[✓] Flutter (Channel master, 1.26.0-2.0.pre.91, on Linux, locale en_US.UTF-8) - Plugin version:
0.5.7 - OS: Chrome
- OS version:
Version 87.0.4280.88 (Official Build) (64-bit).