|
|
@@ -1099,16 +1099,30 @@ ColibriFocus.prototype.addSource = function (elem, fromJid) {
|
|
1099
|
1099
|
|
|
1100
|
1100
|
this.peerconnection.addSource(elem);
|
|
1101
|
1101
|
|
|
|
1102
|
+ // NOTE(gp) this could be a useful thing to have in every Array object.
|
|
|
1103
|
+ var diffArray = function(a) {
|
|
|
1104
|
+ return this.filter(function(i) {return a.indexOf(i) < 0;});
|
|
|
1105
|
+ };
|
|
|
1106
|
+
|
|
1102
|
1107
|
var peerSsrc = this.remotessrc[fromJid];
|
|
1103
|
|
- //console.log("On ADD", self.addssrc, peerSsrc);
|
|
|
1108
|
+ // console.log("On ADD", this.peerconnection.addssrc, peerSsrc);
|
|
1104
|
1109
|
this.peerconnection.addssrc.forEach(function(val, idx){
|
|
1105
|
1110
|
if(!peerSsrc[idx]){
|
|
1106
|
1111
|
// add ssrc
|
|
1107
|
1112
|
peerSsrc[idx] = val;
|
|
1108
|
|
- } else {
|
|
1109
|
|
- if(peerSsrc[idx].indexOf(val) == -1){
|
|
1110
|
|
- peerSsrc[idx] = peerSsrc[idx]+val;
|
|
1111
|
|
- }
|
|
|
1113
|
+ } else if (val) {
|
|
|
1114
|
+ // NOTE(gp) we can't expect the lines in the removessrc SDP fragment
|
|
|
1115
|
+ // to be in the same order as in the lines in the peerSsrc SDP
|
|
|
1116
|
+ // fragment. So, here we remove the val lines and re-add them.
|
|
|
1117
|
+
|
|
|
1118
|
+ var lines = peerSsrc[idx].split('\r\n');
|
|
|
1119
|
+ var diffLines = val.split('\r\n');
|
|
|
1120
|
+
|
|
|
1121
|
+ // Remove ssrc
|
|
|
1122
|
+ peerSsrc[idx] = diffArray.apply(lines, [diffLines]).join('\r\n');
|
|
|
1123
|
+
|
|
|
1124
|
+ // Add ssrc
|
|
|
1125
|
+ peerSsrc[idx] = peerSsrc[idx]+val;
|
|
1112
|
1126
|
}
|
|
1113
|
1127
|
});
|
|
1114
|
1128
|
|
|
|
@@ -1150,12 +1164,22 @@ ColibriFocus.prototype.removeSource = function (elem, fromJid) {
|
|
1150
|
1164
|
|
|
1151
|
1165
|
this.peerconnection.removeSource(elem);
|
|
1152
|
1166
|
|
|
|
1167
|
+ // NOTE(gp) this could be a useful thing to have in every Array object.
|
|
|
1168
|
+ var diffArray = function(a) {
|
|
|
1169
|
+ return this.filter(function(i) {return a.indexOf(i) < 0;});
|
|
|
1170
|
+ };
|
|
|
1171
|
+
|
|
1153
|
1172
|
var peerSsrc = this.remotessrc[fromJid];
|
|
1154
|
|
- //console.log("On REMOVE", self.removessrc, peerSsrc);
|
|
|
1173
|
+ // console.log("On REMOVE", this.peerconnection.removessrc, peerSsrc);
|
|
1155
|
1174
|
this.peerconnection.removessrc.forEach(function(val, idx){
|
|
1156
|
|
- if(peerSsrc[idx]){
|
|
|
1175
|
+ if(peerSsrc[idx] && val){
|
|
|
1176
|
+ // NOTE(gp) we can't expect the lines in the removessrc SDP fragment
|
|
|
1177
|
+ // to be in the same order as in the lines in the peerSsrc SDP
|
|
|
1178
|
+ // fragment.
|
|
|
1179
|
+ var lines = peerSsrc[idx].split('\r\n');
|
|
|
1180
|
+ var diffLines = val.split('\r\n');
|
|
1157
|
1181
|
// Remove ssrc
|
|
1158
|
|
- peerSsrc[idx] = peerSsrc[idx].replace(val, '');
|
|
|
1182
|
+ peerSsrc[idx] = diffArray.apply(lines, [diffLines]).join('\r\n');
|
|
1159
|
1183
|
}
|
|
1160
|
1184
|
});
|
|
1161
|
1185
|
|