|
|
@@ -21,7 +21,6 @@ function JingleSessionPC(me, sid, connection, service) {
|
|
21
|
21
|
this.state = null;
|
|
22
|
22
|
this.localSDP = null;
|
|
23
|
23
|
this.remoteSDP = null;
|
|
24
|
|
- this.relayedStreams = [];
|
|
25
|
24
|
|
|
26
|
25
|
this.usetrickle = true;
|
|
27
|
26
|
this.usepranswer = false; // early transport warmup -- mind you, this might fail. depends on webrtc issue 1718
|
|
|
@@ -37,8 +36,8 @@ function JingleSessionPC(me, sid, connection, service) {
|
|
37
|
36
|
this.addssrc = [];
|
|
38
|
37
|
this.removessrc = [];
|
|
39
|
38
|
this.pendingop = null;
|
|
40
|
|
- this.switchstreams = false;
|
|
41
|
|
- this.addingStreams = false;
|
|
|
39
|
+ this.modifyingLocalStreams = false;
|
|
|
40
|
+ this.modifiedSSRCs = {};
|
|
42
|
41
|
|
|
43
|
42
|
/**
|
|
44
|
43
|
* A map that stores SSRCs of local streams
|
|
|
@@ -182,10 +181,6 @@ JingleSessionPC.prototype.doInitialize = function () {
|
|
182
|
181
|
this.peerconnection.onnegotiationneeded = function (event) {
|
|
183
|
182
|
self.room.eventEmitter.emit(XMPPEvents.PEERCONNECTION_READY, self);
|
|
184
|
183
|
};
|
|
185
|
|
-
|
|
186
|
|
- this.relayedStreams.forEach(function(stream) {
|
|
187
|
|
- self.peerconnection.addStream(stream);
|
|
188
|
|
- });
|
|
189
|
184
|
};
|
|
190
|
185
|
|
|
191
|
186
|
function onIceConnectionStateChange(sid, session) {
|
|
|
@@ -461,81 +456,6 @@ JingleSessionPC.prototype.sendIceCandidates = function (candidates) {
|
|
461
|
456
|
10000);
|
|
462
|
457
|
};
|
|
463
|
458
|
|
|
464
|
|
-
|
|
465
|
|
-JingleSessionPC.prototype.sendOffer = function () {
|
|
466
|
|
- //logger.log('sendOffer...');
|
|
467
|
|
- var self = this;
|
|
468
|
|
- this.peerconnection.createOffer(function (sdp) {
|
|
469
|
|
- self.createdOffer(sdp);
|
|
470
|
|
- },
|
|
471
|
|
- function (e) {
|
|
472
|
|
- logger.error('createOffer failed', e);
|
|
473
|
|
- },
|
|
474
|
|
- this.media_constraints
|
|
475
|
|
- );
|
|
476
|
|
-};
|
|
477
|
|
-
|
|
478
|
|
-// FIXME createdOffer is never used in jitsi-meet
|
|
479
|
|
-JingleSessionPC.prototype.createdOffer = function (sdp) {
|
|
480
|
|
- //logger.log('createdOffer', sdp);
|
|
481
|
|
- var self = this;
|
|
482
|
|
- this.localSDP = new SDP(sdp.sdp);
|
|
483
|
|
- //this.localSDP.mangle();
|
|
484
|
|
- var sendJingle = function () {
|
|
485
|
|
- var init = $iq({to: this.peerjid,
|
|
486
|
|
- type: 'set'})
|
|
487
|
|
- .c('jingle', {xmlns: 'urn:xmpp:jingle:1',
|
|
488
|
|
- action: 'session-initiate',
|
|
489
|
|
- initiator: this.initiator,
|
|
490
|
|
- sid: this.sid});
|
|
491
|
|
- self.localSDP.toJingle(
|
|
492
|
|
- init,
|
|
493
|
|
- this.initiator == this.me ? 'initiator' : 'responder');
|
|
494
|
|
-
|
|
495
|
|
- self.connection.sendIQ(init,
|
|
496
|
|
- function () {
|
|
497
|
|
- var ack = {};
|
|
498
|
|
- ack.source = 'offer';
|
|
499
|
|
- $(document).trigger('ack.jingle', [self.sid, ack]);
|
|
500
|
|
- },
|
|
501
|
|
- function (stanza) {
|
|
502
|
|
- self.state = 'error';
|
|
503
|
|
- self.peerconnection.close();
|
|
504
|
|
- var error = ($(stanza).find('error').length) ? {
|
|
505
|
|
- code: $(stanza).find('error').attr('code'),
|
|
506
|
|
- reason: $(stanza).find('error :first')[0].tagName,
|
|
507
|
|
- }:{};
|
|
508
|
|
- error.source = 'offer';
|
|
509
|
|
- JingleSessionPC.onJingleError(self.sid, error);
|
|
510
|
|
- },
|
|
511
|
|
- 10000);
|
|
512
|
|
- }
|
|
513
|
|
- sdp.sdp = this.localSDP.raw;
|
|
514
|
|
- this.peerconnection.setLocalDescription(sdp,
|
|
515
|
|
- function () {
|
|
516
|
|
- if(self.usetrickle)
|
|
517
|
|
- {
|
|
518
|
|
- sendJingle();
|
|
519
|
|
- }
|
|
520
|
|
- self.setLocalDescription();
|
|
521
|
|
- //logger.log('setLocalDescription success');
|
|
522
|
|
- },
|
|
523
|
|
- function (e) {
|
|
524
|
|
- logger.error('setLocalDescription failed', e);
|
|
525
|
|
- self.room.eventEmitter.emit(XMPPEvents.CONFERENCE_SETUP_FAILED);
|
|
526
|
|
- }
|
|
527
|
|
- );
|
|
528
|
|
- var cands = SDPUtil.find_lines(this.localSDP.raw, 'a=candidate:');
|
|
529
|
|
- for (var i = 0; i < cands.length; i++) {
|
|
530
|
|
- var cand = SDPUtil.parse_icecandidate(cands[i]);
|
|
531
|
|
- if (cand.type == 'srflx') {
|
|
532
|
|
- this.hadstuncandidate = true;
|
|
533
|
|
- } else if (cand.type == 'relay') {
|
|
534
|
|
- this.hadturncandidate = true;
|
|
535
|
|
- }
|
|
536
|
|
- }
|
|
537
|
|
-};
|
|
538
|
|
-
|
|
539
|
459
|
JingleSessionPC.prototype.readSsrcInfo = function (contents) {
|
|
540
|
460
|
var self = this;
|
|
541
|
461
|
$(contents).each(function (idx, content) {
|
|
|
@@ -1032,7 +952,7 @@ JingleSessionPC.prototype._modifySources = function (successCallback, queueCallb
|
|
1032
|
952
|
|
|
1033
|
953
|
if (this.peerconnection.signalingState == 'closed') return;
|
|
1034
|
954
|
if (!(this.addssrc.length || this.removessrc.length || this.pendingop !== null
|
|
1035
|
|
- || this.switchstreams || this.addingStreams)){
|
|
|
955
|
+ || this.modifyingLocalStreams)){
|
|
1036
|
956
|
// There is nothing to do since scheduled job might have been executed by another succeeding call
|
|
1037
|
957
|
this.setLocalDescription();
|
|
1038
|
958
|
if(successCallback){
|
|
|
@@ -1043,8 +963,7 @@ JingleSessionPC.prototype._modifySources = function (successCallback, queueCallb
|
|
1043
|
963
|
}
|
|
1044
|
964
|
|
|
1045
|
965
|
// Reset switch streams flags
|
|
1046
|
|
- this.switchstreams = false;
|
|
1047
|
|
- this.addingStreams = false;
|
|
|
966
|
+ this.modifyingLocalStreams = false;
|
|
1048
|
967
|
|
|
1049
|
968
|
var sdp = new SDP(this.peerconnection.remoteDescription.sdp);
|
|
1050
|
969
|
|
|
|
@@ -1128,91 +1047,12 @@ JingleSessionPC.prototype._modifySources = function (successCallback, queueCallb
|
|
1128
|
1047
|
);
|
|
1129
|
1048
|
};
|
|
1130
|
1049
|
|
|
1131
|
|
-
|
|
1132
|
|
-/**
|
|
1133
|
|
- * Switches video streams.
|
|
1134
|
|
- * @param newStream new stream that will be used as video of this session.
|
|
1135
|
|
- * @param oldStream old video stream of this session.
|
|
1136
|
|
- * @param successCallback callback executed after successful stream switch.
|
|
1137
|
|
- * @param isAudio whether the streams are audio (if true) or video (if false).
|
|
1138
|
|
- */
|
|
1139
|
|
-JingleSessionPC.prototype.switchStreams =
|
|
1140
|
|
- function (newStream, oldStream, successCallback, isAudio) {
|
|
1141
|
|
- var self = this;
|
|
1142
|
|
- var sender, newTrack;
|
|
1143
|
|
- var senderKind = isAudio ? 'audio' : 'video';
|
|
1144
|
|
- // Remember SDP to figure out added/removed SSRCs
|
|
1145
|
|
- var oldSdp = null;
|
|
1146
|
|
-
|
|
1147
|
|
- if (self.peerconnection) {
|
|
1148
|
|
- if (self.peerconnection.localDescription) {
|
|
1149
|
|
- oldSdp = new SDP(self.peerconnection.localDescription.sdp);
|
|
1150
|
|
- }
|
|
1151
|
|
- if (RTCBrowserType.getBrowserType() ===
|
|
1152
|
|
- RTCBrowserType.RTC_BROWSER_FIREFOX) {
|
|
1153
|
|
- // On Firefox we don't replace MediaStreams as this messes up the
|
|
1154
|
|
- // m-lines (which can't be removed in Plan Unified) and brings a lot
|
|
1155
|
|
- // of complications. Instead, we use the RTPSender and replace just
|
|
1156
|
|
- // the track.
|
|
1157
|
|
-
|
|
1158
|
|
- // Find the right sender (for audio or video)
|
|
1159
|
|
- self.peerconnection.peerconnection.getSenders().some(function (s) {
|
|
1160
|
|
- if (s.track && s.track.kind === senderKind) {
|
|
1161
|
|
- sender = s;
|
|
1162
|
|
- return true;
|
|
1163
|
|
- }
|
|
1164
|
|
- });
|
|
1165
|
|
-
|
|
1166
|
|
- if (sender) {
|
|
1167
|
|
- // We assume that our streams have a single track, either audio
|
|
1168
|
|
- // or video.
|
|
1169
|
|
- newTrack = isAudio ? newStream.getAudioTracks()[0] :
|
|
1170
|
|
- newStream.getVideoTracks()[0];
|
|
1171
|
|
- sender.replaceTrack(newTrack)
|
|
1172
|
|
- .then(function() {
|
|
1173
|
|
- console.log("Replaced a track, isAudio=" + isAudio);
|
|
1174
|
|
- })
|
|
1175
|
|
- .catch(function(err) {
|
|
1176
|
|
- console.log("Failed to replace a track: " + err);
|
|
1177
|
|
- });
|
|
1178
|
|
- } else {
|
|
1179
|
|
- console.log("Cannot switch tracks: no RTPSender.");
|
|
1180
|
|
- }
|
|
1181
|
|
- } else {
|
|
1182
|
|
- self.peerconnection.removeStream(oldStream, true);
|
|
1183
|
|
- if (newStream) {
|
|
1184
|
|
- self.peerconnection.addStream(newStream);
|
|
1185
|
|
- }
|
|
1186
|
|
- }
|
|
1187
|
|
- }
|
|
1188
|
|
-
|
|
1189
|
|
- // Conference is not active
|
|
1190
|
|
- if (!oldSdp) {
|
|
1191
|
|
- successCallback();
|
|
1192
|
|
- return;
|
|
1193
|
|
- }
|
|
1194
|
|
-
|
|
1195
|
|
- self.switchstreams = true;
|
|
1196
|
|
- self.modifySourcesQueue.push(function() {
|
|
1197
|
|
- logger.log('modify sources done');
|
|
1198
|
|
-
|
|
1199
|
|
- successCallback();
|
|
1200
|
|
-
|
|
1201
|
|
- var newSdp = new SDP(self.peerconnection.localDescription.sdp);
|
|
1202
|
|
- logger.log("SDPs", oldSdp, newSdp);
|
|
1203
|
|
- self.notifyMySSRCUpdate(oldSdp, newSdp);
|
|
1204
|
|
- });
|
|
1205
|
|
-};
|
|
1206
|
|
-
|
|
1207
|
1050
|
/**
|
|
1208
|
1051
|
* Adds streams.
|
|
1209
|
1052
|
* @param stream new stream that will be added.
|
|
1210
|
1053
|
* @param success_callback callback executed after successful stream addition.
|
|
1211
|
1054
|
*/
|
|
1212
|
|
-JingleSessionPC.prototype.addStream = function (stream, callback) {
|
|
1213
|
|
-
|
|
1214
|
|
- var self = this;
|
|
1215
|
|
-
|
|
|
1055
|
+JingleSessionPC.prototype.addStream = function (stream, callback, ssrcInfo) {
|
|
1216
|
1056
|
// Remember SDP to figure out added/removed SSRCs
|
|
1217
|
1057
|
var oldSdp = null;
|
|
1218
|
1058
|
if(this.peerconnection) {
|
|
|
@@ -1220,7 +1060,7 @@ JingleSessionPC.prototype.addStream = function (stream, callback) {
|
|
1220
|
1060
|
oldSdp = new SDP(this.peerconnection.localDescription.sdp);
|
|
1221
|
1061
|
}
|
|
1222
|
1062
|
if(stream)
|
|
1223
|
|
- this.peerconnection.addStream(stream);
|
|
|
1063
|
+ this.peerconnection.addStream(stream, ssrcInfo);
|
|
1224
|
1064
|
}
|
|
1225
|
1065
|
|
|
1226
|
1066
|
// Conference is not active
|
|
|
@@ -1229,12 +1069,17 @@ JingleSessionPC.prototype.addStream = function (stream, callback) {
|
|
1229
|
1069
|
return;
|
|
1230
|
1070
|
}
|
|
1231
|
1071
|
|
|
1232
|
|
- this.addingStreams = true;
|
|
|
1072
|
+ this.modifyingLocalStreams = true;
|
|
|
1073
|
+ var self = this;
|
|
1233
|
1074
|
this.modifySourcesQueue.push(function() {
|
|
1234
|
1075
|
logger.log('modify sources done');
|
|
1235
|
1076
|
|
|
1236
|
1077
|
callback();
|
|
1237
|
|
-
|
|
|
1078
|
+ if(ssrcInfo) { //available only on video unmute
|
|
|
1079
|
+ self.modifiedSSRCs[ssrcInfo.type] =
|
|
|
1080
|
+ self.modifiedSSRCs[ssrcInfo.type] || [];
|
|
|
1081
|
+ self.modifiedSSRCs[ssrcInfo.type].push(ssrcInfo);
|
|
|
1082
|
+ }
|
|
1238
|
1083
|
var newSdp = new SDP(self.peerconnection.localDescription.sdp);
|
|
1239
|
1084
|
logger.log("SDPs", oldSdp, newSdp);
|
|
1240
|
1085
|
self.notifyMySSRCUpdate(oldSdp, newSdp);
|
|
|
@@ -1246,10 +1091,7 @@ JingleSessionPC.prototype.addStream = function (stream, callback) {
|
|
1246
|
1091
|
* @param stream stream that will be removed.
|
|
1247
|
1092
|
* @param success_callback callback executed after successful stream addition.
|
|
1248
|
1093
|
*/
|
|
1249
|
|
-JingleSessionPC.prototype.removeStream = function (stream, callback) {
|
|
1250
|
|
-
|
|
1251
|
|
- var self = this;
|
|
1252
|
|
-
|
|
|
1094
|
+JingleSessionPC.prototype.removeStream = function (stream, callback, ssrcInfo) {
|
|
1253
|
1095
|
// Remember SDP to figure out added/removed SSRCs
|
|
1254
|
1096
|
var oldSdp = null;
|
|
1255
|
1097
|
if(this.peerconnection) {
|
|
|
@@ -1258,10 +1100,12 @@ JingleSessionPC.prototype.removeStream = function (stream, callback) {
|
|
1258
|
1100
|
}
|
|
1259
|
1101
|
if (RTCBrowserType.getBrowserType() ===
|
|
1260
|
1102
|
RTCBrowserType.RTC_BROWSER_FIREFOX) {
|
|
|
1103
|
+ if(!stream)//There is nothing to be changed
|
|
|
1104
|
+ return;
|
|
1261
|
1105
|
var sender = null;
|
|
1262
|
1106
|
// On Firefox we don't replace MediaStreams as this messes up the
|
|
1263
|
1107
|
// m-lines (which can't be removed in Plan Unified) and brings a lot
|
|
1264
|
|
- // of complications. Instead, we use the RTPSender and replace just
|
|
|
1108
|
+ // of complications. Instead, we use the RTPSender and remove just
|
|
1265
|
1109
|
// the track.
|
|
1266
|
1110
|
var track = null;
|
|
1267
|
1111
|
if(stream.getAudioTracks() && stream.getAudioTracks().length) {
|
|
|
@@ -1272,7 +1116,7 @@ JingleSessionPC.prototype.removeStream = function (stream, callback) {
|
|
1272
|
1116
|
}
|
|
1273
|
1117
|
|
|
1274
|
1118
|
if(!track) {
|
|
1275
|
|
- console.log("Cannot switch tracks: no tracks.");
|
|
|
1119
|
+ logger.log("Cannot remove tracks: no tracks.");
|
|
1276
|
1120
|
return;
|
|
1277
|
1121
|
}
|
|
1278
|
1122
|
|
|
|
@@ -1286,17 +1130,15 @@ JingleSessionPC.prototype.removeStream = function (stream, callback) {
|
|
1286
|
1130
|
|
|
1287
|
1131
|
if (sender) {
|
|
1288
|
1132
|
self.peerconnection.peerconnection.removeTrack(sender);
|
|
1289
|
|
- // .then(function() {
|
|
1290
|
|
- // console.log("Replaced a track, isAudio=" + isAudio);
|
|
1291
|
|
- // })
|
|
1292
|
|
- // .catch(function(err) {
|
|
1293
|
|
- // console.log("Failed to replace a track: " + err);
|
|
1294
|
|
- // });
|
|
1295
|
1133
|
} else {
|
|
1296
|
|
- console.log("Cannot switch tracks: no RTPSender.");
|
|
|
1134
|
+ logger.log("Cannot remove tracks: no RTPSender.");
|
|
1297
|
1135
|
}
|
|
1298
|
1136
|
} else if(stream)
|
|
1299
|
|
- this.peerconnection.removeStream(stream);
|
|
|
1137
|
+ this.peerconnection.removeStream(stream, false, ssrcInfo);
|
|
|
1138
|
+ // else
|
|
|
1139
|
+ // NOTE: If there is no stream and the browser is not FF we still need to do
|
|
|
1140
|
+ // some transformation in order to send remove-source for the muted
|
|
|
1141
|
+ // streams. That's why we aren't calling return here.
|
|
1300
|
1142
|
}
|
|
1301
|
1143
|
|
|
1302
|
1144
|
// Conference is not active
|
|
|
@@ -1305,13 +1147,19 @@ JingleSessionPC.prototype.removeStream = function (stream, callback) {
|
|
1305
|
1147
|
return;
|
|
1306
|
1148
|
}
|
|
1307
|
1149
|
|
|
1308
|
|
- this.addingStreams = true;
|
|
|
1150
|
+ this.modifyingLocalStreams = true;
|
|
|
1151
|
+ var self = this;
|
|
1309
|
1152
|
this.modifySourcesQueue.push(function() {
|
|
1310
|
1153
|
logger.log('modify sources done');
|
|
1311
|
1154
|
|
|
1312
|
1155
|
callback();
|
|
1313
|
1156
|
|
|
1314
|
1157
|
var newSdp = new SDP(self.peerconnection.localDescription.sdp);
|
|
|
1158
|
+ if(ssrcInfo) {
|
|
|
1159
|
+ self.modifiedSSRCs[ssrcInfo.type] =
|
|
|
1160
|
+ self.modifiedSSRCs[ssrcInfo.type] || [];
|
|
|
1161
|
+ self.modifiedSSRCs[ssrcInfo.type].push(ssrcInfo);
|
|
|
1162
|
+ }
|
|
1315
|
1163
|
logger.log("SDPs", oldSdp, newSdp);
|
|
1316
|
1164
|
self.notifyMySSRCUpdate(oldSdp, newSdp);
|
|
1317
|
1165
|
});
|
|
|
@@ -1340,7 +1188,8 @@ JingleSessionPC.prototype.notifyMySSRCUpdate = function (old_sdp, new_sdp) {
|
|
1340
|
1188
|
sid: this.sid
|
|
1341
|
1189
|
}
|
|
1342
|
1190
|
);
|
|
1343
|
|
- var removed = sdpDiffer.toJingle(remove);
|
|
|
1191
|
+ sdpDiffer.toJingle(remove);
|
|
|
1192
|
+ var removed = this.fixJingle(remove);
|
|
1344
|
1193
|
|
|
1345
|
1194
|
if (removed && remove) {
|
|
1346
|
1195
|
logger.info("Sending source-remove", remove);
|
|
|
@@ -1366,7 +1215,9 @@ JingleSessionPC.prototype.notifyMySSRCUpdate = function (old_sdp, new_sdp) {
|
|
1366
|
1215
|
sid: this.sid
|
|
1367
|
1216
|
}
|
|
1368
|
1217
|
);
|
|
1369
|
|
- var added = sdpDiffer.toJingle(add);
|
|
|
1218
|
+
|
|
|
1219
|
+ sdpDiffer.toJingle(add);
|
|
|
1220
|
+ var added = this.fixJingle(add);
|
|
1370
|
1221
|
|
|
1371
|
1222
|
if (added && add) {
|
|
1372
|
1223
|
logger.info("Sending source-add", add);
|
|
|
@@ -1563,4 +1414,132 @@ JingleSessionPC.prototype.getIceConnectionState = function () {
|
|
1563
|
1414
|
return this.peerconnection.iceConnectionState;
|
|
1564
|
1415
|
}
|
|
1565
|
1416
|
|
|
|
1417
|
+
|
|
|
1418
|
+/**
|
|
|
1419
|
+ * Fixes the outgoing jingle packets by removing the nodes related to the
|
|
|
1420
|
+ * muted/unmuted streams, handles removing of muted stream, etc.
|
|
|
1421
|
+ * @param jingle the jingle packet that is going to be sent
|
|
|
1422
|
+ * @returns {boolean} true if the jingle has to be sent and false otherwise.
|
|
|
1423
|
+ */
|
|
|
1424
|
+JingleSessionPC.prototype.fixJingle = function(jingle) {
|
|
|
1425
|
+ var action = $(jingle.nodeTree).find("jingle").attr("action");
|
|
|
1426
|
+ switch (action) {
|
|
|
1427
|
+ case "source-add":
|
|
|
1428
|
+ this.fixSourceAddJingle(jingle);
|
|
|
1429
|
+ break;
|
|
|
1430
|
+ case "source-remove":
|
|
|
1431
|
+ this.fixSourceRemoveJingle(jingle);
|
|
|
1432
|
+ break;
|
|
|
1433
|
+ default:
|
|
|
1434
|
+ logger.error("Unknown jingle action!");
|
|
|
1435
|
+ return false;
|
|
|
1436
|
+ }
|
|
|
1437
|
+
|
|
|
1438
|
+ var sources = $(jingle.tree()).find(">jingle>content>description>source");
|
|
|
1439
|
+ return sources && sources.length > 0;
|
|
|
1440
|
+}
|
|
|
1441
|
+
|
|
|
1442
|
+/**
|
|
|
1443
|
+ * Fixes the outgoing jingle packets with action source-add by removing the
|
|
|
1444
|
+ * nodes related to the unmuted streams
|
|
|
1445
|
+ * @param jingle the jingle packet that is going to be sent
|
|
|
1446
|
+ * @returns {boolean} true if the jingle has to be sent and false otherwise.
|
|
|
1447
|
+ */
|
|
|
1448
|
+JingleSessionPC.prototype.fixSourceAddJingle = function (jingle) {
|
|
|
1449
|
+ var ssrcs = this.modifiedSSRCs["unmute"];
|
|
|
1450
|
+ this.modifiedSSRCs["unmute"] = [];
|
|
|
1451
|
+ if(ssrcs && ssrcs.length) {
|
|
|
1452
|
+ ssrcs.forEach(function (ssrcObj) {
|
|
|
1453
|
+ var desc = $(jingle.tree()).find(">jingle>content[name=\"" +
|
|
|
1454
|
+ ssrcObj.mtype + "\"]>description");
|
|
|
1455
|
+ if(!desc || !desc.length)
|
|
|
1456
|
+ return;
|
|
|
1457
|
+ ssrcObj.ssrc.ssrcs.forEach(function (ssrc) {
|
|
|
1458
|
+ var sourceNode = desc.find(">source[ssrc=\"" +
|
|
|
1459
|
+ ssrc + "\"]");
|
|
|
1460
|
+ sourceNode.remove();
|
|
|
1461
|
+ });
|
|
|
1462
|
+ ssrcObj.ssrc.groups.forEach(function (group) {
|
|
|
1463
|
+ var groupNode = desc.find(">ssrc-group[semantics=\"" +
|
|
|
1464
|
+ group.group.semantics + "\"]:has(source[ssrc=\"" +
|
|
|
1465
|
+ group.primarySSRC +
|
|
|
1466
|
+ "\"])");
|
|
|
1467
|
+ groupNode.remove();
|
|
|
1468
|
+ });
|
|
|
1469
|
+ });
|
|
|
1470
|
+ }
|
|
|
1471
|
+}
|
|
|
1472
|
+
|
|
|
1473
|
+/**
|
|
|
1474
|
+ * Fixes the outgoing jingle packets with action source-remove by removing the
|
|
|
1475
|
+ * nodes related to the muted streams, handles removing of muted stream
|
|
|
1476
|
+ * @param jingle the jingle packet that is going to be sent
|
|
|
1477
|
+ * @returns {boolean} true if the jingle has to be sent and false otherwise.
|
|
|
1478
|
+ */
|
|
|
1479
|
+JingleSessionPC.prototype.fixSourceRemoveJingle = function(jingle) {
|
|
|
1480
|
+ var ssrcs = this.modifiedSSRCs["mute"];
|
|
|
1481
|
+ this.modifiedSSRCs["mute"] = [];
|
|
|
1482
|
+ if(ssrcs && ssrcs.length)
|
|
|
1483
|
+ ssrcs.forEach(function (ssrcObj) {
|
|
|
1484
|
+ ssrcObj.ssrc.ssrcs.forEach(function (ssrc) {
|
|
|
1485
|
+ var sourceNode = $(jingle.tree()).find(">jingle>content[name=\"" +
|
|
|
1486
|
+ ssrcObj.mtype + "\"]>description>source[ssrc=\"" +
|
|
|
1487
|
+ ssrc + "\"]");
|
|
|
1488
|
+ sourceNode.remove();
|
|
|
1489
|
+ });
|
|
|
1490
|
+ ssrcObj.ssrc.groups.forEach(function (group) {
|
|
|
1491
|
+ var groupNode = $(jingle.tree()).find(">jingle>content[name=\"" +
|
|
|
1492
|
+ ssrcObj.mtype + "\"]>description>ssrc-group[semantics=\"" +
|
|
|
1493
|
+ group.group.semantics + "\"]:has(source[ssrc=\"" + group.primarySSRC +
|
|
|
1494
|
+ "\"])");
|
|
|
1495
|
+ groupNode.remove();
|
|
|
1496
|
+ });
|
|
|
1497
|
+ });
|
|
|
1498
|
+
|
|
|
1499
|
+ ssrcs = this.modifiedSSRCs["remove"];
|
|
|
1500
|
+ this.modifiedSSRCs["remove"] = [];
|
|
|
1501
|
+ if(ssrcs && ssrcs.length)
|
|
|
1502
|
+ ssrcs.forEach(function (ssrcObj) {
|
|
|
1503
|
+ var content = $(jingle.tree()).find(">jingle>content[name=\"" +
|
|
|
1504
|
+ ssrcObj.mtype + "\"]");
|
|
|
1505
|
+
|
|
|
1506
|
+ if(!content || !content.length) {
|
|
|
1507
|
+ $(jingle.tree()).find(">jingle").append(
|
|
|
1508
|
+ "<content name=\"" + ssrcObj.mtype + "\"></content>");
|
|
|
1509
|
+ content = $(jingle.tree()).find(">jingle>content[name=\"" +
|
|
|
1510
|
+ ssrcObj.mtype + "\"]");
|
|
|
1511
|
+ }
|
|
|
1512
|
+
|
|
|
1513
|
+ var desc = content.find(">description");
|
|
|
1514
|
+ if(!desc || !desc.length) {
|
|
|
1515
|
+ content.append("<description " +
|
|
|
1516
|
+ "xmlns=\"urn:xmpp:jingle:apps:rtp:1\" media=\"" +
|
|
|
1517
|
+ ssrcObj.mtype + "\"></description>");
|
|
|
1518
|
+ desc = content.find(">description");
|
|
|
1519
|
+ }
|
|
|
1520
|
+
|
|
|
1521
|
+ ssrcObj.ssrc.ssrcs.forEach(function (ssrc) {
|
|
|
1522
|
+ var sourceNode = desc.find(">source[ssrc=\"" +ssrc + "\"]");
|
|
|
1523
|
+ if(!sourceNode || !sourceNode.length) {
|
|
|
1524
|
+ //Maybe we have to include cname, msid, etc here?
|
|
|
1525
|
+ desc.append("<source " +
|
|
|
1526
|
+ "xmlns=\"urn:xmpp:jingle:apps:rtp:ssma:0\" ssrc=\"" +
|
|
|
1527
|
+ ssrc + "\"></source>");
|
|
|
1528
|
+ }
|
|
|
1529
|
+ });
|
|
|
1530
|
+ ssrcObj.ssrc.groups.forEach(function (group) {
|
|
|
1531
|
+ var groupNode = desc.find(">ssrc-group[semantics=\"" +
|
|
|
1532
|
+ group.group.semantics + "\"]:has(source[ssrc=\"" + group.primarySSRC +
|
|
|
1533
|
+ "\"])");
|
|
|
1534
|
+ if(!groupNode || !groupNode.length) {
|
|
|
1535
|
+ desc.append("<ssrc-group semantics=\"" +
|
|
|
1536
|
+ group.group.semantics +
|
|
|
1537
|
+ "\" xmlns=\"urn:xmpp:jingle:apps:rtp:ssma:0\"><source ssrc=\"" +
|
|
|
1538
|
+ group.group.ssrcs.split(" ").join("\"/><source ssrc=\"") + "\"/>" +
|
|
|
1539
|
+ "</ssrc-group>");
|
|
|
1540
|
+ }
|
|
|
1541
|
+ });
|
|
|
1542
|
+ });
|
|
|
1543
|
+}
|
|
|
1544
|
+
|
|
1566
|
1545
|
module.exports = JingleSessionPC;
|