Skip to content

Commit 15d47ce

Browse files
committed
fix issue #169.
1 parent a81631d commit 15d47ce

File tree

2 files changed

+75
-11
lines changed

2 files changed

+75
-11
lines changed

lib/src/rtc_session.dart

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ class RTCSession extends EventManager {
359359

360360
_newRTCSession('local', _request);
361361
await _sendInitialRequest(
362-
mediaConstraints, rtcOfferConstraints, mediaStream);
362+
pcConfig, mediaConstraints, rtcOfferConstraints, mediaStream);
363363
}
364364

365365
void init_incoming(IncomingRequest request,
@@ -475,6 +475,12 @@ class RTCSession extends EventManager {
475475
bool peerOffersFullAudio = false;
476476
bool peerOffersFullVideo = false;
477477

478+
// In future versions, unified-plan will be used by default
479+
String sdpSemantics = 'unified-plan';
480+
if (pcConfig['sdpSemantics'] != null) {
481+
sdpSemantics = pcConfig['sdpSemantics'];
482+
}
483+
478484
_rtcAnswerConstraints = rtcAnswerConstraints;
479485
_rtcOfferConstraints = options['rtcOfferConstraints'] ?? null;
480486

@@ -615,8 +621,22 @@ class RTCSession extends EventManager {
615621

616622
// Attach MediaStream to RTCPeerconnection.
617623
_localMediaStream = stream;
624+
618625
if (stream != null) {
619-
_connection.addStream(stream);
626+
switch (sdpSemantics) {
627+
case 'unified-plan':
628+
stream.getTracks().forEach((MediaStreamTrack track) {
629+
_connection.addTrack(track, stream);
630+
});
631+
break;
632+
case 'plan-b':
633+
_connection.addStream(stream);
634+
break;
635+
default:
636+
logger.error('Unkown sdp semantics $sdpSemantics');
637+
throw Exceptions.NotReadyError('Unkown sdp semantics $sdpSemantics');
638+
break;
639+
}
620640
}
621641

622642
// Set remote description.
@@ -1565,9 +1585,28 @@ class RTCSession extends EventManager {
15651585
}
15661586
};
15671587

1568-
_connection.onAddStream = (MediaStream stream) {
1569-
emit(EventStream(session: this, originator: 'remote', stream: stream));
1570-
};
1588+
// In future versions, unified-plan will be used by default
1589+
String sdpSemantics = 'unified-plan';
1590+
if (pcConfig['sdpSemantics'] != null) {
1591+
sdpSemantics = pcConfig['sdpSemantics'];
1592+
}
1593+
1594+
switch (sdpSemantics) {
1595+
case 'unified-plan':
1596+
_connection.onTrack = (RTCTrackEvent event) {
1597+
if (event.track.kind == 'video' && event.streams.isNotEmpty) {
1598+
emit(EventStream(
1599+
session: this, originator: 'remote', stream: event.streams[0]));
1600+
}
1601+
};
1602+
break;
1603+
case 'plan-b':
1604+
_connection.onAddStream = (MediaStream stream) {
1605+
emit(
1606+
EventStream(session: this, originator: 'remote', stream: stream));
1607+
};
1608+
break;
1609+
}
15711610

15721611
logger.debug('emit "peerconnection"');
15731612
emit(EventPeerConnection(_connection));
@@ -2121,8 +2160,11 @@ class RTCSession extends EventManager {
21212160
/**
21222161
* Initial Request Sender
21232162
*/
2124-
Future<Null> _sendInitialRequest(Map<String, dynamic> mediaConstraints,
2125-
Map<String, dynamic> rtcOfferConstraints, MediaStream mediaStream) async {
2163+
Future<Null> _sendInitialRequest(
2164+
Map<String, dynamic> pcConfig,
2165+
Map<String, dynamic> mediaConstraints,
2166+
Map<String, dynamic> rtcOfferConstraints,
2167+
MediaStream mediaStream) async {
21262168
EventManager handlers = EventManager();
21272169
handlers.on(EventOnRequestTimeout(), (EventOnRequestTimeout value) {
21282170
onRequestTimeout();
@@ -2139,6 +2181,12 @@ class RTCSession extends EventManager {
21392181

21402182
RequestSender request_sender = RequestSender(_ua, _request, handlers);
21412183

2184+
// In future versions, unified-plan will be used by default
2185+
String sdpSemantics = 'unified-plan';
2186+
if (pcConfig['sdpSemantics'] != null) {
2187+
sdpSemantics = pcConfig['sdpSemantics'];
2188+
}
2189+
21422190
// This Promise is resolved within the next iteration, so the app has now
21432191
// a chance to set events such as 'peerconnection' and 'connecting'.
21442192
MediaStream stream;
@@ -2177,7 +2225,20 @@ class RTCSession extends EventManager {
21772225
_localMediaStream = stream;
21782226

21792227
if (stream != null) {
2180-
_connection.addStream(stream);
2228+
switch (sdpSemantics) {
2229+
case 'unified-plan':
2230+
stream.getTracks().forEach((MediaStreamTrack track) {
2231+
_connection.addTrack(track, stream);
2232+
});
2233+
break;
2234+
case 'plan-b':
2235+
_connection.addStream(stream);
2236+
break;
2237+
default:
2238+
logger.error('Unkown sdp semantics $sdpSemantics');
2239+
throw Exceptions.NotReadyError('Unkown sdp semantics $sdpSemantics');
2240+
break;
2241+
}
21812242
}
21822243

21832244
// TODO(cloudwebrtc): should this be triggered here?

lib/src/sip_ua_helper.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ class SIPUAHelper extends EventManager {
156156
RTCSession session = event.session;
157157
if (session.direction == 'incoming') {
158158
// Set event handlers.
159-
session
160-
.addAllEventHandlers(buildCallOptions()['eventHandlers'] as EventManager);
159+
session.addAllEventHandlers(
160+
buildCallOptions()['eventHandlers'] as EventManager);
161161
}
162162
_calls[event.id] =
163163
Call(event.id, session, CallStateEnum.CALL_INITIATION);
@@ -268,7 +268,10 @@ class SIPUAHelper extends EventManager {
268268

269269
Map<String, Object> _defaultOptions = <String, dynamic>{
270270
'eventHandlers': handlers,
271-
'pcConfig': <String, dynamic>{'iceServers': _uaSettings.iceServers},
271+
'pcConfig': <String, dynamic>{
272+
'sdpSemantics': 'unified-plan',
273+
'iceServers': _uaSettings.iceServers
274+
},
272275
'mediaConstraints': <String, dynamic>{
273276
'audio': true,
274277
'video': voiceonly

0 commit comments

Comments
 (0)