Skip to content

Commit a1c25ad

Browse files
committed
Add remote_has_audio/video method for Call.
1 parent ab7cec6 commit a1c25ad

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/src/rtc_session.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ class RTCSession extends EventManager {
191191

192192
String get id => _id;
193193

194+
dynamic get request => _request;
195+
194196
RTCPeerConnection get connection => _connection;
195197

196198
RTCDTMFSender get dtmfSender =>

lib/src/sip_ua_helper.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,35 @@ class Call {
471471
}
472472
return '';
473473
}
474+
475+
bool get remote_has_audio => _peerHasMediaLine('audio');
476+
477+
bool get remote_has_video => _peerHasMediaLine('video');
478+
479+
bool _peerHasMediaLine(String media) {
480+
assert(
481+
_session != null, 'ERROR(_peerHasMediaLine): rtc session is invalid!');
482+
if (_session.request == null) {
483+
return false;
484+
}
485+
486+
bool peerHasMediaLine = false;
487+
Map<String, dynamic> sdp = _session.request.parseSDP();
488+
// Make sure sdp['media'] is an array, not the case if there is only one media.
489+
if (sdp['media'] is! List) {
490+
sdp['media'] = <dynamic>[sdp['media']];
491+
}
492+
// Go through all medias in SDP to find offered capabilities to answer with.
493+
for (Map<String, dynamic> m in sdp['media']) {
494+
if (media == 'audio' && m['type'] == 'audio') {
495+
peerHasMediaLine = true;
496+
}
497+
if (media == 'video' && m['type'] == 'video') {
498+
peerHasMediaLine = true;
499+
}
500+
}
501+
return peerHasMediaLine;
502+
}
474503
}
475504

476505
class CallState {

0 commit comments

Comments
 (0)