|
@@ -607,10 +607,10 @@ SDP.prototype.mangle = function () {
|
607
|
607
|
|
608
|
608
|
// remove lines matching prefix from session section
|
609
|
609
|
SDP.prototype.removeSessionLines = function(prefix) {
|
610
|
|
- var ob = this;
|
|
610
|
+ var self = this;
|
611
|
611
|
var lines = SDPUtil.find_lines(this.session, prefix);
|
612
|
612
|
lines.forEach(function(line) {
|
613
|
|
- ob.session = ob.session.replace(line + '\r\n', '');
|
|
613
|
+ self.session = self.session.replace(line + '\r\n', '');
|
614
|
614
|
});
|
615
|
615
|
this.raw = this.session + this.media.join('');
|
616
|
616
|
return lines;
|
|
@@ -618,10 +618,10 @@ SDP.prototype.removeSessionLines = function(prefix) {
|
618
|
618
|
// remove lines matching prefix from a media section specified by mediaindex
|
619
|
619
|
// TODO: non-numeric mediaindex could match mid
|
620
|
620
|
SDP.prototype.removeMediaLines = function(mediaindex, prefix) {
|
621
|
|
- var ob = this;
|
|
621
|
+ var self = this;
|
622
|
622
|
var lines = SDPUtil.find_lines(this.media[mediaindex], prefix);
|
623
|
623
|
lines.forEach(function(line) {
|
624
|
|
- ob.media[mediaindex] = ob.media[mediaindex].replace(line + '\r\n', '');
|
|
624
|
+ self.media[mediaindex] = self.media[mediaindex].replace(line + '\r\n', '');
|
625
|
625
|
});
|
626
|
626
|
this.raw = this.session + this.media.join('');
|
627
|
627
|
return lines;
|
|
@@ -630,7 +630,7 @@ SDP.prototype.removeMediaLines = function(mediaindex, prefix) {
|
630
|
630
|
// add content's to a jingle element
|
631
|
631
|
SDP.prototype.toJingle = function (elem, thecreator) {
|
632
|
632
|
var i, j, k, mline, ssrc, rtpmap, tmp, line, lines;
|
633
|
|
- var ob = this;
|
|
633
|
+ var self = this;
|
634
|
634
|
// new bundle plan
|
635
|
635
|
if (SDPUtil.find_line(this.session, 'a=group:')) {
|
636
|
636
|
lines = SDPUtil.find_lines(this.session, 'a=group:');
|
|
@@ -806,7 +806,7 @@ SDP.prototype.toJingle = function (elem, thecreator) {
|
806
|
806
|
SDP.prototype.TransportToJingle = function (mediaindex, elem) {
|
807
|
807
|
var i = mediaindex;
|
808
|
808
|
var tmp;
|
809
|
|
- var ob = this;
|
|
809
|
+ var self = this;
|
810
|
810
|
elem.c('transport');
|
811
|
811
|
|
812
|
812
|
// XEP-0320
|
|
@@ -817,7 +817,7 @@ SDP.prototype.TransportToJingle = function (mediaindex, elem) {
|
817
|
817
|
// tmp.xmlns = 'urn:xmpp:jingle:apps:dtls:0'; -- FIXME: update receivers first
|
818
|
818
|
elem.c('fingerprint').t(tmp.fingerprint);
|
819
|
819
|
delete tmp.fingerprint;
|
820
|
|
- line = SDPUtil.find_line(ob.media[mediaindex], 'a=setup:', ob.session);
|
|
820
|
+ line = SDPUtil.find_line(self.media[mediaindex], 'a=setup:', self.session);
|
821
|
821
|
if (line) {
|
822
|
822
|
tmp.setup = line.substr(8);
|
823
|
823
|
}
|
|
@@ -881,7 +881,7 @@ SDP.prototype.RtcpFbFromJingle = function (elem, payloadtype) { // XEP-0293
|
881
|
881
|
|
882
|
882
|
// construct an SDP from a jingle stanza
|
883
|
883
|
SDP.prototype.fromJingle = function (jingle) {
|
884
|
|
- var obj = this;
|
|
884
|
+ var self = this;
|
885
|
885
|
this.raw = 'v=0\r\n' +
|
886
|
886
|
'o=- ' + '1923518516' + ' 2 IN IP4 0.0.0.0\r\n' +// FIXME
|
887
|
887
|
's=-\r\n' +
|
|
@@ -893,7 +893,7 @@ SDP.prototype.fromJingle = function (jingle) {
|
893
|
893
|
return content.getAttribute('name');
|
894
|
894
|
}).get();
|
895
|
895
|
if (contents.length > 0) {
|
896
|
|
- obj.raw += 'a=group:' + (group.getAttribute('semantics') || group.getAttribute('type')) + ' ' + contents.join(' ') + '\r\n';
|
|
896
|
+ self.raw += 'a=group:' + (group.getAttribute('semantics') || group.getAttribute('type')) + ' ' + contents.join(' ') + '\r\n';
|
897
|
897
|
}
|
898
|
898
|
});
|
899
|
899
|
} else if ($(jingle).find('>group[xmlns="urn:ietf:rfc:5888"]').length) {
|
|
@@ -903,7 +903,7 @@ SDP.prototype.fromJingle = function (jingle) {
|
903
|
903
|
return content.getAttribute('name');
|
904
|
904
|
}).get();
|
905
|
905
|
if (group.getAttribute('type') !== null && contents.length > 0) {
|
906
|
|
- obj.raw += 'a=group:' + group.getAttribute('type') + ' ' + contents.join(' ') + '\r\n';
|
|
906
|
+ self.raw += 'a=group:' + group.getAttribute('type') + ' ' + contents.join(' ') + '\r\n';
|
907
|
907
|
}
|
908
|
908
|
});
|
909
|
909
|
} else {
|
|
@@ -922,8 +922,8 @@ SDP.prototype.fromJingle = function (jingle) {
|
922
|
922
|
|
923
|
923
|
this.session = this.raw;
|
924
|
924
|
jingle.find('>content').each(function () {
|
925
|
|
- var m = obj.jingle2media($(this));
|
926
|
|
- obj.media.push(m);
|
|
925
|
+ var m = self.jingle2media($(this));
|
|
926
|
+ self.media.push(m);
|
927
|
927
|
});
|
928
|
928
|
|
929
|
929
|
// reconstruct msid-semantic -- apparently not necessary
|
|
@@ -1416,7 +1416,7 @@ function JingleSession(me, sid, connection) {
|
1416
|
1416
|
}
|
1417
|
1417
|
|
1418
|
1418
|
JingleSession.prototype.initiate = function (peerjid, isInitiator) {
|
1419
|
|
- var obj = this;
|
|
1419
|
+ var self = this;
|
1420
|
1420
|
if (this.state !== null) {
|
1421
|
1421
|
console.error('attempt to initiate on session ' + this.sid +
|
1422
|
1422
|
'in state ' + this.state);
|
|
@@ -1427,11 +1427,10 @@ JingleSession.prototype.initiate = function (peerjid, isInitiator) {
|
1427
|
1427
|
this.initiator = isInitiator ? this.me : peerjid;
|
1428
|
1428
|
this.responder = !isInitiator ? this.me : peerjid;
|
1429
|
1429
|
this.peerjid = peerjid;
|
1430
|
|
- console.log('create PeerConnection ' + JSON.stringify(this.ice_config));
|
|
1430
|
+ //console.log('create PeerConnection ' + JSON.stringify(this.ice_config));
|
1431
|
1431
|
try {
|
1432
|
1432
|
this.peerconnection = new RTCPeerconnection(this.ice_config,
|
1433
|
1433
|
this.pc_constraints);
|
1434
|
|
- console.log('Created RTCPeerConnnection');
|
1435
|
1434
|
} catch (e) {
|
1436
|
1435
|
console.error('Failed to create PeerConnection, exception: ',
|
1437
|
1436
|
e.message);
|
|
@@ -1442,26 +1441,24 @@ JingleSession.prototype.initiate = function (peerjid, isInitiator) {
|
1442
|
1441
|
this.hadturncandidate = false;
|
1443
|
1442
|
this.lasticecandidate = false;
|
1444
|
1443
|
this.peerconnection.onicecandidate = function (event) {
|
1445
|
|
- obj.sendIceCandidate(event.candidate);
|
|
1444
|
+ self.sendIceCandidate(event.candidate);
|
1446
|
1445
|
};
|
1447
|
1446
|
this.peerconnection.onaddstream = function (event) {
|
1448
|
|
- obj.remoteStream = event.stream;
|
1449
|
|
- obj.remoteStreams.push(event.stream);
|
1450
|
|
- $(document).trigger('remotestreamadded.jingle', [event, obj.sid]);
|
|
1447
|
+ self.remoteStream = event.stream;
|
|
1448
|
+ self.remoteStreams.push(event.stream);
|
|
1449
|
+ $(document).trigger('remotestreamadded.jingle', [event, self.sid]);
|
1451
|
1450
|
};
|
1452
|
1451
|
this.peerconnection.onremovestream = function (event) {
|
1453
|
|
- obj.remoteStream = null;
|
|
1452
|
+ self.remoteStream = null;
|
1454
|
1453
|
// FIXME: remove from this.remoteStreams
|
1455
|
|
- $(document).trigger('remotestreamremoved.jingle', [event, obj.sid]);
|
|
1454
|
+ $(document).trigger('remotestreamremoved.jingle', [event, self.sid]);
|
1456
|
1455
|
};
|
1457
|
1456
|
this.peerconnection.onsignalingstatechange = function (event) {
|
1458
|
|
- if (!(obj && obj.peerconnection)) return;
|
1459
|
|
- console.log('signallingstate ', obj.peerconnection.signalingState, event);
|
|
1457
|
+ if (!(self && self.peerconnection)) return;
|
1460
|
1458
|
};
|
1461
|
1459
|
this.peerconnection.oniceconnectionstatechange = function (event) {
|
1462
|
|
- if (!(obj && obj.peerconnection)) return;
|
1463
|
|
- console.log('iceconnectionstatechange', obj.peerconnection.iceConnectionState, event);
|
1464
|
|
- switch (obj.peerconnection.iceConnectionState) {
|
|
1460
|
+ if (!(self && self.peerconnection)) return;
|
|
1461
|
+ switch (self.peerconnection.iceConnectionState) {
|
1465
|
1462
|
case 'connected':
|
1466
|
1463
|
this.startTime = new Date();
|
1467
|
1464
|
break;
|
|
@@ -1469,19 +1466,19 @@ JingleSession.prototype.initiate = function (peerjid, isInitiator) {
|
1469
|
1466
|
this.stopTime = new Date();
|
1470
|
1467
|
break;
|
1471
|
1468
|
}
|
1472
|
|
- $(document).trigger('iceconnectionstatechange.jingle', [obj.sid, obj]);
|
|
1469
|
+ $(document).trigger('iceconnectionstatechange.jingle', [self.sid, self]);
|
1473
|
1470
|
};
|
1474
|
1471
|
// add any local and relayed stream
|
1475
|
1472
|
this.localStreams.forEach(function(stream) {
|
1476
|
|
- obj.peerconnection.addStream(stream);
|
|
1473
|
+ self.peerconnection.addStream(stream);
|
1477
|
1474
|
});
|
1478
|
1475
|
this.relayedStreams.forEach(function(stream) {
|
1479
|
|
- obj.peerconnection.addStream(stream);
|
|
1476
|
+ self.peerconnection.addStream(stream);
|
1480
|
1477
|
});
|
1481
|
1478
|
};
|
1482
|
1479
|
|
1483
|
1480
|
JingleSession.prototype.accept = function () {
|
1484
|
|
- var ob = this;
|
|
1481
|
+ var self = this;
|
1485
|
1482
|
this.state = 'active';
|
1486
|
1483
|
|
1487
|
1484
|
var pranswer = this.peerconnection.localDescription;
|
|
@@ -1513,7 +1510,7 @@ JingleSession.prototype.accept = function () {
|
1513
|
1510
|
function () {
|
1514
|
1511
|
var ack = {};
|
1515
|
1512
|
ack.source = 'answer';
|
1516
|
|
- $(document).trigger('ack.jingle', [ob.sid, ack]);
|
|
1513
|
+ $(document).trigger('ack.jingle', [self.sid, ack]);
|
1517
|
1514
|
},
|
1518
|
1515
|
function (stanza) {
|
1519
|
1516
|
var error = ($(stanza).find('error').length) ? {
|
|
@@ -1521,7 +1518,7 @@ JingleSession.prototype.accept = function () {
|
1521
|
1518
|
reason: $(stanza).find('error :first')[0].tagName,
|
1522
|
1519
|
}:{};
|
1523
|
1520
|
error.source = 'answer';
|
1524
|
|
- $(document).trigger('error.jingle', [ob.sid, error]);
|
|
1521
|
+ $(document).trigger('error.jingle', [self.sid, error]);
|
1525
|
1522
|
},
|
1526
|
1523
|
10000);
|
1527
|
1524
|
|
|
@@ -1532,7 +1529,7 @@ JingleSession.prototype.accept = function () {
|
1532
|
1529
|
}
|
1533
|
1530
|
this.peerconnection.setLocalDescription(new RTCSessionDescription({type: 'answer', sdp: sdp}),
|
1534
|
1531
|
function () {
|
1535
|
|
- console.log('setLocalDescription success');
|
|
1532
|
+ //console.log('setLocalDescription success');
|
1536
|
1533
|
},
|
1537
|
1534
|
function (e) {
|
1538
|
1535
|
console.error('setLocalDescription failed', e);
|
|
@@ -1555,7 +1552,7 @@ JingleSession.prototype.active = function () {
|
1555
|
1552
|
};
|
1556
|
1553
|
|
1557
|
1554
|
JingleSession.prototype.sendIceCandidate = function (candidate) {
|
1558
|
|
- var ob = this;
|
|
1555
|
+ var self = this;
|
1559
|
1556
|
if (candidate && !this.lasticecandidate) {
|
1560
|
1557
|
var ice = SDPUtil.iceparams(this.localSDP.media[candidate.sdpMLineIndex], this.localSDP.session);
|
1561
|
1558
|
var jcand = SDPUtil.candidateToJingle(candidate.candidate);
|
|
@@ -1576,28 +1573,28 @@ JingleSession.prototype.sendIceCandidate = function (candidate) {
|
1576
|
1573
|
if (this.drip_container.length === 0) {
|
1577
|
1574
|
// start 10ms callout
|
1578
|
1575
|
window.setTimeout(function () {
|
1579
|
|
- if (ob.drip_container.length === 0) return;
|
1580
|
|
- var allcands = ob.drip_container;
|
1581
|
|
- ob.drip_container = [];
|
1582
|
|
- var cand = $iq({to: ob.peerjid, type: 'set'})
|
|
1576
|
+ if (self.drip_container.length === 0) return;
|
|
1577
|
+ var allcands = self.drip_container;
|
|
1578
|
+ self.drip_container = [];
|
|
1579
|
+ var cand = $iq({to: self.peerjid, type: 'set'})
|
1583
|
1580
|
.c('jingle', {xmlns: 'urn:xmpp:jingle:1',
|
1584
|
1581
|
action: 'transport-info',
|
1585
|
|
- initiator: ob.initiator,
|
1586
|
|
- sid: ob.sid});
|
1587
|
|
- for (var mid = 0; mid < ob.localSDP.media.length; mid++) {
|
|
1582
|
+ initiator: self.initiator,
|
|
1583
|
+ sid: self.sid});
|
|
1584
|
+ for (var mid = 0; mid < self.localSDP.media.length; mid++) {
|
1588
|
1585
|
var cands = allcands.filter(function (el) { return el.sdpMLineIndex == mid; });
|
1589
|
1586
|
if (cands.length > 0) {
|
1590
|
|
- var ice = SDPUtil.iceparams(ob.localSDP.media[mid], ob.localSDP.session);
|
|
1587
|
+ var ice = SDPUtil.iceparams(self.localSDP.media[mid], self.localSDP.session);
|
1591
|
1588
|
ice.xmlns = 'urn:xmpp:jingle:transports:ice-udp:1';
|
1592
|
|
- cand.c('content', {creator: ob.initiator == ob.me ? 'initiator' : 'responder',
|
|
1589
|
+ cand.c('content', {creator: self.initiator == self.me ? 'initiator' : 'responder',
|
1593
|
1590
|
name: cands[0].sdpMid
|
1594
|
1591
|
}).c('transport', ice);
|
1595
|
1592
|
for (var i = 0; i < cands.length; i++) {
|
1596
|
1593
|
cand.c('candidate', SDPUtil.candidateToJingle(cands[i].candidate)).up();
|
1597
|
1594
|
}
|
1598
|
1595
|
// add fingerprint
|
1599
|
|
- if (SDPUtil.find_line(ob.localSDP.media[mid], 'a=fingerprint:', ob.localSDP.session)) {
|
1600
|
|
- var tmp = SDPUtil.parse_fingerprint(SDPUtil.find_line(ob.localSDP.media[mid], 'a=fingerprint:', ob.localSDP.session));
|
|
1596
|
+ if (SDPUtil.find_line(self.localSDP.media[mid], 'a=fingerprint:', self.localSDP.session)) {
|
|
1597
|
+ var tmp = SDPUtil.parse_fingerprint(SDPUtil.find_line(self.localSDP.media[mid], 'a=fingerprint:', self.localSDP.session));
|
1601
|
1598
|
tmp.required = true;
|
1602
|
1599
|
cand.c('fingerprint').t(tmp.fingerprint);
|
1603
|
1600
|
delete tmp.fingerprint;
|
|
@@ -1609,12 +1606,12 @@ JingleSession.prototype.sendIceCandidate = function (candidate) {
|
1609
|
1606
|
}
|
1610
|
1607
|
}
|
1611
|
1608
|
// might merge last-candidate notification into this, but it is called alot later. See webrtc issue #2340
|
1612
|
|
- //console.log('was this the last candidate', ob.lasticecandidate);
|
1613
|
|
- ob.connection.sendIQ(cand,
|
|
1609
|
+ //console.log('was this the last candidate', self.lasticecandidate);
|
|
1610
|
+ self.connection.sendIQ(cand,
|
1614
|
1611
|
function () {
|
1615
|
1612
|
var ack = {};
|
1616
|
1613
|
ack.source = 'transportinfo';
|
1617
|
|
- $(document).trigger('ack.jingle', [ob.sid, ack]);
|
|
1614
|
+ $(document).trigger('ack.jingle', [self.sid, ack]);
|
1618
|
1615
|
},
|
1619
|
1616
|
function (stanza) {
|
1620
|
1617
|
var error = ($(stanza).find('error').length) ? {
|
|
@@ -1622,7 +1619,7 @@ JingleSession.prototype.sendIceCandidate = function (candidate) {
|
1622
|
1619
|
reason: $(stanza).find('error :first')[0].tagName,
|
1623
|
1620
|
}:{};
|
1624
|
1621
|
error.source = 'transportinfo';
|
1625
|
|
- $(document).trigger('error.jingle', [ob.sid, error]);
|
|
1622
|
+ $(document).trigger('error.jingle', [self.sid, error]);
|
1626
|
1623
|
},
|
1627
|
1624
|
10000);
|
1628
|
1625
|
}, 10);
|
|
@@ -1655,7 +1652,7 @@ JingleSession.prototype.sendIceCandidate = function (candidate) {
|
1655
|
1652
|
function () {
|
1656
|
1653
|
var ack = {};
|
1657
|
1654
|
ack.source = 'transportinfo';
|
1658
|
|
- $(document).trigger('ack.jingle', [ob.sid, ack]);
|
|
1655
|
+ $(document).trigger('ack.jingle', [self.sid, ack]);
|
1659
|
1656
|
},
|
1660
|
1657
|
function (stanza) {
|
1661
|
1658
|
console.error('transport info error');
|
|
@@ -1664,14 +1661,14 @@ JingleSession.prototype.sendIceCandidate = function (candidate) {
|
1664
|
1661
|
reason: $(stanza).find('error :first')[0].tagName,
|
1665
|
1662
|
}:{};
|
1666
|
1663
|
error.source = 'transportinfo';
|
1667
|
|
- $(document).trigger('error.jingle', [ob.sid, error]);
|
|
1664
|
+ $(document).trigger('error.jingle', [self.sid, error]);
|
1668
|
1665
|
},
|
1669
|
1666
|
10000);
|
1670
|
1667
|
}
|
1671
|
1668
|
} else {
|
1672
|
|
- console.log('sendIceCandidate: last candidate.');
|
|
1669
|
+ //console.log('sendIceCandidate: last candidate.');
|
1673
|
1670
|
if (!this.usetrickle) {
|
1674
|
|
- console.log('should send full offer now...');
|
|
1671
|
+ //console.log('should send full offer now...');
|
1675
|
1672
|
var init = $iq({to: this.peerjid,
|
1676
|
1673
|
type: 'set'})
|
1677
|
1674
|
.c('jingle', {xmlns: 'urn:xmpp:jingle:1',
|
|
@@ -1682,20 +1679,20 @@ JingleSession.prototype.sendIceCandidate = function (candidate) {
|
1682
|
1679
|
this.localSDP.toJingle(init, this.initiator == this.me ? 'initiator' : 'responder');
|
1683
|
1680
|
this.connection.sendIQ(init,
|
1684
|
1681
|
function () {
|
1685
|
|
- console.log('session initiate ack');
|
|
1682
|
+ //console.log('session initiate ack');
|
1686
|
1683
|
var ack = {};
|
1687
|
1684
|
ack.source = 'offer';
|
1688
|
|
- $(document).trigger('ack.jingle', [ob.sid, ack]);
|
|
1685
|
+ $(document).trigger('ack.jingle', [self.sid, ack]);
|
1689
|
1686
|
},
|
1690
|
1687
|
function (stanza) {
|
1691
|
|
- ob.state = 'error';
|
1692
|
|
- ob.peerconnection.close();
|
|
1688
|
+ self.state = 'error';
|
|
1689
|
+ self.peerconnection.close();
|
1693
|
1690
|
var error = ($(stanza).find('error').length) ? {
|
1694
|
1691
|
code: $(stanza).find('error').attr('code'),
|
1695
|
1692
|
reason: $(stanza).find('error :first')[0].tagName,
|
1696
|
1693
|
}:{};
|
1697
|
1694
|
error.source = 'offer';
|
1698
|
|
- $(document).trigger('error.jingle', [ob.sid, error]);
|
|
1695
|
+ $(document).trigger('error.jingle', [self.sid, error]);
|
1699
|
1696
|
},
|
1700
|
1697
|
10000);
|
1701
|
1698
|
}
|
|
@@ -1710,10 +1707,10 @@ JingleSession.prototype.sendIceCandidate = function (candidate) {
|
1710
|
1707
|
};
|
1711
|
1708
|
|
1712
|
1709
|
JingleSession.prototype.sendOffer = function () {
|
1713
|
|
- console.log('sendOffer...');
|
1714
|
|
- var ob = this;
|
|
1710
|
+ //console.log('sendOffer...');
|
|
1711
|
+ var self = this;
|
1715
|
1712
|
this.peerconnection.createOffer(function (sdp) {
|
1716
|
|
- ob.createdOffer(sdp);
|
|
1713
|
+ self.createdOffer(sdp);
|
1717
|
1714
|
},
|
1718
|
1715
|
function (e) {
|
1719
|
1716
|
console.error('createOffer failed', e);
|
|
@@ -1723,8 +1720,8 @@ JingleSession.prototype.sendOffer = function () {
|
1723
|
1720
|
};
|
1724
|
1721
|
|
1725
|
1722
|
JingleSession.prototype.createdOffer = function (sdp) {
|
1726
|
|
- console.log('createdOffer', sdp);
|
1727
|
|
- var ob = this;
|
|
1723
|
+ //console.log('createdOffer', sdp);
|
|
1724
|
+ var self = this;
|
1728
|
1725
|
this.localSDP = new SDP(sdp.sdp);
|
1729
|
1726
|
//this.localSDP.mangle();
|
1730
|
1727
|
if (this.usetrickle) {
|
|
@@ -1739,23 +1736,24 @@ JingleSession.prototype.createdOffer = function (sdp) {
|
1739
|
1736
|
function () {
|
1740
|
1737
|
var ack = {};
|
1741
|
1738
|
ack.source = 'offer';
|
1742
|
|
- $(document).trigger('ack.jingle', [ob.sid, ack]);
|
|
1739
|
+ $(document).trigger('ack.jingle', [self.sid, ack]);
|
1743
|
1740
|
},
|
1744
|
1741
|
function (stanza) {
|
1745
|
|
- ob.state = 'error';
|
1746
|
|
- ob.peerconnection.close();
|
|
1742
|
+ self.state = 'error';
|
|
1743
|
+ self.peerconnection.close();
|
1747
|
1744
|
var error = ($(stanza).find('error').length) ? {
|
1748
|
1745
|
code: $(stanza).find('error').attr('code'),
|
1749
|
1746
|
reason: $(stanza).find('error :first')[0].tagName,
|
1750
|
1747
|
}:{};
|
1751
|
1748
|
error.source = 'offer';
|
1752
|
|
- $(document).trigger('error.jingle', [ob.sid, error]);
|
|
1749
|
+ $(document).trigger('error.jingle', [self.sid, error]);
|
1753
|
1750
|
},
|
1754
|
1751
|
10000);
|
1755
|
1752
|
}
|
1756
|
1753
|
sdp.sdp = this.localSDP.raw;
|
1757
|
|
- this.peerconnection.setLocalDescription(sdp, function () {
|
1758
|
|
- console.log('setLocalDescription success');
|
|
1754
|
+ this.peerconnection.setLocalDescription(sdp,
|
|
1755
|
+ function () {
|
|
1756
|
+ //console.log('setLocalDescription success');
|
1759
|
1757
|
},
|
1760
|
1758
|
function (e) {
|
1761
|
1759
|
console.error('setLocalDescription failed', e);
|
|
@@ -1773,7 +1771,7 @@ JingleSession.prototype.createdOffer = function (sdp) {
|
1773
|
1771
|
};
|
1774
|
1772
|
|
1775
|
1773
|
JingleSession.prototype.setRemoteDescription = function (elem, desctype) {
|
1776
|
|
- console.log('setting remote description... ', desctype);
|
|
1774
|
+ //console.log('setting remote description... ', desctype);
|
1777
|
1775
|
this.remoteSDP = new SDP('');
|
1778
|
1776
|
this.remoteSDP.fromJingle(elem);
|
1779
|
1777
|
if (this.peerconnection.remoteDescription !== null) {
|
|
@@ -1807,7 +1805,7 @@ JingleSession.prototype.setRemoteDescription = function (elem, desctype) {
|
1807
|
1805
|
|
1808
|
1806
|
this.peerconnection.setRemoteDescription(remotedesc,
|
1809
|
1807
|
function () {
|
1810
|
|
- console.log('setRemoteDescription success');
|
|
1808
|
+ //console.log('setRemoteDescription success');
|
1811
|
1809
|
},
|
1812
|
1810
|
function (e) {
|
1813
|
1811
|
console.error('setRemoteDescription error', e);
|
|
@@ -1816,7 +1814,7 @@ JingleSession.prototype.setRemoteDescription = function (elem, desctype) {
|
1816
|
1814
|
};
|
1817
|
1815
|
|
1818
|
1816
|
JingleSession.prototype.addIceCandidate = function (elem) {
|
1819
|
|
- var obj = this;
|
|
1817
|
+ var self = this;
|
1820
|
1818
|
if (this.peerconnection.signalingState == 'closed') {
|
1821
|
1819
|
return;
|
1822
|
1820
|
}
|
|
@@ -1841,19 +1839,19 @@ JingleSession.prototype.addIceCandidate = function (elem) {
|
1841
|
1839
|
}
|
1842
|
1840
|
// then add things like ice and dtls from remote candidate
|
1843
|
1841
|
elem.each(function () {
|
1844
|
|
- for (var i = 0; i < obj.remoteSDP.media.length; i++) {
|
1845
|
|
- if (SDPUtil.find_line(obj.remoteSDP.media[i], 'a=mid:' + $(this).attr('name')) ||
|
1846
|
|
- obj.remoteSDP.media[i].indexOf('m=' + $(this).attr('name')) === 0) {
|
1847
|
|
- if (!SDPUtil.find_line(obj.remoteSDP.media[i], 'a=ice-ufrag:')) {
|
|
1842
|
+ for (var i = 0; i < self.remoteSDP.media.length; i++) {
|
|
1843
|
+ if (SDPUtil.find_line(self.remoteSDP.media[i], 'a=mid:' + $(this).attr('name')) ||
|
|
1844
|
+ self.remoteSDP.media[i].indexOf('m=' + $(this).attr('name')) === 0) {
|
|
1845
|
+ if (!SDPUtil.find_line(self.remoteSDP.media[i], 'a=ice-ufrag:')) {
|
1848
|
1846
|
var tmp = $(this).find('transport');
|
1849
|
|
- obj.remoteSDP.media[i] += 'a=ice-ufrag:' + tmp.attr('ufrag') + '\r\n';
|
1850
|
|
- obj.remoteSDP.media[i] += 'a=ice-pwd:' + tmp.attr('pwd') + '\r\n';
|
|
1847
|
+ self.remoteSDP.media[i] += 'a=ice-ufrag:' + tmp.attr('ufrag') + '\r\n';
|
|
1848
|
+ self.remoteSDP.media[i] += 'a=ice-pwd:' + tmp.attr('pwd') + '\r\n';
|
1851
|
1849
|
tmp = $(this).find('transport>fingerprint');
|
1852
|
1850
|
if (tmp.length) {
|
1853
|
|
- obj.remoteSDP.media[i] += 'a=fingerprint:' + tmp.attr('hash') + ' ' + tmp.text() + '\r\n';
|
|
1851
|
+ self.remoteSDP.media[i] += 'a=fingerprint:' + tmp.attr('hash') + ' ' + tmp.text() + '\r\n';
|
1854
|
1852
|
} else {
|
1855
|
1853
|
console.log('no dtls fingerprint (webrtc issue #1718?)');
|
1856
|
|
- obj.remoteSDP.media[i] += 'a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:BAADBAADBAADBAADBAADBAADBAADBAADBAADBAAD\r\n';
|
|
1854
|
+ self.remoteSDP.media[i] += 'a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:BAADBAADBAADBAADBAADBAADBAADBAADBAADBAAD\r\n';
|
1857
|
1855
|
}
|
1858
|
1856
|
break;
|
1859
|
1857
|
}
|
|
@@ -1872,12 +1870,17 @@ JingleSession.prototype.addIceCandidate = function (elem) {
|
1872
|
1870
|
if (iscomplete) {
|
1873
|
1871
|
console.log('setting pranswer');
|
1874
|
1872
|
try {
|
1875
|
|
- this.peerconnection.setRemoteDescription(new RTCSessionDescription({type: 'pranswer', sdp: this.remoteSDP.raw }));
|
|
1873
|
+ this.peerconnection.setRemoteDescription(new RTCSessionDescription({type: 'pranswer', sdp: this.remoteSDP.raw }),
|
|
1874
|
+ function() {
|
|
1875
|
+ },
|
|
1876
|
+ function(e) {
|
|
1877
|
+ console.log('setRemoteDescription pranswer failed', e.toString());
|
|
1878
|
+ });
|
1876
|
1879
|
} catch (e) {
|
1877
|
1880
|
console.error('setting pranswer failed', e);
|
1878
|
1881
|
}
|
1879
|
1882
|
} else {
|
1880
|
|
- console.log('not yet setting pranswer');
|
|
1883
|
+ //console.log('not yet setting pranswer');
|
1881
|
1884
|
}
|
1882
|
1885
|
}
|
1883
|
1886
|
// operate on each content element
|
|
@@ -1885,17 +1888,17 @@ JingleSession.prototype.addIceCandidate = function (elem) {
|
1885
|
1888
|
// would love to deactivate this, but firefox still requires it
|
1886
|
1889
|
var idx = -1;
|
1887
|
1890
|
var i;
|
1888
|
|
- for (i = 0; i < obj.remoteSDP.media.length; i++) {
|
1889
|
|
- if (SDPUtil.find_line(obj.remoteSDP.media[i], 'a=mid:' + $(this).attr('name')) ||
|
1890
|
|
- obj.remoteSDP.media[i].indexOf('m=' + $(this).attr('name')) === 0) {
|
|
1891
|
+ for (i = 0; i < self.remoteSDP.media.length; i++) {
|
|
1892
|
+ if (SDPUtil.find_line(self.remoteSDP.media[i], 'a=mid:' + $(this).attr('name')) ||
|
|
1893
|
+ self.remoteSDP.media[i].indexOf('m=' + $(this).attr('name')) === 0) {
|
1891
|
1894
|
idx = i;
|
1892
|
1895
|
break;
|
1893
|
1896
|
}
|
1894
|
1897
|
}
|
1895
|
1898
|
if (idx == -1) { // fall back to localdescription
|
1896
|
|
- for (i = 0; i < obj.localSDP.media.length; i++) {
|
1897
|
|
- if (SDPUtil.find_line(obj.localSDP.media[i], 'a=mid:' + $(this).attr('name')) ||
|
1898
|
|
- obj.localSDP.media[i].indexOf('m=' + $(this).attr('name')) === 0) {
|
|
1899
|
+ for (i = 0; i < self.localSDP.media.length; i++) {
|
|
1900
|
+ if (SDPUtil.find_line(self.localSDP.media[i], 'a=mid:' + $(this).attr('name')) ||
|
|
1901
|
+ self.localSDP.media[i].indexOf('m=' + $(this).attr('name')) === 0) {
|
1899
|
1902
|
idx = i;
|
1900
|
1903
|
break;
|
1901
|
1904
|
}
|
|
@@ -1910,7 +1913,7 @@ JingleSession.prototype.addIceCandidate = function (elem) {
|
1910
|
1913
|
sdpMid: name,
|
1911
|
1914
|
candidate: line});
|
1912
|
1915
|
try {
|
1913
|
|
- obj.peerconnection.addIceCandidate(candidate);
|
|
1916
|
+ self.peerconnection.addIceCandidate(candidate);
|
1914
|
1917
|
} catch (e) {
|
1915
|
1918
|
console.error('addIceCandidate failed', e.toString(), line);
|
1916
|
1919
|
}
|
|
@@ -1919,11 +1922,11 @@ JingleSession.prototype.addIceCandidate = function (elem) {
|
1919
|
1922
|
};
|
1920
|
1923
|
|
1921
|
1924
|
JingleSession.prototype.sendAnswer = function (provisional) {
|
1922
|
|
- console.log('createAnswer', provisional);
|
1923
|
|
- var ob = this;
|
|
1925
|
+ //console.log('createAnswer', provisional);
|
|
1926
|
+ var self = this;
|
1924
|
1927
|
this.peerconnection.createAnswer(
|
1925
|
1928
|
function (sdp) {
|
1926
|
|
- ob.createdAnswer(sdp, provisional);
|
|
1929
|
+ self.createdAnswer(sdp, provisional);
|
1927
|
1930
|
},
|
1928
|
1931
|
function (e) {
|
1929
|
1932
|
console.error('createAnswer failed', e);
|
|
@@ -1933,9 +1936,9 @@ JingleSession.prototype.sendAnswer = function (provisional) {
|
1933
|
1936
|
};
|
1934
|
1937
|
|
1935
|
1938
|
JingleSession.prototype.createdAnswer = function (sdp, provisional) {
|
1936
|
|
- console.log('createAnswer callback');
|
|
1939
|
+ //console.log('createAnswer callback');
|
1937
|
1940
|
console.log(sdp);
|
1938
|
|
- var ob = this;
|
|
1941
|
+ var self = this;
|
1939
|
1942
|
this.localSDP = new SDP(sdp.sdp);
|
1940
|
1943
|
//this.localSDP.mangle();
|
1941
|
1944
|
this.usepranswer = provisional === true;
|
|
@@ -1953,7 +1956,7 @@ JingleSession.prototype.createdAnswer = function (sdp, provisional) {
|
1953
|
1956
|
function () {
|
1954
|
1957
|
var ack = {};
|
1955
|
1958
|
ack.source = 'answer';
|
1956
|
|
- $(document).trigger('ack.jingle', [ob.sid, ack]);
|
|
1959
|
+ $(document).trigger('ack.jingle', [self.sid, ack]);
|
1957
|
1960
|
},
|
1958
|
1961
|
function (stanza) {
|
1959
|
1962
|
var error = ($(stanza).find('error').length) ? {
|
|
@@ -1961,7 +1964,7 @@ JingleSession.prototype.createdAnswer = function (sdp, provisional) {
|
1961
|
1964
|
reason: $(stanza).find('error :first')[0].tagName,
|
1962
|
1965
|
}:{};
|
1963
|
1966
|
error.source = 'answer';
|
1964
|
|
- $(document).trigger('error.jingle', [ob.sid, error]);
|
|
1967
|
+ $(document).trigger('error.jingle', [self.sid, error]);
|
1965
|
1968
|
},
|
1966
|
1969
|
10000);
|
1967
|
1970
|
} else {
|
|
@@ -1975,7 +1978,7 @@ JingleSession.prototype.createdAnswer = function (sdp, provisional) {
|
1975
|
1978
|
sdp.sdp = this.localSDP.raw;
|
1976
|
1979
|
this.peerconnection.setLocalDescription(sdp,
|
1977
|
1980
|
function () {
|
1978
|
|
- console.log('setLocalDescription success');
|
|
1981
|
+ //console.log('setLocalDescription success');
|
1979
|
1982
|
},
|
1980
|
1983
|
function (e) {
|
1981
|
1984
|
console.error('setLocalDescription failed', e);
|
|
@@ -1993,7 +1996,7 @@ JingleSession.prototype.createdAnswer = function (sdp, provisional) {
|
1993
|
1996
|
};
|
1994
|
1997
|
|
1995
|
1998
|
JingleSession.prototype.sendTerminate = function (reason, text) {
|
1996
|
|
- var obj = this,
|
|
1999
|
+ var self = this,
|
1997
|
2000
|
term = $iq({to: this.peerjid,
|
1998
|
2001
|
type: 'set'})
|
1999
|
2002
|
.c('jingle', {xmlns: 'urn:xmpp:jingle:1',
|
|
@@ -2009,19 +2012,19 @@ JingleSession.prototype.sendTerminate = function (reason, text) {
|
2009
|
2012
|
|
2010
|
2013
|
this.connection.sendIQ(term,
|
2011
|
2014
|
function () {
|
2012
|
|
- obj.peerconnection.close();
|
2013
|
|
- obj.peerconnection = null;
|
2014
|
|
- obj.terminate();
|
|
2015
|
+ self.peerconnection.close();
|
|
2016
|
+ self.peerconnection = null;
|
|
2017
|
+ self.terminate();
|
2015
|
2018
|
var ack = {};
|
2016
|
2019
|
ack.source = 'terminate';
|
2017
|
|
- $(document).trigger('ack.jingle', [obj.sid, ack]);
|
|
2020
|
+ $(document).trigger('ack.jingle', [self.sid, ack]);
|
2018
|
2021
|
},
|
2019
|
2022
|
function (stanza) {
|
2020
|
2023
|
var error = ($(stanza).find('error').length) ? {
|
2021
|
2024
|
code: $(stanza).find('error').attr('code'),
|
2022
|
2025
|
reason: $(stanza).find('error :first')[0].tagName,
|
2023
|
2026
|
}:{};
|
2024
|
|
- $(document).trigger('ack.jingle', [obj.sid, error]);
|
|
2027
|
+ $(document).trigger('ack.jingle', [self.sid, error]);
|
2025
|
2028
|
},
|
2026
|
2029
|
10000);
|
2027
|
2030
|
if (this.statsinterval !== null) {
|
|
@@ -2036,7 +2039,7 @@ JingleSession.prototype.addSource = function (elem) {
|
2036
|
2039
|
console.log('ice', this.peerconnection.iceConnectionState);
|
2037
|
2040
|
var sdp = new SDP(this.peerconnection.remoteDescription.sdp);
|
2038
|
2041
|
|
2039
|
|
- var ob = this;
|
|
2042
|
+ var self = this;
|
2040
|
2043
|
$(elem).each(function (idx, content) {
|
2041
|
2044
|
var name = $(content).attr('name');
|
2042
|
2045
|
var lines = '';
|
|
@@ -2050,13 +2053,12 @@ JingleSession.prototype.addSource = function (elem) {
|
2050
|
2053
|
lines += '\r\n';
|
2051
|
2054
|
});
|
2052
|
2055
|
});
|
2053
|
|
- console.log(name, lines);
|
2054
|
2056
|
sdp.media.forEach(function(media, idx) {
|
2055
|
2057
|
if (!SDPUtil.find_line(media, 'a=mid:' + name))
|
2056
|
2058
|
return;
|
2057
|
2059
|
sdp.media[idx] += lines;
|
2058
|
|
- if (!ob.addssrc[idx]) ob.addssrc[idx] = '';
|
2059
|
|
- ob.addssrc[idx] += lines;
|
|
2060
|
+ if (!self.addssrc[idx]) self.addssrc[idx] = '';
|
|
2061
|
+ self.addssrc[idx] += lines;
|
2060
|
2062
|
});
|
2061
|
2063
|
sdp.raw = sdp.session + sdp.media.join('');
|
2062
|
2064
|
});
|
|
@@ -2068,7 +2070,7 @@ JingleSession.prototype.removeSource = function (elem) {
|
2068
|
2070
|
console.log('ice', this.peerconnection.iceConnectionState);
|
2069
|
2071
|
var sdp = new SDP(this.peerconnection.remoteDescription.sdp);
|
2070
|
2072
|
|
2071
|
|
- var ob = this;
|
|
2073
|
+ var self = this;
|
2072
|
2074
|
$(elem).each(function (idx, content) {
|
2073
|
2075
|
var name = $(content).attr('name');
|
2074
|
2076
|
var lines = '';
|
|
@@ -2082,39 +2084,34 @@ JingleSession.prototype.removeSource = function (elem) {
|
2082
|
2084
|
lines += '\r\n';
|
2083
|
2085
|
});
|
2084
|
2086
|
});
|
2085
|
|
- console.log(name, lines);
|
2086
|
2087
|
sdp.media.forEach(function(media, idx) {
|
2087
|
2088
|
if (!SDPUtil.find_line(media, 'a=mid:' + name))
|
2088
|
2089
|
return;
|
2089
|
2090
|
sdp.media[idx] += lines;
|
2090
|
|
- if (!ob.addssrc[idx]) ob.removessrc[idx] = '';
|
2091
|
|
- ob.removessrc[idx] += lines;
|
|
2091
|
+ if (!self.addssrc[idx]) self.removessrc[idx] = '';
|
|
2092
|
+ self.removessrc[idx] += lines;
|
2092
|
2093
|
});
|
2093
|
2094
|
sdp.raw = sdp.session + sdp.media.join('');
|
2094
|
2095
|
});
|
2095
|
|
- console.log(this.removessrc);
|
2096
|
2096
|
this.modifySources();
|
2097
|
2097
|
};
|
2098
|
2098
|
|
2099
|
|
-
|
2100
|
|
-
|
2101
|
2099
|
JingleSession.prototype.modifySources = function() {
|
2102
|
|
- var ob = this;
|
|
2100
|
+ var self = this;
|
2103
|
2101
|
if (!(this.addssrc.length || this.removessrc.length)) return;
|
2104
|
2102
|
if (this.peerconnection.signalingState == 'closed') return;
|
2105
|
2103
|
if (!(this.peerconnection.signalingState == 'stable' && this.peerconnection.iceConnectionState == 'connected')) {
|
2106
|
2104
|
console.warn('modifySources not yet', this.peerconnection.signalingState, this.peerconnection.iceConnectionState);
|
2107
|
2105
|
this.wait = true;
|
2108
|
|
- window.setTimeout(function() { ob.modifySources(); }, 250);
|
|
2106
|
+ window.setTimeout(function() { self.modifySources(); }, 250);
|
2109
|
2107
|
return;
|
2110
|
2108
|
}
|
2111
|
2109
|
if (this.wait) {
|
2112
|
|
- window.setTimeout(function() { ob.modifySources(); }, 2500);
|
|
2110
|
+ window.setTimeout(function() { self.modifySources(); }, 2500);
|
2113
|
2111
|
this.wait = false;
|
2114
|
2112
|
return;
|
2115
|
2113
|
}
|
2116
|
2114
|
|
2117
|
|
- console.log('ice', this.peerconnection.iceConnectionState);
|
2118
|
2115
|
var sdp = new SDP(this.peerconnection.remoteDescription.sdp);
|
2119
|
2116
|
|
2120
|
2117
|
// add sources
|
|
@@ -2136,13 +2133,11 @@ JingleSession.prototype.modifySources = function() {
|
2136
|
2133
|
sdp.raw = sdp.session + sdp.media.join('');
|
2137
|
2134
|
this.peerconnection.setRemoteDescription(new RTCSessionDescription({type: 'offer', sdp: sdp.raw}),
|
2138
|
2135
|
function() {
|
2139
|
|
- console.log('modify ok');
|
2140
|
|
- ob.peerconnection.createAnswer(
|
|
2136
|
+ self.peerconnection.createAnswer(
|
2141
|
2137
|
function(modifiedAnswer) {
|
2142
|
|
- console.log('modified answer...');
|
2143
|
|
- ob.peerconnection.setLocalDescription(modifiedAnswer,
|
|
2138
|
+ self.peerconnection.setLocalDescription(modifiedAnswer,
|
2144
|
2139
|
function() {
|
2145
|
|
- console.log('modified setLocalDescription ok');
|
|
2140
|
+ //console.log('modified setLocalDescription ok');
|
2146
|
2141
|
},
|
2147
|
2142
|
function(error) {
|
2148
|
2143
|
console.log('modified setLocalDescription failed');
|
|
@@ -2187,7 +2182,7 @@ JingleSession.prototype.sendRinging = function () {
|
2187
|
2182
|
};
|
2188
|
2183
|
|
2189
|
2184
|
JingleSession.prototype.getStats = function (interval) {
|
2190
|
|
- var ob = this;
|
|
2185
|
+ var self = this;
|
2191
|
2186
|
var recv = {audio: 0, video: 0};
|
2192
|
2187
|
var lost = {audio: 0, video: 0};
|
2193
|
2188
|
var lastrecv = {audio: 0, video: 0};
|
|
@@ -2195,8 +2190,8 @@ JingleSession.prototype.getStats = function (interval) {
|
2195
|
2190
|
var loss = {audio: 0, video: 0};
|
2196
|
2191
|
var delta = {audio: 0, video: 0};
|
2197
|
2192
|
this.statsinterval = window.setInterval(function () {
|
2198
|
|
- if (ob && ob.peerconnection && ob.peerconnection.getStats) {
|
2199
|
|
- ob.peerconnection.getStats(function (stats) {
|
|
2193
|
+ if (self && self.peerconnection && self.peerconnection.getStats) {
|
|
2194
|
+ self.peerconnection.getStats(function (stats) {
|
2200
|
2195
|
var results = stats.result();
|
2201
|
2196
|
// TODO: there are so much statistics you can get from this..
|
2202
|
2197
|
for (var i = 0; i < results.length; ++i) {
|
|
@@ -2225,7 +2220,7 @@ JingleSession.prototype.getStats = function (interval) {
|
2225
|
2220
|
delta.video = recv.video - lastrecv.video;
|
2226
|
2221
|
loss.audio = (delta.audio > 0) ? Math.ceil(100 * (lost.audio - lastlost.audio) / delta.audio) : 0;
|
2227
|
2222
|
loss.video = (delta.video > 0) ? Math.ceil(100 * (lost.video - lastlost.video) / delta.video) : 0;
|
2228
|
|
- $(document).trigger('packetloss.jingle', [ob.sid, loss]);
|
|
2223
|
+ $(document).trigger('packetloss.jingle', [self.sid, loss]);
|
2229
|
2224
|
});
|
2230
|
2225
|
}
|
2231
|
2226
|
}, interval || 3000);
|