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.

JingleSessionPC.js 44KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176
  1. /* jshint -W117 */
  2. var logger = require("jitsi-meet-logger").getLogger(__filename);
  3. var JingleSession = require("./JingleSession");
  4. var TraceablePeerConnection = require("./TraceablePeerConnection");
  5. var SDPDiffer = require("./SDPDiffer");
  6. var SDPUtil = require("./SDPUtil");
  7. var SDP = require("./SDP");
  8. var async = require("async");
  9. var XMPPEvents = require("../../service/xmpp/XMPPEvents");
  10. var RTCBrowserType = require("../RTC/RTCBrowserType");
  11. var RTC = require("../RTC/RTC");
  12. /**
  13. * Constant tells how long we're going to wait for IQ response, before timeout
  14. * error is triggered.
  15. * @type {number}
  16. */
  17. var IQ_TIMEOUT = 10000;
  18. // Jingle stuff
  19. function JingleSessionPC(me, sid, peerjid, connection,
  20. media_constraints, ice_config, service, eventEmitter) {
  21. JingleSession.call(this, me, sid, peerjid, connection,
  22. media_constraints, ice_config, service, eventEmitter);
  23. this.localSDP = null;
  24. this.remoteSDP = null;
  25. this.hadstuncandidate = false;
  26. this.hadturncandidate = false;
  27. this.lasticecandidate = false;
  28. this.addssrc = [];
  29. this.removessrc = [];
  30. this.pendingop = null;
  31. this.modifyingLocalStreams = false;
  32. this.modifiedSSRCs = {};
  33. /**
  34. * A map that stores SSRCs of remote streams. And is used only locally
  35. * We store the mapping when jingle is received, and later is used
  36. * onaddstream webrtc event where we have only the ssrc
  37. * FIXME: This map got filled and never cleaned and can grow durring long
  38. * conference
  39. * @type {{}} maps SSRC number to jid
  40. */
  41. this.ssrcOwners = {};
  42. this.webrtcIceUdpDisable = !!this.service.options.webrtcIceUdpDisable;
  43. this.webrtcIceTcpDisable = !!this.service.options.webrtcIceTcpDisable;
  44. this.modifySourcesQueue = async.queue(this._modifySources.bind(this), 1);
  45. // We start with the queue paused. We resume it when the signaling state is
  46. // stable and the ice connection state is connected.
  47. this.modifySourcesQueue.pause();
  48. }
  49. //XXX this is badly broken...
  50. JingleSessionPC.prototype = JingleSession.prototype;
  51. JingleSessionPC.prototype.constructor = JingleSessionPC;
  52. JingleSessionPC.prototype.updateModifySourcesQueue = function() {
  53. var signalingState = this.peerconnection.signalingState;
  54. var iceConnectionState = this.peerconnection.iceConnectionState;
  55. if (signalingState === 'stable' && iceConnectionState === 'connected') {
  56. this.modifySourcesQueue.resume();
  57. } else {
  58. this.modifySourcesQueue.pause();
  59. }
  60. };
  61. JingleSessionPC.prototype.doInitialize = function () {
  62. var self = this;
  63. this.hadstuncandidate = false;
  64. this.hadturncandidate = false;
  65. this.lasticecandidate = false;
  66. // True if reconnect is in progress
  67. this.isreconnect = false;
  68. // Set to true if the connection was ever stable
  69. this.wasstable = false;
  70. this.peerconnection = new TraceablePeerConnection(
  71. this.connection.jingle.ice_config,
  72. RTC.getPCConstraints(),
  73. this);
  74. this.peerconnection.onicecandidate = function (ev) {
  75. if (!ev) {
  76. // There was an incomplete check for ev before which left the last
  77. // line of the function unprotected from a potential throw of an
  78. // exception. Consequently, it may be argued that the check is
  79. // unnecessary. Anyway, I'm leaving it and making the check
  80. // complete.
  81. return;
  82. }
  83. var candidate = ev.candidate;
  84. if (candidate) {
  85. // Discard candidates of disabled protocols.
  86. var protocol = candidate.protocol;
  87. if (typeof protocol === 'string') {
  88. protocol = protocol.toLowerCase();
  89. if (protocol == 'tcp') {
  90. if (self.webrtcIceTcpDisable)
  91. return;
  92. } else if (protocol == 'udp') {
  93. if (self.webrtcIceUdpDisable)
  94. return;
  95. }
  96. }
  97. }
  98. self.sendIceCandidate(candidate);
  99. };
  100. this.peerconnection.onaddstream = function (event) {
  101. if (event.stream.id !== 'default') {
  102. logger.log("REMOTE STREAM ADDED: ", event.stream , event.stream.id);
  103. self.remoteStreamAdded(event);
  104. } else {
  105. // This is a recvonly stream. Clients that implement Unified Plan,
  106. // such as Firefox use recvonly "streams/channels/tracks" for
  107. // receiving remote stream/tracks, as opposed to Plan B where there
  108. // are only 3 channels: audio, video and data.
  109. logger.log("RECVONLY REMOTE STREAM IGNORED: " + event.stream + " - " + event.stream.id);
  110. }
  111. };
  112. this.peerconnection.onremovestream = function (event) {
  113. // Remove the stream from remoteStreams
  114. if (event.stream.id !== 'default') {
  115. logger.log("REMOTE STREAM REMOVED: ", event.stream , event.stream.id);
  116. self.remoteStreamRemoved(event);
  117. } else {
  118. // This is a recvonly stream. Clients that implement Unified Plan,
  119. // such as Firefox use recvonly "streams/channels/tracks" for
  120. // receiving remote stream/tracks, as opposed to Plan B where there
  121. // are only 3 channels: audio, video and data.
  122. logger.log("RECVONLY REMOTE STREAM IGNORED: " + event.stream + " - " + event.stream.id);
  123. }
  124. };
  125. this.peerconnection.onsignalingstatechange = function (event) {
  126. if (!(self && self.peerconnection)) return;
  127. if (self.peerconnection.signalingState === 'stable') {
  128. self.wasstable = true;
  129. }
  130. self.updateModifySourcesQueue();
  131. };
  132. /**
  133. * The oniceconnectionstatechange event handler contains the code to execute when the iceconnectionstatechange event,
  134. * of type Event, is received by this RTCPeerConnection. Such an event is sent when the value of
  135. * RTCPeerConnection.iceConnectionState changes.
  136. *
  137. * @param event the event containing information about the change
  138. */
  139. this.peerconnection.oniceconnectionstatechange = function (event) {
  140. if (!(self && self.peerconnection)) return;
  141. logger.log("(TIME) ICE " + self.peerconnection.iceConnectionState +
  142. ":\t", window.performance.now());
  143. self.updateModifySourcesQueue();
  144. switch (self.peerconnection.iceConnectionState) {
  145. case 'connected':
  146. // Informs interested parties that the connection has been restored.
  147. if (self.peerconnection.signalingState === 'stable' && self.isreconnect)
  148. self.room.eventEmitter.emit(XMPPEvents.CONNECTION_RESTORED);
  149. self.isreconnect = false;
  150. break;
  151. case 'disconnected':
  152. self.isreconnect = true;
  153. // Informs interested parties that the connection has been interrupted.
  154. if (self.wasstable)
  155. self.room.eventEmitter.emit(XMPPEvents.CONNECTION_INTERRUPTED);
  156. break;
  157. case 'failed':
  158. self.room.eventEmitter.emit(XMPPEvents.CONFERENCE_SETUP_FAILED);
  159. break;
  160. }
  161. };
  162. this.peerconnection.onnegotiationneeded = function (event) {
  163. self.room.eventEmitter.emit(XMPPEvents.PEERCONNECTION_READY, self);
  164. };
  165. };
  166. JingleSessionPC.prototype.sendIceCandidate = function (candidate) {
  167. var self = this;
  168. if (candidate && !this.lasticecandidate) {
  169. var ice = SDPUtil.iceparams(this.localSDP.media[candidate.sdpMLineIndex], this.localSDP.session);
  170. var jcand = SDPUtil.candidateToJingle(candidate.candidate);
  171. if (!(ice && jcand)) {
  172. logger.error('failed to get ice && jcand');
  173. return;
  174. }
  175. ice.xmlns = 'urn:xmpp:jingle:transports:ice-udp:1';
  176. if (jcand.type === 'srflx') {
  177. this.hadstuncandidate = true;
  178. } else if (jcand.type === 'relay') {
  179. this.hadturncandidate = true;
  180. }
  181. if (this.usedrip) {
  182. if (this.drip_container.length === 0) {
  183. // start 20ms callout
  184. window.setTimeout(function () {
  185. if (self.drip_container.length === 0) return;
  186. self.sendIceCandidates(self.drip_container);
  187. self.drip_container = [];
  188. }, 20);
  189. }
  190. this.drip_container.push(candidate);
  191. } else {
  192. self.sendIceCandidates([candidate]);
  193. }
  194. } else {
  195. logger.log('sendIceCandidate: last candidate.');
  196. // FIXME: remember to re-think in ICE-restart
  197. this.lasticecandidate = true;
  198. logger.log('Have we encountered any srflx candidates? ' + this.hadstuncandidate);
  199. logger.log('Have we encountered any relay candidates? ' + this.hadturncandidate);
  200. }
  201. };
  202. JingleSessionPC.prototype.sendIceCandidates = function (candidates) {
  203. logger.log('sendIceCandidates', candidates);
  204. var cand = $iq({to: this.peerjid, type: 'set'})
  205. .c('jingle', {xmlns: 'urn:xmpp:jingle:1',
  206. action: 'transport-info',
  207. initiator: this.initiator,
  208. sid: this.sid});
  209. for (var mid = 0; mid < this.localSDP.media.length; mid++) {
  210. var cands = candidates.filter(function (el) { return el.sdpMLineIndex == mid; });
  211. var mline = SDPUtil.parse_mline(this.localSDP.media[mid].split('\r\n')[0]);
  212. if (cands.length > 0) {
  213. var ice = SDPUtil.iceparams(this.localSDP.media[mid], this.localSDP.session);
  214. ice.xmlns = 'urn:xmpp:jingle:transports:ice-udp:1';
  215. cand.c('content', {creator: this.initiator == this.me ? 'initiator' : 'responder',
  216. name: (cands[0].sdpMid? cands[0].sdpMid : mline.media)
  217. }).c('transport', ice);
  218. for (var i = 0; i < cands.length; i++) {
  219. cand.c('candidate', SDPUtil.candidateToJingle(cands[i].candidate)).up();
  220. }
  221. // add fingerprint
  222. var fingerprint_line = SDPUtil.find_line(this.localSDP.media[mid], 'a=fingerprint:', this.localSDP.session);
  223. if (fingerprint_line) {
  224. var tmp = SDPUtil.parse_fingerprint(fingerprint_line);
  225. tmp.required = true;
  226. cand.c(
  227. 'fingerprint',
  228. {xmlns: 'urn:xmpp:jingle:apps:dtls:0'})
  229. .t(tmp.fingerprint);
  230. delete tmp.fingerprint;
  231. cand.attrs(tmp);
  232. cand.up();
  233. }
  234. cand.up(); // transport
  235. cand.up(); // content
  236. }
  237. }
  238. // might merge last-candidate notification into this, but it is called alot later. See webrtc issue #2340
  239. //logger.log('was this the last candidate', this.lasticecandidate);
  240. this.connection.sendIQ(
  241. cand, null, this.newJingleErrorHandler(cand), IQ_TIMEOUT);
  242. };
  243. JingleSessionPC.prototype.readSsrcInfo = function (contents) {
  244. var self = this;
  245. $(contents).each(function (idx, content) {
  246. var name = $(content).attr('name');
  247. var mediaType = this.getAttribute('name');
  248. var ssrcs = $(content).find('description>source[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]');
  249. ssrcs.each(function () {
  250. var ssrc = this.getAttribute('ssrc');
  251. $(this).find('>ssrc-info[xmlns="http://jitsi.org/jitmeet"]').each(
  252. function () {
  253. var owner = this.getAttribute('owner');
  254. self.ssrcOwners[ssrc] = owner;
  255. }
  256. );
  257. });
  258. });
  259. };
  260. JingleSessionPC.prototype.acceptOffer = function(jingleOffer,
  261. success, failure) {
  262. this.state = 'active';
  263. this.setRemoteDescription(jingleOffer, 'offer',
  264. function() {
  265. this.sendAnswer(success, failure);
  266. }.bind(this),
  267. failure);
  268. };
  269. JingleSessionPC.prototype.setRemoteDescription = function (elem, desctype,
  270. success, failure) {
  271. //logger.log('setting remote description... ', desctype);
  272. this.remoteSDP = new SDP('');
  273. if (this.webrtcIceTcpDisable) {
  274. this.remoteSDP.removeTcpCandidates = true;
  275. }
  276. if (this.webrtcIceUdpDisable) {
  277. this.remoteSDP.removeUdpCandidates = true;
  278. }
  279. this.remoteSDP.fromJingle(elem);
  280. this.readSsrcInfo($(elem).find(">content"));
  281. var remotedesc = new RTCSessionDescription({type: desctype, sdp: this.remoteSDP.raw});
  282. this.peerconnection.setRemoteDescription(remotedesc,
  283. function () {
  284. //logger.log('setRemoteDescription success');
  285. if (success) {
  286. success();
  287. }
  288. },
  289. function (e) {
  290. logger.error('setRemoteDescription error', e);
  291. if (failure)
  292. failure(e);
  293. JingleSessionPC.onJingleFatalError(this, e);
  294. }.bind(this)
  295. );
  296. };
  297. JingleSessionPC.prototype.sendAnswer = function (success, failure) {
  298. //logger.log('createAnswer');
  299. this.peerconnection.createAnswer(
  300. function (sdp) {
  301. this.createdAnswer(sdp, success, failure);
  302. }.bind(this),
  303. function (error) {
  304. logger.error("createAnswer failed", error);
  305. if (failure)
  306. failure(error);
  307. this.room.eventEmitter.emit(
  308. XMPPEvents.CONFERENCE_SETUP_FAILED, error);
  309. }.bind(this),
  310. this.media_constraints
  311. );
  312. };
  313. JingleSessionPC.prototype.createdAnswer = function (sdp, success, failure) {
  314. //logger.log('createAnswer callback');
  315. var self = this;
  316. this.localSDP = new SDP(sdp.sdp);
  317. var sendJingle = function (ssrcs) {
  318. var accept = $iq({to: self.peerjid,
  319. type: 'set'})
  320. .c('jingle', {xmlns: 'urn:xmpp:jingle:1',
  321. action: 'session-accept',
  322. initiator: self.initiator,
  323. responder: self.responder,
  324. sid: self.sid });
  325. if (self.webrtcIceTcpDisable) {
  326. self.localSDP.removeTcpCandidates = true;
  327. }
  328. if (self.webrtcIceUdpDisable) {
  329. self.localSDP.removeUdpCandidates = true;
  330. }
  331. self.localSDP.toJingle(
  332. accept,
  333. self.initiator == self.me ? 'initiator' : 'responder',
  334. ssrcs);
  335. self.fixJingle(accept);
  336. self.connection.sendIQ(accept,
  337. success,
  338. self.newJingleErrorHandler(accept, failure),
  339. IQ_TIMEOUT);
  340. };
  341. sdp.sdp = this.localSDP.raw;
  342. this.peerconnection.setLocalDescription(sdp,
  343. function () {
  344. //logger.log('setLocalDescription success');
  345. sendJingle(success, failure);
  346. },
  347. function (error) {
  348. logger.error('setLocalDescription failed', error);
  349. if (failure)
  350. failure(error);
  351. self.room.eventEmitter.emit(XMPPEvents.CONFERENCE_SETUP_FAILED);
  352. }
  353. );
  354. var cands = SDPUtil.find_lines(this.localSDP.raw, 'a=candidate:');
  355. for (var j = 0; j < cands.length; j++) {
  356. var cand = SDPUtil.parse_icecandidate(cands[j]);
  357. if (cand.type == 'srflx') {
  358. this.hadstuncandidate = true;
  359. } else if (cand.type == 'relay') {
  360. this.hadturncandidate = true;
  361. }
  362. }
  363. };
  364. JingleSessionPC.prototype.terminate = function (reason, text,
  365. success, failure) {
  366. var term = $iq({to: this.peerjid,
  367. type: 'set'})
  368. .c('jingle', {xmlns: 'urn:xmpp:jingle:1',
  369. action: 'session-terminate',
  370. initiator: this.initiator,
  371. sid: this.sid})
  372. .c('reason')
  373. .c(reason || 'success');
  374. if (text) {
  375. term.up().c('text').t(text);
  376. }
  377. this.connection.sendIQ(
  378. term, success, this.newJingleErrorHandler(term, failure), IQ_TIMEOUT);
  379. // this should result in 'onTerminated' being called by strope.jingle.js
  380. this.connection.jingle.terminate(this.sid);
  381. };
  382. JingleSessionPC.prototype.onTerminated = function (reasonCondition,
  383. reasonText) {
  384. this.state = 'ended';
  385. // Do something with reason and reasonCondition when we start to care
  386. //this.reasonCondition = reasonCondition;
  387. //this.reasonText = reasonText;
  388. logger.info("Session terminated", this, reasonCondition, reasonText);
  389. if (this.peerconnection)
  390. this.peerconnection.close();
  391. };
  392. /**
  393. * Handles a Jingle source-add message for this Jingle session.
  394. * @param elem An array of Jingle "content" elements.
  395. */
  396. JingleSessionPC.prototype.addSource = function (elem) {
  397. var self = this;
  398. // FIXME: dirty waiting
  399. if (!this.peerconnection.localDescription)
  400. {
  401. logger.warn("addSource - localDescription not ready yet")
  402. setTimeout(function()
  403. {
  404. self.addSource(elem);
  405. },
  406. 200
  407. );
  408. return;
  409. }
  410. logger.log('addssrc', new Date().getTime());
  411. logger.log('ice', this.peerconnection.iceConnectionState);
  412. this.readSsrcInfo(elem);
  413. var sdp = new SDP(this.peerconnection.remoteDescription.sdp);
  414. var mySdp = new SDP(this.peerconnection.localDescription.sdp);
  415. $(elem).each(function (idx, content) {
  416. var name = $(content).attr('name');
  417. var lines = '';
  418. $(content).find('ssrc-group[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]').each(function() {
  419. var semantics = this.getAttribute('semantics');
  420. var ssrcs = $(this).find('>source').map(function () {
  421. return this.getAttribute('ssrc');
  422. }).get();
  423. if (ssrcs.length) {
  424. lines += 'a=ssrc-group:' + semantics + ' ' + ssrcs.join(' ') + '\r\n';
  425. }
  426. });
  427. var tmp = $(content).find('source[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]'); // can handle both >source and >description>source
  428. tmp.each(function () {
  429. var ssrc = $(this).attr('ssrc');
  430. if(mySdp.containsSSRC(ssrc)){
  431. /**
  432. * This happens when multiple participants change their streams at the same time and
  433. * ColibriFocus.modifySources have to wait for stable state. In the meantime multiple
  434. * addssrc are scheduled for update IQ. See
  435. */
  436. logger.warn("Got add stream request for my own ssrc: "+ssrc);
  437. return;
  438. }
  439. if (sdp.containsSSRC(ssrc)) {
  440. logger.warn("Source-add request for existing SSRC: " + ssrc);
  441. return;
  442. }
  443. $(this).find('>parameter').each(function () {
  444. lines += 'a=ssrc:' + ssrc + ' ' + $(this).attr('name');
  445. if ($(this).attr('value') && $(this).attr('value').length)
  446. lines += ':' + $(this).attr('value');
  447. lines += '\r\n';
  448. });
  449. });
  450. sdp.media.forEach(function(media, idx) {
  451. if (!SDPUtil.find_line(media, 'a=mid:' + name))
  452. return;
  453. sdp.media[idx] += lines;
  454. if (!self.addssrc[idx]) self.addssrc[idx] = '';
  455. self.addssrc[idx] += lines;
  456. });
  457. sdp.raw = sdp.session + sdp.media.join('');
  458. });
  459. this.modifySourcesQueue.push(function() {
  460. // When a source is added and if this is FF, a new channel is allocated
  461. // for receiving the added source. We need to diffuse the SSRC of this
  462. // new recvonly channel to the rest of the peers.
  463. logger.log('modify sources done');
  464. var newSdp = new SDP(self.peerconnection.localDescription.sdp);
  465. logger.log("SDPs", mySdp, newSdp);
  466. self.notifyMySSRCUpdate(mySdp, newSdp);
  467. });
  468. };
  469. /**
  470. * Handles a Jingle source-remove message for this Jingle session.
  471. * @param elem An array of Jingle "content" elements.
  472. */
  473. JingleSessionPC.prototype.removeSource = function (elem) {
  474. var self = this;
  475. // FIXME: dirty waiting
  476. if (!this.peerconnection.localDescription) {
  477. logger.warn("removeSource - localDescription not ready yet");
  478. setTimeout(function() {
  479. self.removeSource(elem);
  480. },
  481. 200
  482. );
  483. return;
  484. }
  485. logger.log('removessrc', new Date().getTime());
  486. logger.log('ice', this.peerconnection.iceConnectionState);
  487. var sdp = new SDP(this.peerconnection.remoteDescription.sdp);
  488. var mySdp = new SDP(this.peerconnection.localDescription.sdp);
  489. $(elem).each(function (idx, content) {
  490. var name = $(content).attr('name');
  491. var lines = '';
  492. $(content).find('ssrc-group[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]').each(function() {
  493. var semantics = this.getAttribute('semantics');
  494. var ssrcs = $(this).find('>source').map(function () {
  495. return this.getAttribute('ssrc');
  496. }).get();
  497. if (ssrcs.length) {
  498. lines += 'a=ssrc-group:' + semantics + ' ' + ssrcs.join(' ') + '\r\n';
  499. }
  500. });
  501. var tmp = $(content).find('source[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]'); // can handle both >source and >description>source
  502. tmp.each(function () {
  503. var ssrc = $(this).attr('ssrc');
  504. // This should never happen, but can be useful for bug detection
  505. if(mySdp.containsSSRC(ssrc)){
  506. logger.error("Got remove stream request for my own ssrc: "+ssrc);
  507. return;
  508. }
  509. $(this).find('>parameter').each(function () {
  510. lines += 'a=ssrc:' + ssrc + ' ' + $(this).attr('name');
  511. if ($(this).attr('value') && $(this).attr('value').length)
  512. lines += ':' + $(this).attr('value');
  513. lines += '\r\n';
  514. });
  515. });
  516. sdp.media.forEach(function(media, idx) {
  517. if (!SDPUtil.find_line(media, 'a=mid:' + name))
  518. return;
  519. sdp.media[idx] += lines;
  520. if (!self.removessrc[idx]) self.removessrc[idx] = '';
  521. self.removessrc[idx] += lines;
  522. });
  523. sdp.raw = sdp.session + sdp.media.join('');
  524. });
  525. this.modifySourcesQueue.push(function() {
  526. // When a source is removed and if this is FF, the recvonly channel that
  527. // receives the remote stream is deactivated . We need to diffuse the
  528. // recvonly SSRC removal to the rest of the peers.
  529. logger.log('modify sources done');
  530. var newSdp = new SDP(self.peerconnection.localDescription.sdp);
  531. logger.log("SDPs", mySdp, newSdp);
  532. self.notifyMySSRCUpdate(mySdp, newSdp);
  533. });
  534. };
  535. JingleSessionPC.prototype._modifySources = function (successCallback, queueCallback) {
  536. var self = this;
  537. if (this.peerconnection.signalingState == 'closed') return;
  538. if (!(this.addssrc.length || this.removessrc.length || this.pendingop !== null
  539. || this.modifyingLocalStreams)){
  540. // There is nothing to do since scheduled job might have been
  541. // executed by another succeeding call
  542. if(successCallback){
  543. successCallback();
  544. }
  545. queueCallback();
  546. return;
  547. }
  548. // Reset switch streams flags
  549. this.modifyingLocalStreams = false;
  550. var sdp = new SDP(this.peerconnection.remoteDescription.sdp);
  551. // add sources
  552. this.addssrc.forEach(function(lines, idx) {
  553. sdp.media[idx] += lines;
  554. });
  555. this.addssrc = [];
  556. // remove sources
  557. this.removessrc.forEach(function(lines, idx) {
  558. lines = lines.split('\r\n');
  559. lines.pop(); // remove empty last element;
  560. lines.forEach(function(line) {
  561. sdp.media[idx] = sdp.media[idx].replace(line + '\r\n', '');
  562. });
  563. });
  564. this.removessrc = [];
  565. sdp.raw = sdp.session + sdp.media.join('');
  566. this.peerconnection.setRemoteDescription(new RTCSessionDescription({type: 'offer', sdp: sdp.raw}),
  567. function() {
  568. if(self.signalingState == 'closed') {
  569. logger.error("createAnswer attempt on closed state");
  570. queueCallback("createAnswer attempt on closed state");
  571. return;
  572. }
  573. self.peerconnection.createAnswer(
  574. function(modifiedAnswer) {
  575. // change video direction, see https://github.com/jitsi/jitmeet/issues/41
  576. if (self.pendingop !== null) {
  577. var sdp = new SDP(modifiedAnswer.sdp);
  578. if (sdp.media.length > 1) {
  579. switch(self.pendingop) {
  580. case 'mute':
  581. sdp.media[1] = sdp.media[1].replace('a=sendrecv', 'a=recvonly');
  582. break;
  583. case 'unmute':
  584. sdp.media[1] = sdp.media[1].replace('a=recvonly', 'a=sendrecv');
  585. break;
  586. }
  587. sdp.raw = sdp.session + sdp.media.join('');
  588. modifiedAnswer.sdp = sdp.raw;
  589. }
  590. self.pendingop = null;
  591. }
  592. // FIXME: pushing down an answer while ice connection state
  593. // is still checking is bad...
  594. //logger.log(self.peerconnection.iceConnectionState);
  595. // trying to work around another chrome bug
  596. //modifiedAnswer.sdp = modifiedAnswer.sdp.replace(/a=setup:active/g, 'a=setup:actpass');
  597. self.peerconnection.setLocalDescription(modifiedAnswer,
  598. function() {
  599. if(successCallback){
  600. successCallback();
  601. }
  602. queueCallback();
  603. },
  604. function(error) {
  605. logger.error('modified setLocalDescription failed', error);
  606. queueCallback(error);
  607. }
  608. );
  609. },
  610. function(error) {
  611. logger.error('modified answer failed', error);
  612. queueCallback(error);
  613. }
  614. );
  615. },
  616. function(error) {
  617. logger.error('modify failed', error);
  618. queueCallback(error);
  619. }
  620. );
  621. };
  622. /**
  623. * Adds stream.
  624. * @param stream new stream that will be added.
  625. * @param success_callback callback executed after successful stream addition.
  626. * @param ssrcInfo object with information about the SSRCs associated with the
  627. * stream.
  628. * @param dontModifySources {boolean} if true _modifySources won't be called.
  629. * Used for streams added before the call start.
  630. */
  631. JingleSessionPC.prototype.addStream = function (stream, callback, ssrcInfo,
  632. dontModifySources) {
  633. // Remember SDP to figure out added/removed SSRCs
  634. var oldSdp = null;
  635. if(this.peerconnection) {
  636. if(this.peerconnection.localDescription) {
  637. oldSdp = new SDP(this.peerconnection.localDescription.sdp);
  638. }
  639. //when adding muted stream we have to pass the ssrcInfo but we don't
  640. //have a stream
  641. if(stream || ssrcInfo)
  642. this.peerconnection.addStream(stream, ssrcInfo);
  643. }
  644. // Conference is not active
  645. if(!oldSdp || !this.peerconnection || dontModifySources) {
  646. if(ssrcInfo) {
  647. //available only on video unmute or when adding muted stream
  648. this.modifiedSSRCs[ssrcInfo.type] =
  649. this.modifiedSSRCs[ssrcInfo.type] || [];
  650. this.modifiedSSRCs[ssrcInfo.type].push(ssrcInfo);
  651. }
  652. callback();
  653. return;
  654. }
  655. this.modifyingLocalStreams = true;
  656. var self = this;
  657. this.modifySourcesQueue.push(function() {
  658. logger.log('modify sources done');
  659. if(ssrcInfo) {
  660. //available only on video unmute or when adding muted stream
  661. self.modifiedSSRCs[ssrcInfo.type] =
  662. self.modifiedSSRCs[ssrcInfo.type] || [];
  663. self.modifiedSSRCs[ssrcInfo.type].push(ssrcInfo);
  664. }
  665. callback();
  666. var newSdp = new SDP(self.peerconnection.localDescription.sdp);
  667. logger.log("SDPs", oldSdp, newSdp);
  668. self.notifyMySSRCUpdate(oldSdp, newSdp);
  669. });
  670. }
  671. /**
  672. * Generate ssrc info object for a stream with the following properties:
  673. * - ssrcs - Array of the ssrcs associated with the stream.
  674. * - groups - Array of the groups associated with the stream.
  675. */
  676. JingleSessionPC.prototype.generateNewStreamSSRCInfo = function () {
  677. return this.peerconnection.generateNewStreamSSRCInfo();
  678. };
  679. /**
  680. * Remove streams.
  681. * @param stream stream that will be removed.
  682. * @param success_callback callback executed after successful stream addition.
  683. * @param ssrcInfo object with information about the SSRCs associated with the
  684. * stream.
  685. */
  686. JingleSessionPC.prototype.removeStream = function (stream, callback, ssrcInfo) {
  687. // Remember SDP to figure out added/removed SSRCs
  688. var oldSdp = null;
  689. if(this.peerconnection) {
  690. if(this.peerconnection.localDescription) {
  691. oldSdp = new SDP(this.peerconnection.localDescription.sdp);
  692. }
  693. if (RTCBrowserType.getBrowserType() ===
  694. RTCBrowserType.RTC_BROWSER_FIREFOX) {
  695. if(!stream)//There is nothing to be changed
  696. return;
  697. var sender = null;
  698. // On Firefox we don't replace MediaStreams as this messes up the
  699. // m-lines (which can't be removed in Plan Unified) and brings a lot
  700. // of complications. Instead, we use the RTPSender and remove just
  701. // the track.
  702. var track = null;
  703. if(stream.getAudioTracks() && stream.getAudioTracks().length) {
  704. track = stream.getAudioTracks()[0];
  705. } else if(stream.getVideoTracks() && stream.getVideoTracks().length)
  706. {
  707. track = stream.getVideoTracks()[0];
  708. }
  709. if(!track) {
  710. logger.log("Cannot remove tracks: no tracks.");
  711. return;
  712. }
  713. // Find the right sender (for audio or video)
  714. this.peerconnection.peerconnection.getSenders().some(function (s) {
  715. if (s.track === track) {
  716. sender = s;
  717. return true;
  718. }
  719. });
  720. if (sender) {
  721. this.peerconnection.peerconnection.removeTrack(sender);
  722. } else {
  723. logger.log("Cannot remove tracks: no RTPSender.");
  724. }
  725. } else if(stream)
  726. this.peerconnection.removeStream(stream, false, ssrcInfo);
  727. // else
  728. // NOTE: If there is no stream and the browser is not FF we still need to do
  729. // some transformation in order to send remove-source for the muted
  730. // streams. That's why we aren't calling return here.
  731. }
  732. // Conference is not active
  733. if(!oldSdp || !this.peerconnection) {
  734. callback();
  735. return;
  736. }
  737. this.modifyingLocalStreams = true;
  738. var self = this;
  739. this.modifySourcesQueue.push(function() {
  740. logger.log('modify sources done');
  741. callback();
  742. var newSdp = new SDP(self.peerconnection.localDescription.sdp);
  743. if(ssrcInfo) {
  744. self.modifiedSSRCs[ssrcInfo.type] =
  745. self.modifiedSSRCs[ssrcInfo.type] || [];
  746. self.modifiedSSRCs[ssrcInfo.type].push(ssrcInfo);
  747. }
  748. logger.log("SDPs", oldSdp, newSdp);
  749. self.notifyMySSRCUpdate(oldSdp, newSdp);
  750. });
  751. }
  752. /**
  753. * Figures out added/removed ssrcs and send update IQs.
  754. * @param old_sdp SDP object for old description.
  755. * @param new_sdp SDP object for new description.
  756. */
  757. JingleSessionPC.prototype.notifyMySSRCUpdate = function (old_sdp, new_sdp) {
  758. if (!(this.peerconnection.signalingState == 'stable' &&
  759. this.peerconnection.iceConnectionState == 'connected')){
  760. logger.log("Too early to send updates");
  761. return;
  762. }
  763. // send source-remove IQ.
  764. sdpDiffer = new SDPDiffer(new_sdp, old_sdp);
  765. var remove = $iq({to: this.peerjid, type: 'set'})
  766. .c('jingle', {
  767. xmlns: 'urn:xmpp:jingle:1',
  768. action: 'source-remove',
  769. initiator: this.initiator,
  770. sid: this.sid
  771. }
  772. );
  773. sdpDiffer.toJingle(remove);
  774. var removed = this.fixJingle(remove);
  775. if (removed && remove) {
  776. logger.info("Sending source-remove", remove.tree());
  777. this.connection.sendIQ(
  778. remove, null, this.newJingleErrorHandler(remove), IQ_TIMEOUT);
  779. } else {
  780. logger.log('removal not necessary');
  781. }
  782. // send source-add IQ.
  783. var sdpDiffer = new SDPDiffer(old_sdp, new_sdp);
  784. var add = $iq({to: this.peerjid, type: 'set'})
  785. .c('jingle', {
  786. xmlns: 'urn:xmpp:jingle:1',
  787. action: 'source-add',
  788. initiator: this.initiator,
  789. sid: this.sid
  790. }
  791. );
  792. sdpDiffer.toJingle(add);
  793. var added = this.fixJingle(add);
  794. if (added && add) {
  795. logger.info("Sending source-add", add.tree());
  796. this.connection.sendIQ(
  797. add, null, this.newJingleErrorHandler(add), IQ_TIMEOUT);
  798. } else {
  799. logger.log('addition not necessary');
  800. }
  801. };
  802. /**
  803. * Method returns function(errorResponse) which is a callback to be passed to
  804. * Strophe connection.sendIQ method. An 'error' structure is created that is
  805. * passed as 1st argument to given <tt>failureCb</tt>. The format of this
  806. * structure is as follows:
  807. * {
  808. * code: {XMPP error response code}
  809. * reason: {the name of XMPP error reason element or 'timeout' if the request
  810. * has timed out within <tt>IQ_TIMEOUT</tt> milliseconds}
  811. * source: {request.tree() that provides original request}
  812. * session: {JingleSessionPC instance on which the error occurred}
  813. * }
  814. * @param request Strophe IQ instance which is the request to be dumped into
  815. * the error structure
  816. * @param failureCb function(error) called when error response was returned or
  817. * when a timeout has occurred.
  818. * @returns {function(this:JingleSessionPC)}
  819. */
  820. JingleSessionPC.prototype.newJingleErrorHandler = function(request, failureCb) {
  821. return function (errResponse) {
  822. var error = { };
  823. // Get XMPP error code and condition(reason)
  824. var errorElSel = $(errResponse).find('error');
  825. if (errorElSel.length) {
  826. error.code = errorElSel.attr('code');
  827. var errorReasonSel = $(errResponse).find('error :first');
  828. if (errorReasonSel.length)
  829. error.reason = errorReasonSel[0].tagName;
  830. }
  831. if (!errResponse) {
  832. error.reason = 'timeout';
  833. }
  834. error.source = null;
  835. if (request && "function" == typeof request.tree) {
  836. error.source = request.tree();
  837. }
  838. error.session = this;
  839. logger.error("Jingle error", error);
  840. if (failureCb) {
  841. failureCb(error);
  842. }
  843. this.room.eventEmitter.emit(XMPPEvents.JINGLE_ERROR, error);
  844. }.bind(this);
  845. };
  846. JingleSessionPC.onJingleFatalError = function (session, error)
  847. {
  848. this.room.eventEmitter.emit(XMPPEvents.CONFERENCE_SETUP_FAILED);
  849. this.room.eventEmitter.emit(XMPPEvents.JINGLE_FATAL_ERROR, session, error);
  850. };
  851. JingleSessionPC.prototype.remoteStreamAdded = function (data, times) {
  852. var self = this;
  853. var thessrc;
  854. var streamId = RTC.getStreamID(data.stream);
  855. // look up an associated JID for a stream id
  856. if (!streamId) {
  857. logger.error("No stream ID for", data.stream);
  858. } else if (streamId && streamId.indexOf('mixedmslabel') === -1) {
  859. // look only at a=ssrc: and _not_ at a=ssrc-group: lines
  860. var ssrclines = this.peerconnection.remoteDescription?
  861. SDPUtil.find_lines(this.peerconnection.remoteDescription.sdp, 'a=ssrc:') : [];
  862. ssrclines = ssrclines.filter(function (line) {
  863. // NOTE(gp) previously we filtered on the mslabel, but that property
  864. // is not always present.
  865. // return line.indexOf('mslabel:' + data.stream.label) !== -1;
  866. if (RTCBrowserType.isTemasysPluginUsed()) {
  867. return ((line.indexOf('mslabel:' + streamId) !== -1));
  868. } else {
  869. return ((line.indexOf('msid:' + streamId) !== -1));
  870. }
  871. });
  872. if (ssrclines.length) {
  873. thessrc = ssrclines[0].substring(7).split(' ')[0];
  874. if (!self.ssrcOwners[thessrc]) {
  875. logger.error("No SSRC owner known for: " + thessrc);
  876. return;
  877. }
  878. data.peerjid = self.ssrcOwners[thessrc];
  879. logger.log('associated jid', self.ssrcOwners[thessrc]);
  880. } else {
  881. logger.error("No SSRC lines for ", streamId);
  882. }
  883. }
  884. this.room.remoteStreamAdded(data, this.sid, thessrc);
  885. };
  886. /**
  887. * Handles remote stream removal.
  888. * @param event The event object associated with the removal.
  889. */
  890. JingleSessionPC.prototype.remoteStreamRemoved = function (event) {
  891. var thessrc;
  892. var streamId = RTC.getStreamID(event.stream);
  893. if (!streamId) {
  894. logger.error("No stream ID for", event.stream);
  895. } else if (streamId && streamId.indexOf('mixedmslabel') === -1) {
  896. this.room.eventEmitter.emit(XMPPEvents.REMOTE_STREAM_REMOVED, streamId);
  897. }
  898. };
  899. /**
  900. * Returns the ice connection state for the peer connection.
  901. * @returns the ice connection state for the peer connection.
  902. */
  903. JingleSessionPC.prototype.getIceConnectionState = function () {
  904. return this.peerconnection.iceConnectionState;
  905. };
  906. /**
  907. * Fixes the outgoing jingle packets by removing the nodes related to the
  908. * muted/unmuted streams, handles removing of muted stream, etc.
  909. * @param jingle the jingle packet that is going to be sent
  910. * @returns {boolean} true if the jingle has to be sent and false otherwise.
  911. */
  912. JingleSessionPC.prototype.fixJingle = function(jingle) {
  913. var action = $(jingle.nodeTree).find("jingle").attr("action");
  914. switch (action) {
  915. case "source-add":
  916. case "session-accept":
  917. this.fixSourceAddJingle(jingle);
  918. break;
  919. case "source-remove":
  920. this.fixSourceRemoveJingle(jingle);
  921. break;
  922. default:
  923. logger.error("Unknown jingle action!");
  924. return false;
  925. }
  926. var sources = $(jingle.tree()).find(">jingle>content>description>source");
  927. return sources && sources.length > 0;
  928. };
  929. /**
  930. * Fixes the outgoing jingle packets with action source-add by removing the
  931. * nodes related to the unmuted streams
  932. * @param jingle the jingle packet that is going to be sent
  933. * @returns {boolean} true if the jingle has to be sent and false otherwise.
  934. */
  935. JingleSessionPC.prototype.fixSourceAddJingle = function (jingle) {
  936. var ssrcs = this.modifiedSSRCs["unmute"];
  937. this.modifiedSSRCs["unmute"] = [];
  938. if(ssrcs && ssrcs.length) {
  939. ssrcs.forEach(function (ssrcObj) {
  940. var desc = $(jingle.tree()).find(">jingle>content[name=\"" +
  941. ssrcObj.mtype + "\"]>description");
  942. if(!desc || !desc.length)
  943. return;
  944. ssrcObj.ssrc.ssrcs.forEach(function (ssrc) {
  945. var sourceNode = desc.find(">source[ssrc=\"" +
  946. ssrc + "\"]");
  947. sourceNode.remove();
  948. });
  949. ssrcObj.ssrc.groups.forEach(function (group) {
  950. var groupNode = desc.find(">ssrc-group[semantics=\"" +
  951. group.group.semantics + "\"]:has(source[ssrc=\"" +
  952. group.primarySSRC +
  953. "\"])");
  954. groupNode.remove();
  955. });
  956. });
  957. }
  958. ssrcs = this.modifiedSSRCs["addMuted"];
  959. this.modifiedSSRCs["addMuted"] = [];
  960. if(ssrcs && ssrcs.length) {
  961. ssrcs.forEach(function (ssrcObj) {
  962. var desc = createDescriptionNode(jingle, ssrcObj.mtype);
  963. var cname = Math.random().toString(36).substring(2);
  964. ssrcObj.ssrc.ssrcs.forEach(function (ssrc) {
  965. var sourceNode = desc.find(">source[ssrc=\"" +ssrc + "\"]");
  966. sourceNode.remove();
  967. var sourceXML = "<source " +
  968. "xmlns=\"urn:xmpp:jingle:apps:rtp:ssma:0\" ssrc=\"" +
  969. ssrc + "\">" +
  970. "<parameter xmlns=\"urn:xmpp:jingle:apps:rtp:ssma:0\"" +
  971. " value=\"" + ssrcObj.msid + "\" name=\"msid\"/>" +
  972. "<parameter xmlns=\"urn:xmpp:jingle:apps:rtp:ssma:0\"" +
  973. " value=\"" + cname + "\" name=\"cname\" />" + "</source>";
  974. desc.append(sourceXML);
  975. });
  976. ssrcObj.ssrc.groups.forEach(function (group) {
  977. var groupNode = desc.find(">ssrc-group[semantics=\"" +
  978. group.group.semantics + "\"]:has(source[ssrc=\"" + group.primarySSRC +
  979. "\"])");
  980. groupNode.remove();
  981. desc.append("<ssrc-group semantics=\"" +
  982. group.group.semantics +
  983. "\" xmlns=\"urn:xmpp:jingle:apps:rtp:ssma:0\"><source ssrc=\"" +
  984. group.group.ssrcs.split(" ").join("\"/><source ssrc=\"") + "\"/>" +
  985. "</ssrc-group>");
  986. });
  987. });
  988. }
  989. };
  990. /**
  991. * Fixes the outgoing jingle packets with action source-remove by removing the
  992. * nodes related to the muted streams, handles removing of muted stream
  993. * @param jingle the jingle packet that is going to be sent
  994. * @returns {boolean} true if the jingle has to be sent and false otherwise.
  995. */
  996. JingleSessionPC.prototype.fixSourceRemoveJingle = function(jingle) {
  997. var ssrcs = this.modifiedSSRCs["mute"];
  998. this.modifiedSSRCs["mute"] = [];
  999. if(ssrcs && ssrcs.length)
  1000. ssrcs.forEach(function (ssrcObj) {
  1001. ssrcObj.ssrc.ssrcs.forEach(function (ssrc) {
  1002. var sourceNode = $(jingle.tree()).find(">jingle>content[name=\"" +
  1003. ssrcObj.mtype + "\"]>description>source[ssrc=\"" +
  1004. ssrc + "\"]");
  1005. sourceNode.remove();
  1006. });
  1007. ssrcObj.ssrc.groups.forEach(function (group) {
  1008. var groupNode = $(jingle.tree()).find(">jingle>content[name=\"" +
  1009. ssrcObj.mtype + "\"]>description>ssrc-group[semantics=\"" +
  1010. group.group.semantics + "\"]:has(source[ssrc=\"" + group.primarySSRC +
  1011. "\"])");
  1012. groupNode.remove();
  1013. });
  1014. });
  1015. ssrcs = this.modifiedSSRCs["remove"];
  1016. this.modifiedSSRCs["remove"] = [];
  1017. if(ssrcs && ssrcs.length)
  1018. ssrcs.forEach(function (ssrcObj) {
  1019. var desc = createDescriptionNode(jingle, ssrcObj.mtype);
  1020. ssrcObj.ssrc.ssrcs.forEach(function (ssrc) {
  1021. var sourceNode = desc.find(">source[ssrc=\"" +ssrc + "\"]");
  1022. if(!sourceNode || !sourceNode.length) {
  1023. //Maybe we have to include cname, msid, etc here?
  1024. desc.append("<source " +
  1025. "xmlns=\"urn:xmpp:jingle:apps:rtp:ssma:0\" ssrc=\"" +
  1026. ssrc + "\"></source>");
  1027. }
  1028. });
  1029. ssrcObj.ssrc.groups.forEach(function (group) {
  1030. var groupNode = desc.find(">ssrc-group[semantics=\"" +
  1031. group.group.semantics + "\"]:has(source[ssrc=\"" + group.primarySSRC +
  1032. "\"])");
  1033. if(!groupNode || !groupNode.length) {
  1034. desc.append("<ssrc-group semantics=\"" +
  1035. group.group.semantics +
  1036. "\" xmlns=\"urn:xmpp:jingle:apps:rtp:ssma:0\"><source ssrc=\"" +
  1037. group.group.ssrcs.split(" ").join("\"/><source ssrc=\"") + "\"/>" +
  1038. "</ssrc-group>");
  1039. }
  1040. });
  1041. });
  1042. };
  1043. /**
  1044. * Returns the description node related to the passed content type. If the node
  1045. * doesn't exists it will be created.
  1046. * @param jingle - the jingle packet
  1047. * @param mtype - the content type(audio, video, etc.)
  1048. */
  1049. function createDescriptionNode(jingle, mtype) {
  1050. var content = $(jingle.tree()).find(">jingle>content[name=\"" +
  1051. mtype + "\"]");
  1052. if(!content || !content.length) {
  1053. $(jingle.tree()).find(">jingle").append(
  1054. "<content name=\"" + mtype + "\"></content>");
  1055. content = $(jingle.tree()).find(">jingle>content[name=\"" +
  1056. mtype + "\"]");
  1057. }
  1058. var desc = content.find(">description");
  1059. if(!desc || !desc.length) {
  1060. content.append("<description " +
  1061. "xmlns=\"urn:xmpp:jingle:apps:rtp:1\" media=\"" +
  1062. mtype + "\"></description>");
  1063. desc = content.find(">description");
  1064. }
  1065. return desc;
  1066. }
  1067. module.exports = JingleSessionPC;