Skip to content

Commit

Permalink
fix issue #169.
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwebrtc committed Feb 3, 2021
1 parent a81631d commit 15d47ce
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 11 deletions.
77 changes: 69 additions & 8 deletions lib/src/rtc_session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ class RTCSession extends EventManager {

_newRTCSession('local', _request);
await _sendInitialRequest(
mediaConstraints, rtcOfferConstraints, mediaStream);
pcConfig, mediaConstraints, rtcOfferConstraints, mediaStream);
}

void init_incoming(IncomingRequest request,
Expand Down Expand Up @@ -475,6 +475,12 @@ class RTCSession extends EventManager {
bool peerOffersFullAudio = false;
bool peerOffersFullVideo = false;

// In future versions, unified-plan will be used by default
String sdpSemantics = 'unified-plan';
if (pcConfig['sdpSemantics'] != null) {
sdpSemantics = pcConfig['sdpSemantics'];
}

_rtcAnswerConstraints = rtcAnswerConstraints;
_rtcOfferConstraints = options['rtcOfferConstraints'] ?? null;

Expand Down Expand Up @@ -615,8 +621,22 @@ class RTCSession extends EventManager {

// Attach MediaStream to RTCPeerconnection.
_localMediaStream = stream;

if (stream != null) {
_connection.addStream(stream);
switch (sdpSemantics) {
case 'unified-plan':
stream.getTracks().forEach((MediaStreamTrack track) {
_connection.addTrack(track, stream);
});
break;
case 'plan-b':
_connection.addStream(stream);
break;
default:
logger.error('Unkown sdp semantics $sdpSemantics');
throw Exceptions.NotReadyError('Unkown sdp semantics $sdpSemantics');
break;
}
}

// Set remote description.
Expand Down Expand Up @@ -1565,9 +1585,28 @@ class RTCSession extends EventManager {
}
};

_connection.onAddStream = (MediaStream stream) {
emit(EventStream(session: this, originator: 'remote', stream: stream));
};
// In future versions, unified-plan will be used by default
String sdpSemantics = 'unified-plan';
if (pcConfig['sdpSemantics'] != null) {
sdpSemantics = pcConfig['sdpSemantics'];
}

switch (sdpSemantics) {
case 'unified-plan':
_connection.onTrack = (RTCTrackEvent event) {
if (event.track.kind == 'video' && event.streams.isNotEmpty) {
emit(EventStream(
session: this, originator: 'remote', stream: event.streams[0]));
}
};
break;
case 'plan-b':
_connection.onAddStream = (MediaStream stream) {
emit(
EventStream(session: this, originator: 'remote', stream: stream));
};
break;
}

logger.debug('emit "peerconnection"');
emit(EventPeerConnection(_connection));
Expand Down Expand Up @@ -2121,8 +2160,11 @@ class RTCSession extends EventManager {
/**
* Initial Request Sender
*/
Future<Null> _sendInitialRequest(Map<String, dynamic> mediaConstraints,
Map<String, dynamic> rtcOfferConstraints, MediaStream mediaStream) async {
Future<Null> _sendInitialRequest(
Map<String, dynamic> pcConfig,
Map<String, dynamic> mediaConstraints,
Map<String, dynamic> rtcOfferConstraints,
MediaStream mediaStream) async {
EventManager handlers = EventManager();
handlers.on(EventOnRequestTimeout(), (EventOnRequestTimeout value) {
onRequestTimeout();
Expand All @@ -2139,6 +2181,12 @@ class RTCSession extends EventManager {

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

// In future versions, unified-plan will be used by default
String sdpSemantics = 'unified-plan';
if (pcConfig['sdpSemantics'] != null) {
sdpSemantics = pcConfig['sdpSemantics'];
}

// This Promise is resolved within the next iteration, so the app has now
// a chance to set events such as 'peerconnection' and 'connecting'.
MediaStream stream;
Expand Down Expand Up @@ -2177,7 +2225,20 @@ class RTCSession extends EventManager {
_localMediaStream = stream;

if (stream != null) {
_connection.addStream(stream);
switch (sdpSemantics) {
case 'unified-plan':
stream.getTracks().forEach((MediaStreamTrack track) {
_connection.addTrack(track, stream);
});
break;
case 'plan-b':
_connection.addStream(stream);
break;
default:
logger.error('Unkown sdp semantics $sdpSemantics');
throw Exceptions.NotReadyError('Unkown sdp semantics $sdpSemantics');
break;
}
}

// TODO(cloudwebrtc): should this be triggered here?
Expand Down
9 changes: 6 additions & 3 deletions lib/src/sip_ua_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ class SIPUAHelper extends EventManager {
RTCSession session = event.session;
if (session.direction == 'incoming') {
// Set event handlers.
session
.addAllEventHandlers(buildCallOptions()['eventHandlers'] as EventManager);
session.addAllEventHandlers(
buildCallOptions()['eventHandlers'] as EventManager);
}
_calls[event.id] =
Call(event.id, session, CallStateEnum.CALL_INITIATION);
Expand Down Expand Up @@ -268,7 +268,10 @@ class SIPUAHelper extends EventManager {

Map<String, Object> _defaultOptions = <String, dynamic>{
'eventHandlers': handlers,
'pcConfig': <String, dynamic>{'iceServers': _uaSettings.iceServers},
'pcConfig': <String, dynamic>{
'sdpSemantics': 'unified-plan',
'iceServers': _uaSettings.iceServers
},
'mediaConstraints': <String, dynamic>{
'audio': true,
'video': voiceonly
Expand Down

0 comments on commit 15d47ce

Please sign in to comment.