You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

colibri.focus.js 43KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  1. /* colibri.js -- a COLIBRI focus
  2. * The colibri spec has been submitted to the XMPP Standards Foundation
  3. * for publications as a XMPP extensions:
  4. * http://xmpp.org/extensions/inbox/colibri.html
  5. *
  6. * colibri.js is a participating focus, i.e. the focus participates
  7. * in the conference. The conference itself can be ad-hoc, through a
  8. * MUC, through PubSub, etc.
  9. *
  10. * colibri.js relies heavily on the strophe.jingle library available
  11. * from https://github.com/ESTOS/strophe.jingle
  12. * and interoperates with the Jitsi videobridge available from
  13. * https://jitsi.org/Projects/JitsiVideobridge
  14. */
  15. /*
  16. Copyright (c) 2013 ESTOS GmbH
  17. Permission is hereby granted, free of charge, to any person obtaining a copy
  18. of this software and associated documentation files (the "Software"), to deal
  19. in the Software without restriction, including without limitation the rights
  20. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  21. copies of the Software, and to permit persons to whom the Software is
  22. furnished to do so, subject to the following conditions:
  23. The above copyright notice and this permission notice shall be included in
  24. all copies or substantial portions of the Software.
  25. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  26. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  27. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  28. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  29. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  30. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  31. THE SOFTWARE.
  32. */
  33. /* jshint -W117 */
  34. ColibriFocus.prototype = Object.create(SessionBase.prototype);
  35. function ColibriFocus(connection, bridgejid) {
  36. SessionBase.call(this, connection, Math.random().toString(36).substr(2, 12));
  37. this.bridgejid = bridgejid;
  38. this.peers = [];
  39. this.confid = null;
  40. /**
  41. * Local XMPP resource used to join the multi user chat.
  42. * @type {*}
  43. */
  44. this.myMucResource = Strophe.getResourceFromJid(connection.emuc.myroomjid);
  45. /**
  46. * Default channel expire value in seconds.
  47. * @type {number}
  48. */
  49. this.channelExpire = 60;
  50. // media types of the conference
  51. if (config.openSctp)
  52. {
  53. this.media = ['audio', 'video', 'data'];
  54. }
  55. else
  56. {
  57. this.media = ['audio', 'video'];
  58. }
  59. this.connection.jingle.sessions[this.sid] = this;
  60. this.mychannel = [];
  61. this.channels = [];
  62. this.remotessrc = {};
  63. // container for candidates from the focus
  64. // gathered before confid is known
  65. this.drip_container = [];
  66. // silly wait flag
  67. this.wait = true;
  68. }
  69. // creates a conferences with an initial set of peers
  70. ColibriFocus.prototype.makeConference = function (peers) {
  71. var self = this;
  72. if (this.confid !== null) {
  73. console.error('makeConference called twice? Ignoring...');
  74. // FIXME: just invite peers?
  75. return;
  76. }
  77. this.confid = 0; // !null
  78. this.peers = [];
  79. peers.forEach(function (peer) {
  80. self.peers.push(peer);
  81. self.channels.push([]);
  82. });
  83. this.peerconnection
  84. = new TraceablePeerConnection(
  85. this.connection.jingle.ice_config,
  86. this.connection.jingle.pc_constraints );
  87. if(this.connection.jingle.localAudio) {
  88. this.peerconnection.addStream(this.connection.jingle.localAudio);
  89. }
  90. if(this.connection.jingle.localVideo) {
  91. this.peerconnection.addStream(this.connection.jingle.localVideo);
  92. }
  93. this.peerconnection.oniceconnectionstatechange = function (event) {
  94. console.warn('ice connection state changed to', self.peerconnection.iceConnectionState);
  95. /*
  96. if (self.peerconnection.signalingState == 'stable' && self.peerconnection.iceConnectionState == 'connected') {
  97. console.log('adding new remote SSRCs from iceconnectionstatechange');
  98. window.setTimeout(function() { self.modifySources(); }, 1000);
  99. }
  100. */
  101. };
  102. this.peerconnection.onsignalingstatechange = function (event) {
  103. console.warn(self.peerconnection.signalingState);
  104. /*
  105. if (self.peerconnection.signalingState == 'stable' && self.peerconnection.iceConnectionState == 'connected') {
  106. console.log('adding new remote SSRCs from signalingstatechange');
  107. window.setTimeout(function() { self.modifySources(); }, 1000);
  108. }
  109. */
  110. };
  111. this.peerconnection.onaddstream = function (event) {
  112. // search the jid associated with this stream
  113. Object.keys(self.remotessrc).forEach(function (jid) {
  114. if (self.remotessrc[jid].join('\r\n').indexOf('mslabel:' + event.stream.id) != -1) {
  115. event.peerjid = jid;
  116. }
  117. });
  118. $(document).trigger('remotestreamadded.jingle', [event, self.sid]);
  119. };
  120. this.peerconnection.onicecandidate = function (event) {
  121. //console.log('focus onicecandidate', self.confid, new Date().getTime(), event.candidate);
  122. if (!event.candidate) {
  123. console.log('end of candidates');
  124. return;
  125. }
  126. self.sendIceCandidate(event.candidate);
  127. };
  128. this._makeConference();
  129. /*
  130. this.peerconnection.createOffer(
  131. function (offer) {
  132. self.peerconnection.setLocalDescription(
  133. offer,
  134. function () {
  135. // success
  136. $(document).trigger('setLocalDescription.jingle', [self.sid]);
  137. // FIXME: could call _makeConference here and trickle candidates later
  138. self._makeConference();
  139. },
  140. function (error) {
  141. console.log('setLocalDescription failed', error);
  142. }
  143. );
  144. },
  145. function (error) {
  146. console.warn(error);
  147. }
  148. );
  149. */
  150. };
  151. ColibriFocus.prototype._makeConference = function () {
  152. var self = this;
  153. var elem = $iq({to: this.bridgejid, type: 'get'});
  154. elem.c('conference', {xmlns: 'http://jitsi.org/protocol/colibri'});
  155. this.media.forEach(function (name) {
  156. var isData = name === 'data';
  157. var channel = isData ? 'sctpconnection' : 'channel';
  158. elem.c('content', {name: name});
  159. elem.c(channel, {
  160. initiator: 'true',
  161. expire: '15',
  162. endpoint: self.myMucResource
  163. });
  164. if (isData)
  165. elem.attrs({port: 5000});
  166. elem.up();// end of channel
  167. for (var j = 0; j < self.peers.length; j++) {
  168. elem.c(channel, {
  169. initiator: 'true',
  170. expire: '15',
  171. endpoint: self.peers[j].substr(1 + self.peers[j].lastIndexOf('/'))
  172. });
  173. if (isData)
  174. elem.attrs({port: 5000});
  175. elem.up(); // end of channel
  176. }
  177. elem.up(); // end of content
  178. });
  179. /*
  180. var localSDP = new SDP(this.peerconnection.localDescription.sdp);
  181. localSDP.media.forEach(function (media, channel) {
  182. var name = SDPUtil.parse_mline(media.split('\r\n')[0]).media;
  183. elem.c('content', {name: name});
  184. elem.c('channel', {initiator: 'false', expire: '15'});
  185. // FIXME: should reuse code from .toJingle
  186. var mline = SDPUtil.parse_mline(media.split('\r\n')[0]);
  187. for (var j = 0; j < mline.fmt.length; j++) {
  188. var rtpmap = SDPUtil.find_line(media, 'a=rtpmap:' + mline.fmt[j]);
  189. elem.c('payload-type', SDPUtil.parse_rtpmap(rtpmap));
  190. elem.up();
  191. }
  192. localSDP.TransportToJingle(channel, elem);
  193. elem.up(); // end of channel
  194. for (j = 0; j < self.peers.length; j++) {
  195. elem.c('channel', {initiator: 'true', expire:'15' }).up();
  196. }
  197. elem.up(); // end of content
  198. });
  199. */
  200. this.connection.sendIQ(elem,
  201. function (result) {
  202. self.createdConference(result);
  203. },
  204. function (error) {
  205. console.warn(error);
  206. }
  207. );
  208. };
  209. // callback when a conference was created
  210. ColibriFocus.prototype.createdConference = function (result) {
  211. console.log('created a conference on the bridge');
  212. var self = this;
  213. var tmp;
  214. this.confid = $(result).find('>conference').attr('id');
  215. var remotecontents = $(result).find('>conference>content').get();
  216. var numparticipants = 0;
  217. for (var i = 0; i < remotecontents.length; i++)
  218. {
  219. var contentName = $(remotecontents[i]).attr('name');
  220. var channelName
  221. = contentName !== 'data' ? '>channel' : '>sctpconnection';
  222. tmp = $(remotecontents[i]).find(channelName).get();
  223. this.mychannel.push($(tmp.shift()));
  224. numparticipants = tmp.length;
  225. for (j = 0; j < tmp.length; j++) {
  226. if (this.channels[j] === undefined) {
  227. this.channels[j] = [];
  228. }
  229. this.channels[j].push(tmp[j]);
  230. }
  231. }
  232. console.log('remote channels', this.channels);
  233. // Notify that the focus has created the conference on the bridge
  234. $(document).trigger('conferenceCreated.jingle', [self]);
  235. var bridgeSDP = new SDP(
  236. 'v=0\r\n' +
  237. 'o=- 5151055458874951233 2 IN IP4 127.0.0.1\r\n' +
  238. 's=-\r\n' +
  239. 't=0 0\r\n' +
  240. /* Audio */
  241. 'm=audio 1 RTP/SAVPF 111 103 104 0 8 106 105 13 126\r\n' +
  242. 'c=IN IP4 0.0.0.0\r\n' +
  243. 'a=rtcp:1 IN IP4 0.0.0.0\r\n' +
  244. 'a=mid:audio\r\n' +
  245. 'a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level\r\n' +
  246. 'a=sendrecv\r\n' +
  247. 'a=rtpmap:111 opus/48000/2\r\n' +
  248. 'a=fmtp:111 minptime=10\r\n' +
  249. 'a=rtpmap:103 ISAC/16000\r\n' +
  250. 'a=rtpmap:104 ISAC/32000\r\n' +
  251. 'a=rtpmap:0 PCMU/8000\r\n' +
  252. 'a=rtpmap:8 PCMA/8000\r\n' +
  253. 'a=rtpmap:106 CN/32000\r\n' +
  254. 'a=rtpmap:105 CN/16000\r\n' +
  255. 'a=rtpmap:13 CN/8000\r\n' +
  256. 'a=rtpmap:126 telephone-event/8000\r\n' +
  257. 'a=maxptime:60\r\n' +
  258. /* Video */
  259. 'm=video 1 RTP/SAVPF 100 116 117\r\n' +
  260. 'c=IN IP4 0.0.0.0\r\n' +
  261. 'a=rtcp:1 IN IP4 0.0.0.0\r\n' +
  262. 'a=mid:video\r\n' +
  263. 'a=extmap:2 urn:ietf:params:rtp-hdrext:toffset\r\n' +
  264. 'a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\n' +
  265. 'a=sendrecv\r\n' +
  266. 'a=rtpmap:100 VP8/90000\r\n' +
  267. 'a=rtcp-fb:100 ccm fir\r\n' +
  268. 'a=rtcp-fb:100 nack\r\n' +
  269. 'a=rtcp-fb:100 goog-remb\r\n' +
  270. 'a=rtpmap:116 red/90000\r\n' +
  271. 'a=rtpmap:117 ulpfec/90000\r\n' +
  272. /* Data SCTP */
  273. (config.openSctp ?
  274. 'm=application 1 DTLS/SCTP 5000\r\n' +
  275. 'c=IN IP4 0.0.0.0\r\n' +
  276. 'a=sctpmap:5000 webrtc-datachannel\r\n' +
  277. 'a=mid:data\r\n'
  278. : '')
  279. );
  280. bridgeSDP.media.length = this.mychannel.length;
  281. var channel;
  282. /*
  283. for (channel = 0; channel < bridgeSDP.media.length; channel++) {
  284. bridgeSDP.media[channel] = '';
  285. // unchanged lines
  286. bridgeSDP.media[channel] += SDPUtil.find_line(localSDP.media[channel], 'm=') + '\r\n';
  287. bridgeSDP.media[channel] += SDPUtil.find_line(localSDP.media[channel], 'c=') + '\r\n';
  288. if (SDPUtil.find_line(localSDP.media[channel], 'a=rtcp:')) {
  289. bridgeSDP.media[channel] += SDPUtil.find_line(localSDP.media[channel], 'a=rtcp:') + '\r\n';
  290. }
  291. if (SDPUtil.find_line(localSDP.media[channel], 'a=mid:')) {
  292. bridgeSDP.media[channel] += SDPUtil.find_line(localSDP.media[channel], 'a=mid:') + '\r\n';
  293. }
  294. if (SDPUtil.find_line(localSDP.media[channel], 'a=sendrecv')) {
  295. bridgeSDP.media[channel] += 'a=sendrecv\r\n';
  296. }
  297. if (SDPUtil.find_line(localSDP.media[channel], 'a=extmap:')) {
  298. bridgeSDP.media[channel] += SDPUtil.find_lines(localSDP.media[channel], 'a=extmap:').join('\r\n') + '\r\n';
  299. }
  300. // FIXME: should look at m-line and group the ids together
  301. if (SDPUtil.find_line(localSDP.media[channel], 'a=rtpmap:')) {
  302. bridgeSDP.media[channel] += SDPUtil.find_lines(localSDP.media[channel], 'a=rtpmap:').join('\r\n') + '\r\n';
  303. }
  304. if (SDPUtil.find_line(localSDP.media[channel], 'a=fmtp:')) {
  305. bridgeSDP.media[channel] += SDPUtil.find_lines(localSDP.media[channel], 'a=fmtp:').join('\r\n') + '\r\n';
  306. }
  307. if (SDPUtil.find_line(localSDP.media[channel], 'a=rtcp-fb:')) {
  308. bridgeSDP.media[channel] += SDPUtil.find_lines(localSDP.media[channel], 'a=rtcp-fb:').join('\r\n') + '\r\n';
  309. }
  310. // FIXME: changed lines -- a=sendrecv direction, a=setup direction
  311. }
  312. */
  313. for (channel = 0; channel < bridgeSDP.media.length; channel++) {
  314. // get the mixed ssrc
  315. tmp = $(this.mychannel[channel]).find('>source[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]');
  316. // FIXME: check rtp-level-relay-type
  317. var isData = bridgeSDP.media[channel].indexOf('application') !== -1;
  318. if (!isData && tmp.length)
  319. {
  320. bridgeSDP.media[channel] += 'a=ssrc:' + tmp.attr('ssrc') + ' ' + 'cname:mixed' + '\r\n';
  321. bridgeSDP.media[channel] += 'a=ssrc:' + tmp.attr('ssrc') + ' ' + 'label:mixedlabela0' + '\r\n';
  322. bridgeSDP.media[channel] += 'a=ssrc:' + tmp.attr('ssrc') + ' ' + 'msid:mixedmslabel mixedlabela0' + '\r\n';
  323. bridgeSDP.media[channel] += 'a=ssrc:' + tmp.attr('ssrc') + ' ' + 'mslabel:mixedmslabel' + '\r\n';
  324. }
  325. else if (!isData)
  326. {
  327. // make chrome happy... '3735928559' == 0xDEADBEEF
  328. // FIXME: this currently appears as two streams, should be one
  329. bridgeSDP.media[channel] += 'a=ssrc:' + '3735928559' + ' ' + 'cname:mixed' + '\r\n';
  330. bridgeSDP.media[channel] += 'a=ssrc:' + '3735928559' + ' ' + 'label:mixedlabelv0' + '\r\n';
  331. bridgeSDP.media[channel] += 'a=ssrc:' + '3735928559' + ' ' + 'msid:mixedmslabel mixedlabelv0' + '\r\n';
  332. bridgeSDP.media[channel] += 'a=ssrc:' + '3735928559' + ' ' + 'mslabel:mixedmslabel' + '\r\n';
  333. }
  334. // FIXME: should take code from .fromJingle
  335. tmp = $(this.mychannel[channel]).find('>transport[xmlns="urn:xmpp:jingle:transports:ice-udp:1"]');
  336. if (tmp.length) {
  337. bridgeSDP.media[channel] += 'a=ice-ufrag:' + tmp.attr('ufrag') + '\r\n';
  338. bridgeSDP.media[channel] += 'a=ice-pwd:' + tmp.attr('pwd') + '\r\n';
  339. tmp.find('>candidate').each(function () {
  340. bridgeSDP.media[channel] += SDPUtil.candidateFromJingle(this);
  341. });
  342. tmp = tmp.find('>fingerprint');
  343. if (tmp.length) {
  344. bridgeSDP.media[channel] += 'a=fingerprint:' + tmp.attr('hash') + ' ' + tmp.text() + '\r\n';
  345. bridgeSDP.media[channel] += 'a=setup:actpass\r\n'; // offer so always actpass
  346. }
  347. }
  348. }
  349. bridgeSDP.raw = bridgeSDP.session + bridgeSDP.media.join('');
  350. this.peerconnection.setRemoteDescription(
  351. new RTCSessionDescription({type: 'offer', sdp: bridgeSDP.raw}),
  352. function () {
  353. console.log('setRemoteDescription success');
  354. self.peerconnection.createAnswer(
  355. function (answer) {
  356. self.peerconnection.setLocalDescription(answer,
  357. function () {
  358. console.log('setLocalDescription succeded.');
  359. // make sure our presence is updated
  360. $(document).trigger('setLocalDescription.jingle', [self.sid]);
  361. var elem = $iq({to: self.bridgejid, type: 'get'});
  362. elem.c('conference', {xmlns: 'http://jitsi.org/protocol/colibri', id: self.confid});
  363. var localSDP = new SDP(self.peerconnection.localDescription.sdp);
  364. localSDP.media.forEach(function (media, channel) {
  365. var name = SDPUtil.parse_mid(SDPUtil.find_line(media, 'a=mid:'));
  366. elem.c('content', {name: name});
  367. var mline = SDPUtil.parse_mline(media.split('\r\n')[0]);
  368. if (name !== 'data')
  369. {
  370. elem.c('channel', {
  371. initiator: 'true',
  372. expire: self.channelExpire,
  373. id: self.mychannel[channel].attr('id'),
  374. endpoint: self.myMucResource
  375. });
  376. // FIXME: should reuse code from .toJingle
  377. for (var j = 0; j < mline.fmt.length; j++)
  378. {
  379. var rtpmap = SDPUtil.find_line(media, 'a=rtpmap:' + mline.fmt[j]);
  380. if (rtpmap)
  381. {
  382. elem.c('payload-type', SDPUtil.parse_rtpmap(rtpmap));
  383. elem.up();
  384. }
  385. }
  386. }
  387. else
  388. {
  389. var sctpmap = SDPUtil.find_line(media, 'a=sctpmap:' + mline.fmt[0]);
  390. var sctpPort = SDPUtil.parse_sctpmap(sctpmap)[0];
  391. elem.c("sctpconnection",
  392. {
  393. initiator: 'true',
  394. expire: self.channelExpire,
  395. endpoint: self.myMucResource,
  396. port: sctpPort
  397. }
  398. );
  399. }
  400. localSDP.TransportToJingle(channel, elem);
  401. elem.up(); // end of channel
  402. elem.up(); // end of content
  403. });
  404. self.connection.sendIQ(elem,
  405. function (result) {
  406. // ...
  407. },
  408. function (error) {
  409. console.error(
  410. "ERROR setLocalDescription succeded",
  411. error, elem);
  412. }
  413. );
  414. // now initiate sessions
  415. for (var i = 0; i < numparticipants; i++) {
  416. self.initiate(self.peers[i], true);
  417. }
  418. // Notify we've created the conference
  419. $(document).trigger(
  420. 'conferenceCreated.jingle', self);
  421. },
  422. function (error) {
  423. console.warn('setLocalDescription failed.', error);
  424. }
  425. );
  426. },
  427. function (error) {
  428. console.warn('createAnswer failed.', error);
  429. }
  430. );
  431. /*
  432. for (var i = 0; i < numparticipants; i++) {
  433. self.initiate(self.peers[i], true);
  434. }
  435. */
  436. },
  437. function (error) {
  438. console.log('setRemoteDescription failed.', error);
  439. }
  440. );
  441. };
  442. // send a session-initiate to a new participant
  443. ColibriFocus.prototype.initiate = function (peer, isInitiator) {
  444. var participant = this.peers.indexOf(peer);
  445. console.log('tell', peer, participant);
  446. var sdp;
  447. if (this.peerconnection !== null && this.peerconnection.signalingState == 'stable') {
  448. sdp = new SDP(this.peerconnection.remoteDescription.sdp);
  449. var localSDP = new SDP(this.peerconnection.localDescription.sdp);
  450. // throw away stuff we don't want
  451. // not needed with static offer
  452. sdp.removeSessionLines('a=group:');
  453. sdp.removeSessionLines('a=msid-semantic:'); // FIXME: not mapped over jingle anyway...
  454. for (var i = 0; i < sdp.media.length; i++) {
  455. sdp.removeMediaLines(i, 'a=rtcp-mux');
  456. sdp.removeMediaLines(i, 'a=ssrc:');
  457. sdp.removeMediaLines(i, 'a=crypto:');
  458. sdp.removeMediaLines(i, 'a=candidate:');
  459. sdp.removeMediaLines(i, 'a=ice-options:google-ice');
  460. sdp.removeMediaLines(i, 'a=ice-ufrag:');
  461. sdp.removeMediaLines(i, 'a=ice-pwd:');
  462. sdp.removeMediaLines(i, 'a=fingerprint:');
  463. sdp.removeMediaLines(i, 'a=setup:');
  464. if (1) { //i > 0) { // not for audio FIXME: does not work as intended
  465. // re-add all remote a=ssrcs
  466. for (var jid in this.remotessrc) {
  467. if (jid == peer) continue;
  468. sdp.media[i] += this.remotessrc[jid][i];
  469. }
  470. // and local a=ssrc lines
  471. sdp.media[i] += SDPUtil.find_lines(localSDP.media[i], 'a=ssrc').join('\r\n') + '\r\n';
  472. }
  473. }
  474. sdp.raw = sdp.session + sdp.media.join('');
  475. } else {
  476. console.error('can not initiate a new session without a stable peerconnection');
  477. return;
  478. }
  479. // add stuff we got from the bridge
  480. for (var j = 0; j < sdp.media.length; j++) {
  481. var chan = $(this.channels[participant][j]);
  482. console.log('channel id', chan.attr('id'));
  483. tmp = chan.find('>source[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]');
  484. if (tmp.length) {
  485. sdp.media[j] += 'a=ssrc:' + tmp.attr('ssrc') + ' ' + 'cname:mixed' + '\r\n';
  486. sdp.media[j] += 'a=ssrc:' + tmp.attr('ssrc') + ' ' + 'label:mixedlabela0' + '\r\n';
  487. sdp.media[j] += 'a=ssrc:' + tmp.attr('ssrc') + ' ' + 'msid:mixedmslabel mixedlabela0' + '\r\n';
  488. sdp.media[j] += 'a=ssrc:' + tmp.attr('ssrc') + ' ' + 'mslabel:mixedmslabel' + '\r\n';
  489. }
  490. // No SSRCs for 'data', comes when j == 2
  491. else if (j < 2)
  492. {
  493. // make chrome happy... '3735928559' == 0xDEADBEEF
  494. sdp.media[j] += 'a=ssrc:' + '3735928559' + ' ' + 'cname:mixed' + '\r\n';
  495. sdp.media[j] += 'a=ssrc:' + '3735928559' + ' ' + 'label:mixedlabelv0' + '\r\n';
  496. sdp.media[j] += 'a=ssrc:' + '3735928559' + ' ' + 'msid:mixedmslabel mixedlabelv0' + '\r\n';
  497. sdp.media[j] += 'a=ssrc:' + '3735928559' + ' ' + 'mslabel:mixedmslabel' + '\r\n';
  498. }
  499. tmp = chan.find('>transport[xmlns="urn:xmpp:jingle:transports:ice-udp:1"]');
  500. if (tmp.length) {
  501. if (tmp.attr('ufrag'))
  502. sdp.media[j] += 'a=ice-ufrag:' + tmp.attr('ufrag') + '\r\n';
  503. if (tmp.attr('pwd'))
  504. sdp.media[j] += 'a=ice-pwd:' + tmp.attr('pwd') + '\r\n';
  505. // and the candidates...
  506. tmp.find('>candidate').each(function () {
  507. sdp.media[j] += SDPUtil.candidateFromJingle(this);
  508. });
  509. tmp = tmp.find('>fingerprint');
  510. if (tmp.length) {
  511. sdp.media[j] += 'a=fingerprint:' + tmp.attr('hash') + ' ' + tmp.text() + '\r\n';
  512. /*
  513. if (tmp.attr('direction')) {
  514. sdp.media[j] += 'a=setup:' + tmp.attr('direction') + '\r\n';
  515. }
  516. */
  517. sdp.media[j] += 'a=setup:actpass\r\n';
  518. }
  519. }
  520. }
  521. // make a new colibri session and configure it
  522. // FIXME: is it correct to use this.connection.jid when used in a MUC?
  523. var sess = new ColibriSession(this.connection.jid,
  524. Math.random().toString(36).substr(2, 12), // random string
  525. this.connection);
  526. sess.initiate(peer);
  527. sess.colibri = this;
  528. // We do not announce our audio per conference peer, so only video is set here
  529. sess.localVideo = this.connection.jingle.localVideo;
  530. sess.media_constraints = this.connection.jingle.media_constraints;
  531. sess.pc_constraints = this.connection.jingle.pc_constraints;
  532. sess.ice_config = this.connection.jingle.ice_config;
  533. this.connection.jingle.sessions[sess.sid] = sess;
  534. this.connection.jingle.jid2session[sess.peerjid] = sess;
  535. // send a session-initiate
  536. var init = $iq({to: peer, type: 'set'})
  537. .c('jingle',
  538. {xmlns: 'urn:xmpp:jingle:1',
  539. action: 'session-initiate',
  540. initiator: sess.me,
  541. sid: sess.sid
  542. }
  543. );
  544. sdp.toJingle(init, 'initiator');
  545. this.connection.sendIQ(init,
  546. function (res) {
  547. console.log('got result');
  548. },
  549. function (err) {
  550. console.log('got error');
  551. }
  552. );
  553. };
  554. // pull in a new participant into the conference
  555. ColibriFocus.prototype.addNewParticipant = function (peer) {
  556. var self = this;
  557. if (this.confid === 0 || !this.peerconnection.localDescription)
  558. {
  559. // bad state
  560. if (this.confid === 0)
  561. {
  562. console.error('confid does not exist yet, postponing', peer);
  563. }
  564. else
  565. {
  566. console.error('local description not ready yet, postponing', peer);
  567. }
  568. window.setTimeout(function () {
  569. self.addNewParticipant(peer);
  570. }, 250);
  571. return;
  572. }
  573. var index = this.channels.length;
  574. this.channels.push([]);
  575. this.peers.push(peer);
  576. var elem = $iq({to: this.bridgejid, type: 'get'});
  577. elem.c('conference', {xmlns: 'http://jitsi.org/protocol/colibri', id: this.confid});
  578. var localSDP = new SDP(this.peerconnection.localDescription.sdp);
  579. localSDP.media.forEach(function (media, channel) {
  580. var name = SDPUtil.parse_mid(SDPUtil.find_line(media, 'a=mid:'));
  581. elem.c('content', {name: name});
  582. if (name !== 'data')
  583. {
  584. elem.c('channel', {
  585. initiator: 'true',
  586. expire: self.channelExpire,
  587. endpoint: peer.substr(1 + peer.lastIndexOf('/'))
  588. });
  589. }
  590. else
  591. {
  592. elem.c('sctpconnection', {
  593. endpoint: peer.substr(1 + peer.lastIndexOf('/')),
  594. initiator: 'true',
  595. expire: self.channelExpire,
  596. port: 5000
  597. });
  598. }
  599. elem.up(); // end of channel/sctpconnection
  600. elem.up(); // end of content
  601. });
  602. this.connection.sendIQ(elem,
  603. function (result) {
  604. var contents = $(result).find('>conference>content').get();
  605. for (var i = 0; i < contents.length; i++) {
  606. var channelXml = $(contents[i]).find('>channel');
  607. if (channelXml.length)
  608. {
  609. tmp = channelXml.get();
  610. }
  611. else
  612. {
  613. tmp = $(contents[i]).find('>sctpconnection').get();
  614. }
  615. self.channels[index][i] = tmp[0];
  616. }
  617. self.initiate(peer, true);
  618. },
  619. function (error) {
  620. console.warn(error);
  621. }
  622. );
  623. };
  624. // update the channel description (payload-types + dtls fp) for a participant
  625. ColibriFocus.prototype.updateChannel = function (remoteSDP, participant) {
  626. console.log('change allocation for', this.confid);
  627. var self = this;
  628. var change = $iq({to: this.bridgejid, type: 'set'});
  629. change.c('conference', {xmlns: 'http://jitsi.org/protocol/colibri', id: this.confid});
  630. for (channel = 0; channel < this.channels[participant].length; channel++)
  631. {
  632. var name = SDPUtil.parse_mid(SDPUtil.find_line(remoteSDP.media[channel], 'a=mid:'));
  633. change.c('content', {name: name});
  634. if (name !== 'data')
  635. {
  636. change.c('channel', {
  637. id: $(this.channels[participant][channel]).attr('id'),
  638. endpoint: $(this.channels[participant][channel]).attr('endpoint'),
  639. expire: self.channelExpire
  640. });
  641. var rtpmap = SDPUtil.find_lines(remoteSDP.media[channel], 'a=rtpmap:');
  642. rtpmap.forEach(function (val) {
  643. // TODO: too much copy-paste
  644. var rtpmap = SDPUtil.parse_rtpmap(val);
  645. change.c('payload-type', rtpmap);
  646. //
  647. // put any 'a=fmtp:' + mline.fmt[j] lines into <param name=foo value=bar/>
  648. /*
  649. if (SDPUtil.find_line(remoteSDP.media[channel], 'a=fmtp:' + rtpmap.id)) {
  650. tmp = SDPUtil.parse_fmtp(SDPUtil.find_line(remoteSDP.media[channel], 'a=fmtp:' + rtpmap.id));
  651. for (var k = 0; k < tmp.length; k++) {
  652. change.c('parameter', tmp[k]).up();
  653. }
  654. }
  655. */
  656. change.up();
  657. });
  658. }
  659. else
  660. {
  661. var sctpmap = SDPUtil.find_line(remoteSDP.media[channel], 'a=sctpmap:');
  662. change.c('sctpconnection', {
  663. endpoint: $(this.channels[participant][channel]).attr('endpoint'),
  664. expire: self.channelExpire,
  665. port: SDPUtil.parse_sctpmap(sctpmap)[0]
  666. });
  667. }
  668. // now add transport
  669. remoteSDP.TransportToJingle(channel, change);
  670. change.up(); // end of channel/sctpconnection
  671. change.up(); // end of content
  672. }
  673. this.connection.sendIQ(change,
  674. function (res) {
  675. console.log('got result');
  676. },
  677. function (err) {
  678. console.log('got error');
  679. }
  680. );
  681. };
  682. // tell everyone about a new participants a=ssrc lines (isadd is true)
  683. // or a leaving participants a=ssrc lines
  684. ColibriFocus.prototype.sendSSRCUpdate = function (sdpMediaSsrcs, fromJid, isadd) {
  685. var self = this;
  686. this.peers.forEach(function (peerjid) {
  687. if (peerjid == fromJid) return;
  688. console.log('tell', peerjid, 'about ' + (isadd ? 'new' : 'removed') + ' ssrcs from', fromJid);
  689. if (!self.remotessrc[peerjid]) {
  690. // FIXME: this should only send to participants that are stable, i.e. who have sent a session-accept
  691. // possibly, this.remoteSSRC[session.peerjid] does not exist yet
  692. console.warn('do we really want to bother', peerjid, 'with updates yet?');
  693. }
  694. var peersess = self.connection.jingle.jid2session[peerjid];
  695. if(!peersess){
  696. console.warn('no session with peer: '+peerjid+' yet...');
  697. return;
  698. }
  699. self.sendSSRCUpdateIq(sdpMediaSsrcs, peersess.sid, peersess.initiator, peerjid, isadd);
  700. });
  701. };
  702. /**
  703. * Overrides SessionBase.addSource.
  704. *
  705. * @param elem proprietary 'add source' Jingle request(XML node).
  706. * @param fromJid JID of the participant to whom new ssrcs belong.
  707. */
  708. ColibriFocus.prototype.addSource = function (elem, fromJid) {
  709. var self = this;
  710. // FIXME: dirty waiting
  711. if (!this.peerconnection.localDescription)
  712. {
  713. console.warn("addSource - localDescription not ready yet")
  714. setTimeout(function()
  715. {
  716. self.addSource(elem, fromJid);
  717. },
  718. 200
  719. );
  720. return;
  721. }
  722. this.peerconnection.addSource(elem);
  723. var peerSsrc = this.remotessrc[fromJid];
  724. //console.log("On ADD", self.addssrc, peerSsrc);
  725. this.peerconnection.addssrc.forEach(function(val, idx){
  726. if(!peerSsrc[idx]){
  727. // add ssrc
  728. peerSsrc[idx] = val;
  729. } else {
  730. if(peerSsrc[idx].indexOf(val) == -1){
  731. peerSsrc[idx] = peerSsrc[idx]+val;
  732. }
  733. }
  734. });
  735. var oldRemoteSdp = new SDP(this.peerconnection.remoteDescription.sdp);
  736. this.modifySources(function(){
  737. // Notify other participants about added ssrc
  738. var remoteSDP = new SDP(self.peerconnection.remoteDescription.sdp);
  739. var newSSRCs = oldRemoteSdp.getNewMedia(remoteSDP);
  740. self.sendSSRCUpdate(newSSRCs, fromJid, true);
  741. });
  742. };
  743. /**
  744. * Overrides SessionBase.removeSource.
  745. *
  746. * @param elem proprietary 'remove source' Jingle request(XML node).
  747. * @param fromJid JID of the participant to whom removed ssrcs belong.
  748. */
  749. ColibriFocus.prototype.removeSource = function (elem, fromJid) {
  750. var self = this;
  751. // FIXME: dirty waiting
  752. if (!self.peerconnection.localDescription)
  753. {
  754. console.warn("removeSource - localDescription not ready yet");
  755. setTimeout(function()
  756. {
  757. self.removeSource(elem, fromJid);
  758. },
  759. 200
  760. );
  761. return;
  762. }
  763. this.peerconnection.removeSource(elem);
  764. var peerSsrc = this.remotessrc[fromJid];
  765. //console.log("On REMOVE", self.removessrc, peerSsrc);
  766. this.peerconnection.removessrc.forEach(function(val, idx){
  767. if(peerSsrc[idx]){
  768. // Remove ssrc
  769. peerSsrc[idx] = peerSsrc[idx].replace(val, '');
  770. }
  771. });
  772. var oldSDP = new SDP(self.peerconnection.remoteDescription.sdp);
  773. this.modifySources(function(){
  774. // Notify other participants about removed ssrc
  775. var remoteSDP = new SDP(self.peerconnection.remoteDescription.sdp);
  776. var removedSSRCs = remoteSDP.getNewMedia(oldSDP);
  777. self.sendSSRCUpdate(removedSSRCs, fromJid, false);
  778. });
  779. };
  780. ColibriFocus.prototype.setRemoteDescription = function (session, elem, desctype) {
  781. var participant = this.peers.indexOf(session.peerjid);
  782. console.log('Colibri.setRemoteDescription from', session.peerjid, participant);
  783. var remoteSDP = new SDP('');
  784. var channel;
  785. remoteSDP.fromJingle(elem);
  786. // ACT 1: change allocation on bridge
  787. this.updateChannel(remoteSDP, participant);
  788. // ACT 2: tell anyone else about the new SSRCs
  789. this.sendSSRCUpdate(remoteSDP.getMediaSsrcMap(), session.peerjid, true);
  790. // ACT 3: note the SSRCs
  791. this.remotessrc[session.peerjid] = [];
  792. for (channel = 0; channel < this.channels[participant].length; channel++) {
  793. //if (channel == 0) continue; FIXME: does not work as intended
  794. if (SDPUtil.find_lines(remoteSDP.media[channel], 'a=ssrc:').length)
  795. {
  796. this.remotessrc[session.peerjid][channel] =
  797. SDPUtil.find_lines(remoteSDP.media[channel], 'a=ssrc:')
  798. .join('\r\n') + '\r\n';
  799. }
  800. }
  801. // ACT 4: add new a=ssrc lines to local remotedescription
  802. for (channel = 0; channel < this.channels[participant].length; channel++) {
  803. //if (channel == 0) continue; FIXME: does not work as intended
  804. if (SDPUtil.find_lines(remoteSDP.media[channel], 'a=ssrc:').length) {
  805. this.peerconnection.enqueueAddSsrc(
  806. channel,
  807. SDPUtil.find_lines(remoteSDP.media[channel], 'a=ssrc:').join('\r\n') + '\r\n'
  808. );
  809. }
  810. }
  811. this.modifySources();
  812. };
  813. // relay ice candidates to bridge using trickle
  814. ColibriFocus.prototype.addIceCandidate = function (session, elem) {
  815. var self = this;
  816. var participant = this.peers.indexOf(session.peerjid);
  817. //console.log('change transport allocation for', this.confid, session.peerjid, participant);
  818. var change = $iq({to: this.bridgejid, type: 'set'});
  819. change.c('conference', {xmlns: 'http://jitsi.org/protocol/colibri', id: this.confid});
  820. $(elem).each(function () {
  821. var name = $(this).attr('name');
  822. var channel = name == 'audio' ? 0 : 1; // FIXME: search mlineindex in localdesc
  823. if (name != 'audio' && name != 'video')
  824. channel = 2; // name == 'data'
  825. change.c('content', {name: name});
  826. if (name !== 'data')
  827. {
  828. change.c('channel', {
  829. id: $(self.channels[participant][channel]).attr('id'),
  830. endpoint: $(self.channels[participant][channel]).attr('endpoint'),
  831. expire: self.channelExpire
  832. });
  833. }
  834. else
  835. {
  836. change.c('sctpconnection', {
  837. endpoint: $(self.channels[participant][channel]).attr('endpoint'),
  838. expire: self.channelExpire
  839. });
  840. }
  841. $(this).find('>transport').each(function () {
  842. change.c('transport', {
  843. ufrag: $(this).attr('ufrag'),
  844. pwd: $(this).attr('pwd'),
  845. xmlns: $(this).attr('xmlns')
  846. });
  847. $(this).find('>candidate').each(function () {
  848. /* not yet
  849. if (this.getAttribute('protocol') == 'tcp' && this.getAttribute('port') == 0) {
  850. // chrome generates TCP candidates with port 0
  851. return;
  852. }
  853. */
  854. var line = SDPUtil.candidateFromJingle(this);
  855. change.c('candidate', SDPUtil.candidateToJingle(line)).up();
  856. });
  857. change.up(); // end of transport
  858. });
  859. change.up(); // end of channel/sctpconnection
  860. change.up(); // end of content
  861. });
  862. // FIXME: need to check if there is at least one candidate when filtering TCP ones
  863. this.connection.sendIQ(change,
  864. function (res) {
  865. console.log('got result');
  866. },
  867. function (err) {
  868. console.error('got error', err);
  869. }
  870. );
  871. };
  872. // send our own candidate to the bridge
  873. ColibriFocus.prototype.sendIceCandidate = function (candidate) {
  874. var self = this;
  875. //console.log('candidate', candidate);
  876. if (!candidate) {
  877. console.log('end of candidates');
  878. return;
  879. }
  880. if (this.drip_container.length === 0) {
  881. // start 20ms callout
  882. window.setTimeout(function () {
  883. if (self.drip_container.length === 0) return;
  884. self.sendIceCandidates(self.drip_container);
  885. self.drip_container = [];
  886. }, 20);
  887. }
  888. this.drip_container.push(candidate);
  889. };
  890. // sort and send multiple candidates
  891. ColibriFocus.prototype.sendIceCandidates = function (candidates) {
  892. var self = this;
  893. var mycands = $iq({to: this.bridgejid, type: 'set'});
  894. mycands.c('conference', {xmlns: 'http://jitsi.org/protocol/colibri', id: this.confid});
  895. // FIXME: multi-candidate logic is taken from strophe.jingle, should be refactored there
  896. var localSDP = new SDP(this.peerconnection.localDescription.sdp);
  897. for (var mid = 0; mid < localSDP.media.length; mid++)
  898. {
  899. var cands = candidates.filter(function (el) { return el.sdpMLineIndex == mid; });
  900. if (cands.length > 0)
  901. {
  902. var name = cands[0].sdpMid;
  903. mycands.c('content', {name: name });
  904. if (name !== 'data')
  905. {
  906. mycands.c('channel', {
  907. id: $(this.mychannel[cands[0].sdpMLineIndex]).attr('id'),
  908. endpoint: $(this.mychannel[cands[0].sdpMLineIndex]).attr('endpoint'),
  909. expire: self.channelExpire
  910. });
  911. }
  912. else
  913. {
  914. mycands.c('sctpconnection', {
  915. endpoint: $(this.mychannel[cands[0].sdpMLineIndex]).attr('endpoint'),
  916. port: $(this.mychannel[cands[0].sdpMLineIndex]).attr('port'),
  917. expire: self.channelExpire
  918. });
  919. }
  920. mycands.c('transport', {xmlns: 'urn:xmpp:jingle:transports:ice-udp:1'});
  921. for (var i = 0; i < cands.length; i++) {
  922. mycands.c('candidate', SDPUtil.candidateToJingle(cands[i].candidate)).up();
  923. }
  924. mycands.up(); // transport
  925. mycands.up(); // channel / sctpconnection
  926. mycands.up(); // content
  927. }
  928. }
  929. console.log('send cands', candidates);
  930. this.connection.sendIQ(mycands,
  931. function (res) {
  932. console.log('got result');
  933. },
  934. function (err) {
  935. console.error('got error', err);
  936. }
  937. );
  938. };
  939. ColibriFocus.prototype.terminate = function (session, reason) {
  940. console.log('remote session terminated from', session.peerjid);
  941. var participant = this.peers.indexOf(session.peerjid);
  942. if (!this.remotessrc[session.peerjid] || participant == -1) {
  943. return;
  944. }
  945. var ssrcs = this.remotessrc[session.peerjid];
  946. for (var i = 0; i < ssrcs.length; i++) {
  947. this.peerconnection.enqueueRemoveSsrc(i, ssrcs[i]);
  948. }
  949. // remove from this.peers
  950. this.peers.splice(participant, 1);
  951. // expire channel on bridge
  952. var change = $iq({to: this.bridgejid, type: 'set'});
  953. change.c('conference', {xmlns: 'http://jitsi.org/protocol/colibri', id: this.confid});
  954. for (var channel = 0; channel < this.channels[participant].length; channel++) {
  955. var name = channel === 0 ? 'audio' : 'video';
  956. if (channel == 2)
  957. name = 'data';
  958. change.c('content', {name: name});
  959. if (name !== 'data')
  960. {
  961. change.c('channel', {
  962. id: $(this.channels[participant][channel]).attr('id'),
  963. endpoint: $(this.channels[participant][channel]).attr('endpoint'),
  964. expire: '0'
  965. });
  966. }
  967. else
  968. {
  969. change.c('sctpconnection', {
  970. endpoint: $(this.channels[participant][channel]).attr('endpoint'),
  971. expire: '0'
  972. });
  973. }
  974. change.up(); // end of channel/sctpconnection
  975. change.up(); // end of content
  976. }
  977. this.connection.sendIQ(change,
  978. function (res) {
  979. console.log('got result');
  980. },
  981. function (err) {
  982. console.error('got error', err);
  983. }
  984. );
  985. // and remove from channels
  986. this.channels.splice(participant, 1);
  987. // tell everyone about the ssrcs to be removed
  988. var sdp = new SDP('');
  989. var localSDP = new SDP(this.peerconnection.localDescription.sdp);
  990. var contents = SDPUtil.find_lines(localSDP.raw, 'a=mid:').map(SDPUtil.parse_mid);
  991. for (var j = 0; j < ssrcs.length; j++) {
  992. sdp.media[j] = 'a=mid:' + contents[j] + '\r\n';
  993. sdp.media[j] += ssrcs[j];
  994. this.peerconnection.enqueueRemoveSsrc(j, ssrcs[j]);
  995. }
  996. this.sendSSRCUpdate(sdp.getMediaSsrcMap(), session.peerjid, false);
  997. delete this.remotessrc[session.peerjid];
  998. this.modifySources();
  999. };
  1000. ColibriFocus.prototype.sendTerminate = function (session, reason, text) {
  1001. var term = $iq({to: session.peerjid, type: 'set'})
  1002. .c('jingle',
  1003. {xmlns: 'urn:xmpp:jingle:1',
  1004. action: 'session-terminate',
  1005. initiator: session.me,
  1006. sid: session.sid})
  1007. .c('reason')
  1008. .c(reason || 'success');
  1009. if (text) {
  1010. term.up().c('text').t(text);
  1011. }
  1012. this.connection.sendIQ(term,
  1013. function () {
  1014. if (!session)
  1015. return;
  1016. if (session.peerconnection) {
  1017. session.peerconnection.close();
  1018. session.peerconnection = null;
  1019. }
  1020. session.terminate();
  1021. var ack = {};
  1022. ack.source = 'terminate';
  1023. $(document).trigger('ack.jingle', [session.sid, ack]);
  1024. },
  1025. function (stanza) {
  1026. var error = ($(stanza).find('error').length) ? {
  1027. code: $(stanza).find('error').attr('code'),
  1028. reason: $(stanza).find('error :first')[0].tagName,
  1029. }:{};
  1030. $(document).trigger('ack.jingle', [self.sid, error]);
  1031. },
  1032. 10000);
  1033. if (this.statsinterval !== null) {
  1034. window.clearInterval(this.statsinterval);
  1035. this.statsinterval = null;
  1036. }
  1037. };