Skip to content

Commit 9676724

Browse files
Remove text media channels in SDP offers (#461)
Co-authored-by: Victor Uvarov <[email protected]>
1 parent e640197 commit 9676724

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

lib/src/rtc_session.dart

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,9 +634,10 @@ class RTCSession extends EventManager implements Owner {
634634
}
635635

636636
logger.d('emit "sdp"');
637-
emit(EventSdp(originator: 'remote', type: 'offer', sdp: request.body));
637+
final String? processedSDP = _sdpOfferToWebRTC(request.body);
638+
emit(EventSdp(originator: 'remote', type: 'offer', sdp: processedSDP));
638639

639-
RTCSessionDescription offer = RTCSessionDescription(request.body, 'offer');
640+
RTCSessionDescription offer = RTCSessionDescription(processedSDP, 'offer');
640641
try {
641642
await _connection!.setRemoteDescription(offer);
642643
} catch (error) {
@@ -1981,9 +1982,10 @@ class RTCSession extends EventManager implements Owner {
19811982
}
19821983

19831984
logger.d('emit "sdp"');
1984-
emit(EventSdp(originator: 'remote', type: 'offer', sdp: request.body));
1985+
final String? processedSDP = _sdpOfferToWebRTC(request.body);
1986+
emit(EventSdp(originator: 'remote', type: 'offer', sdp: processedSDP));
19851987

1986-
RTCSessionDescription offer = RTCSessionDescription(request.body, 'offer');
1988+
RTCSessionDescription offer = RTCSessionDescription(processedSDP, 'offer');
19871989

19881990
if (_status == C.STATUS_TERMINATED) {
19891991
throw Exceptions.InvalidStateError('terminated');
@@ -2789,6 +2791,28 @@ class RTCSession extends EventManager implements Owner {
27892791
return sdp_transform.write(sdp, null);
27902792
}
27912793

2794+
/// SDP offers may contain text media channels. e.g. Older clients using linphone.
2795+
///
2796+
/// WebRTC does not support text media channels, so remove them.
2797+
String? _sdpOfferToWebRTC(String? sdpInput) {
2798+
if (sdpInput == null) {
2799+
return sdpInput;
2800+
}
2801+
2802+
Map<String, dynamic> sdp = sdp_transform.parse(sdpInput);
2803+
2804+
final List<Map<String, dynamic>> mediaList = <Map<String, dynamic>>[];
2805+
2806+
for (dynamic element in sdp['media']) {
2807+
if (element['type'] != 'text') {
2808+
mediaList.add(element);
2809+
}
2810+
}
2811+
sdp['media'] = mediaList;
2812+
2813+
return sdp_transform.write(sdp, null);
2814+
}
2815+
27922816
void _setLocalMediaStatus() {
27932817
bool enableAudio = true, enableVideo = true;
27942818

0 commit comments

Comments
 (0)