您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

strophe.jingle.session.js 45KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  1. /* jshint -W117 */
  2. // Jingle stuff
  3. function JingleSession(me, sid, connection) {
  4. this.me = me;
  5. this.sid = sid;
  6. this.connection = connection;
  7. this.initiator = null;
  8. this.responder = null;
  9. this.isInitiator = null;
  10. this.peerjid = null;
  11. this.state = null;
  12. this.localSDP = null;
  13. this.remoteSDP = null;
  14. this.relayedStreams = [];
  15. this.remoteStreams = [];
  16. this.startTime = null;
  17. this.stopTime = null;
  18. this.media_constraints = null;
  19. this.pc_constraints = null;
  20. this.ice_config = {};
  21. this.drip_container = [];
  22. this.usetrickle = true;
  23. this.usepranswer = false; // early transport warmup -- mind you, this might fail. depends on webrtc issue 1718
  24. this.usedrip = false; // dripping is sending trickle candidates not one-by-one
  25. this.hadstuncandidate = false;
  26. this.hadturncandidate = false;
  27. this.lasticecandidate = false;
  28. this.statsinterval = null;
  29. this.reason = null;
  30. this.addssrc = [];
  31. this.removessrc = [];
  32. this.pendingop = null;
  33. this.switchstreams = false;
  34. this.wait = true;
  35. this.localStreamsSSRC = null;
  36. /**
  37. * The indicator which determines whether the (local) video has been muted
  38. * in response to a user command in contrast to an automatic decision made
  39. * by the application logic.
  40. */
  41. this.videoMuteByUser = false;
  42. }
  43. JingleSession.prototype.initiate = function (peerjid, isInitiator) {
  44. var self = this;
  45. if (this.state !== null) {
  46. console.error('attempt to initiate on session ' + this.sid +
  47. 'in state ' + this.state);
  48. return;
  49. }
  50. this.isInitiator = isInitiator;
  51. this.state = 'pending';
  52. this.initiator = isInitiator ? this.me : peerjid;
  53. this.responder = !isInitiator ? this.me : peerjid;
  54. this.peerjid = peerjid;
  55. this.hadstuncandidate = false;
  56. this.hadturncandidate = false;
  57. this.lasticecandidate = false;
  58. this.peerconnection
  59. = new TraceablePeerConnection(
  60. this.connection.jingle.ice_config,
  61. this.connection.jingle.pc_constraints );
  62. this.peerconnection.onicecandidate = function (event) {
  63. self.sendIceCandidate(event.candidate);
  64. };
  65. this.peerconnection.onaddstream = function (event) {
  66. self.remoteStreams.push(event.stream);
  67. console.log("REMOTE STREAM ADDED: " + event.stream + " - " + event.stream.id);
  68. $(document).trigger('remotestreamadded.jingle', [event, self.sid]);
  69. };
  70. this.peerconnection.onremovestream = function (event) {
  71. // Remove the stream from remoteStreams
  72. var streamIdx = self.remoteStreams.indexOf(event.stream);
  73. if(streamIdx !== -1){
  74. self.remoteStreams.splice(streamIdx, 1);
  75. }
  76. // FIXME: remotestreamremoved.jingle not defined anywhere(unused)
  77. $(document).trigger('remotestreamremoved.jingle', [event, self.sid]);
  78. };
  79. this.peerconnection.onsignalingstatechange = function (event) {
  80. if (!(self && self.peerconnection)) return;
  81. };
  82. this.peerconnection.oniceconnectionstatechange = function (event) {
  83. if (!(self && self.peerconnection)) return;
  84. switch (self.peerconnection.iceConnectionState) {
  85. case 'connected':
  86. this.startTime = new Date();
  87. break;
  88. case 'disconnected':
  89. this.stopTime = new Date();
  90. break;
  91. }
  92. $(document).trigger('iceconnectionstatechange.jingle', [self.sid, self]);
  93. };
  94. // add any local and relayed stream
  95. RTC.localStreams.forEach(function(stream) {
  96. self.peerconnection.addStream(stream.getOriginalStream());
  97. });
  98. this.relayedStreams.forEach(function(stream) {
  99. self.peerconnection.addStream(stream);
  100. });
  101. };
  102. JingleSession.prototype.accept = function () {
  103. var self = this;
  104. this.state = 'active';
  105. var pranswer = this.peerconnection.localDescription;
  106. if (!pranswer || pranswer.type != 'pranswer') {
  107. return;
  108. }
  109. console.log('going from pranswer to answer');
  110. if (this.usetrickle) {
  111. // remove candidates already sent from session-accept
  112. var lines = SDPUtil.find_lines(pranswer.sdp, 'a=candidate:');
  113. for (var i = 0; i < lines.length; i++) {
  114. pranswer.sdp = pranswer.sdp.replace(lines[i] + '\r\n', '');
  115. }
  116. }
  117. while (SDPUtil.find_line(pranswer.sdp, 'a=inactive')) {
  118. // FIXME: change any inactive to sendrecv or whatever they were originally
  119. pranswer.sdp = pranswer.sdp.replace('a=inactive', 'a=sendrecv');
  120. }
  121. pranswer = simulcast.reverseTransformLocalDescription(pranswer);
  122. var prsdp = new SDP(pranswer.sdp);
  123. var accept = $iq({to: this.peerjid,
  124. type: 'set'})
  125. .c('jingle', {xmlns: 'urn:xmpp:jingle:1',
  126. action: 'session-accept',
  127. initiator: this.initiator,
  128. responder: this.responder,
  129. sid: this.sid });
  130. prsdp.toJingle(accept, this.initiator == this.me ? 'initiator' : 'responder', this.localStreamsSSRC);
  131. var sdp = this.peerconnection.localDescription.sdp;
  132. while (SDPUtil.find_line(sdp, 'a=inactive')) {
  133. // FIXME: change any inactive to sendrecv or whatever they were originally
  134. sdp = sdp.replace('a=inactive', 'a=sendrecv');
  135. }
  136. this.peerconnection.setLocalDescription(new RTCSessionDescription({type: 'answer', sdp: sdp}),
  137. function () {
  138. //console.log('setLocalDescription success');
  139. $(document).trigger('setLocalDescription.jingle', [self.sid]);
  140. this.connection.sendIQ(accept,
  141. function () {
  142. var ack = {};
  143. ack.source = 'answer';
  144. $(document).trigger('ack.jingle', [self.sid, ack]);
  145. },
  146. function (stanza) {
  147. var error = ($(stanza).find('error').length) ? {
  148. code: $(stanza).find('error').attr('code'),
  149. reason: $(stanza).find('error :first')[0].tagName
  150. }:{};
  151. error.source = 'answer';
  152. JingleSession.onJingleError(self.sid, error);
  153. },
  154. 10000);
  155. },
  156. function (e) {
  157. console.error('setLocalDescription failed', e);
  158. }
  159. );
  160. };
  161. JingleSession.prototype.terminate = function (reason) {
  162. this.state = 'ended';
  163. this.reason = reason;
  164. this.peerconnection.close();
  165. if (this.statsinterval !== null) {
  166. window.clearInterval(this.statsinterval);
  167. this.statsinterval = null;
  168. }
  169. };
  170. JingleSession.prototype.active = function () {
  171. return this.state == 'active';
  172. };
  173. JingleSession.prototype.sendIceCandidate = function (candidate) {
  174. var self = this;
  175. if (candidate && !this.lasticecandidate) {
  176. var ice = SDPUtil.iceparams(this.localSDP.media[candidate.sdpMLineIndex], this.localSDP.session);
  177. var jcand = SDPUtil.candidateToJingle(candidate.candidate);
  178. if (!(ice && jcand)) {
  179. console.error('failed to get ice && jcand');
  180. return;
  181. }
  182. ice.xmlns = 'urn:xmpp:jingle:transports:ice-udp:1';
  183. if (jcand.type === 'srflx') {
  184. this.hadstuncandidate = true;
  185. } else if (jcand.type === 'relay') {
  186. this.hadturncandidate = true;
  187. }
  188. if (this.usetrickle) {
  189. if (this.usedrip) {
  190. if (this.drip_container.length === 0) {
  191. // start 20ms callout
  192. window.setTimeout(function () {
  193. if (self.drip_container.length === 0) return;
  194. self.sendIceCandidates(self.drip_container);
  195. self.drip_container = [];
  196. }, 20);
  197. }
  198. this.drip_container.push(candidate);
  199. return;
  200. } else {
  201. self.sendIceCandidate([candidate]);
  202. }
  203. }
  204. } else {
  205. //console.log('sendIceCandidate: last candidate.');
  206. if (!this.usetrickle) {
  207. //console.log('should send full offer now...');
  208. var init = $iq({to: this.peerjid,
  209. type: 'set'})
  210. .c('jingle', {xmlns: 'urn:xmpp:jingle:1',
  211. action: this.peerconnection.localDescription.type == 'offer' ? 'session-initiate' : 'session-accept',
  212. initiator: this.initiator,
  213. sid: this.sid});
  214. this.localSDP = new SDP(this.peerconnection.localDescription.sdp);
  215. var self = this;
  216. var sendJingle = function (ssrc) {
  217. if(!ssrc)
  218. ssrc = {};
  219. self.localSDP.toJingle(init, self.initiator == self.me ? 'initiator' : 'responder', ssrc);
  220. self.connection.sendIQ(init,
  221. function () {
  222. //console.log('session initiate ack');
  223. var ack = {};
  224. ack.source = 'offer';
  225. $(document).trigger('ack.jingle', [self.sid, ack]);
  226. },
  227. function (stanza) {
  228. self.state = 'error';
  229. self.peerconnection.close();
  230. var error = ($(stanza).find('error').length) ? {
  231. code: $(stanza).find('error').attr('code'),
  232. reason: $(stanza).find('error :first')[0].tagName,
  233. }:{};
  234. error.source = 'offer';
  235. JingleSession.onJingleError(self.sid, error);
  236. },
  237. 10000);
  238. }
  239. sendJingle();
  240. }
  241. this.lasticecandidate = true;
  242. console.log('Have we encountered any srflx candidates? ' + this.hadstuncandidate);
  243. console.log('Have we encountered any relay candidates? ' + this.hadturncandidate);
  244. if (!(this.hadstuncandidate || this.hadturncandidate) && this.peerconnection.signalingState != 'closed') {
  245. $(document).trigger('nostuncandidates.jingle', [this.sid]);
  246. }
  247. }
  248. };
  249. JingleSession.prototype.sendIceCandidates = function (candidates) {
  250. console.log('sendIceCandidates', candidates);
  251. var cand = $iq({to: this.peerjid, type: 'set'})
  252. .c('jingle', {xmlns: 'urn:xmpp:jingle:1',
  253. action: 'transport-info',
  254. initiator: this.initiator,
  255. sid: this.sid});
  256. for (var mid = 0; mid < this.localSDP.media.length; mid++) {
  257. var cands = candidates.filter(function (el) { return el.sdpMLineIndex == mid; });
  258. var mline = SDPUtil.parse_mline(this.localSDP.media[mid].split('\r\n')[0]);
  259. if (cands.length > 0) {
  260. var ice = SDPUtil.iceparams(this.localSDP.media[mid], this.localSDP.session);
  261. ice.xmlns = 'urn:xmpp:jingle:transports:ice-udp:1';
  262. cand.c('content', {creator: this.initiator == this.me ? 'initiator' : 'responder',
  263. name: (cands[0].sdpMid? cands[0].sdpMid : mline.media)
  264. }).c('transport', ice);
  265. for (var i = 0; i < cands.length; i++) {
  266. cand.c('candidate', SDPUtil.candidateToJingle(cands[i].candidate)).up();
  267. }
  268. // add fingerprint
  269. if (SDPUtil.find_line(this.localSDP.media[mid], 'a=fingerprint:', this.localSDP.session)) {
  270. var tmp = SDPUtil.parse_fingerprint(SDPUtil.find_line(this.localSDP.media[mid], 'a=fingerprint:', this.localSDP.session));
  271. tmp.required = true;
  272. cand.c(
  273. 'fingerprint',
  274. {xmlns: 'urn:xmpp:jingle:apps:dtls:0'})
  275. .t(tmp.fingerprint);
  276. delete tmp.fingerprint;
  277. cand.attrs(tmp);
  278. cand.up();
  279. }
  280. cand.up(); // transport
  281. cand.up(); // content
  282. }
  283. }
  284. // might merge last-candidate notification into this, but it is called alot later. See webrtc issue #2340
  285. //console.log('was this the last candidate', this.lasticecandidate);
  286. this.connection.sendIQ(cand,
  287. function () {
  288. var ack = {};
  289. ack.source = 'transportinfo';
  290. $(document).trigger('ack.jingle', [this.sid, ack]);
  291. },
  292. function (stanza) {
  293. var error = ($(stanza).find('error').length) ? {
  294. code: $(stanza).find('error').attr('code'),
  295. reason: $(stanza).find('error :first')[0].tagName,
  296. }:{};
  297. error.source = 'transportinfo';
  298. JingleSession.onJingleError(this.sid, error);
  299. },
  300. 10000);
  301. };
  302. JingleSession.prototype.sendOffer = function () {
  303. //console.log('sendOffer...');
  304. var self = this;
  305. this.peerconnection.createOffer(function (sdp) {
  306. self.createdOffer(sdp);
  307. },
  308. function (e) {
  309. console.error('createOffer failed', e);
  310. },
  311. this.media_constraints
  312. );
  313. };
  314. JingleSession.prototype.createdOffer = function (sdp) {
  315. //console.log('createdOffer', sdp);
  316. var self = this;
  317. this.localSDP = new SDP(sdp.sdp);
  318. //this.localSDP.mangle();
  319. var sendJingle = function () {
  320. var init = $iq({to: this.peerjid,
  321. type: 'set'})
  322. .c('jingle', {xmlns: 'urn:xmpp:jingle:1',
  323. action: 'session-initiate',
  324. initiator: this.initiator,
  325. sid: this.sid});
  326. this.localSDP.toJingle(init, this.initiator == this.me ? 'initiator' : 'responder', this.localStreamsSSRC);
  327. this.connection.sendIQ(init,
  328. function () {
  329. var ack = {};
  330. ack.source = 'offer';
  331. $(document).trigger('ack.jingle', [self.sid, ack]);
  332. },
  333. function (stanza) {
  334. self.state = 'error';
  335. self.peerconnection.close();
  336. var error = ($(stanza).find('error').length) ? {
  337. code: $(stanza).find('error').attr('code'),
  338. reason: $(stanza).find('error :first')[0].tagName,
  339. }:{};
  340. error.source = 'offer';
  341. JingleSession.onJingleError(self.sid, error);
  342. },
  343. 10000);
  344. }
  345. sdp.sdp = this.localSDP.raw;
  346. this.peerconnection.setLocalDescription(sdp,
  347. function () {
  348. if(this.usetrickle)
  349. {
  350. sendJingle();
  351. $(document).trigger('setLocalDescription.jingle', [self.sid]);
  352. }
  353. else
  354. $(document).trigger('setLocalDescription.jingle', [self.sid]);
  355. //console.log('setLocalDescription success');
  356. },
  357. function (e) {
  358. console.error('setLocalDescription failed', e);
  359. }
  360. );
  361. var cands = SDPUtil.find_lines(this.localSDP.raw, 'a=candidate:');
  362. for (var i = 0; i < cands.length; i++) {
  363. var cand = SDPUtil.parse_icecandidate(cands[i]);
  364. if (cand.type == 'srflx') {
  365. this.hadstuncandidate = true;
  366. } else if (cand.type == 'relay') {
  367. this.hadturncandidate = true;
  368. }
  369. }
  370. };
  371. JingleSession.prototype.setRemoteDescription = function (elem, desctype) {
  372. //console.log('setting remote description... ', desctype);
  373. this.remoteSDP = new SDP('');
  374. this.remoteSDP.fromJingle(elem);
  375. if (this.peerconnection.remoteDescription !== null) {
  376. console.log('setRemoteDescription when remote description is not null, should be pranswer', this.peerconnection.remoteDescription);
  377. if (this.peerconnection.remoteDescription.type == 'pranswer') {
  378. var pranswer = new SDP(this.peerconnection.remoteDescription.sdp);
  379. for (var i = 0; i < pranswer.media.length; i++) {
  380. // make sure we have ice ufrag and pwd
  381. if (!SDPUtil.find_line(this.remoteSDP.media[i], 'a=ice-ufrag:', this.remoteSDP.session)) {
  382. if (SDPUtil.find_line(pranswer.media[i], 'a=ice-ufrag:', pranswer.session)) {
  383. this.remoteSDP.media[i] += SDPUtil.find_line(pranswer.media[i], 'a=ice-ufrag:', pranswer.session) + '\r\n';
  384. } else {
  385. console.warn('no ice ufrag?');
  386. }
  387. if (SDPUtil.find_line(pranswer.media[i], 'a=ice-pwd:', pranswer.session)) {
  388. this.remoteSDP.media[i] += SDPUtil.find_line(pranswer.media[i], 'a=ice-pwd:', pranswer.session) + '\r\n';
  389. } else {
  390. console.warn('no ice pwd?');
  391. }
  392. }
  393. // copy over candidates
  394. var lines = SDPUtil.find_lines(pranswer.media[i], 'a=candidate:');
  395. for (var j = 0; j < lines.length; j++) {
  396. this.remoteSDP.media[i] += lines[j] + '\r\n';
  397. }
  398. }
  399. this.remoteSDP.raw = this.remoteSDP.session + this.remoteSDP.media.join('');
  400. }
  401. }
  402. var remotedesc = new RTCSessionDescription({type: desctype, sdp: this.remoteSDP.raw});
  403. this.peerconnection.setRemoteDescription(remotedesc,
  404. function () {
  405. //console.log('setRemoteDescription success');
  406. },
  407. function (e) {
  408. console.error('setRemoteDescription error', e);
  409. JingleSession.onJingleFatalError(self, e);
  410. }
  411. );
  412. };
  413. JingleSession.prototype.addIceCandidate = function (elem) {
  414. var self = this;
  415. if (this.peerconnection.signalingState == 'closed') {
  416. return;
  417. }
  418. if (!this.peerconnection.remoteDescription && this.peerconnection.signalingState == 'have-local-offer') {
  419. console.log('trickle ice candidate arriving before session accept...');
  420. // create a PRANSWER for setRemoteDescription
  421. if (!this.remoteSDP) {
  422. var cobbled = 'v=0\r\n' +
  423. 'o=- ' + '1923518516' + ' 2 IN IP4 0.0.0.0\r\n' +// FIXME
  424. 's=-\r\n' +
  425. 't=0 0\r\n';
  426. // first, take some things from the local description
  427. for (var i = 0; i < this.localSDP.media.length; i++) {
  428. cobbled += SDPUtil.find_line(this.localSDP.media[i], 'm=') + '\r\n';
  429. cobbled += SDPUtil.find_lines(this.localSDP.media[i], 'a=rtpmap:').join('\r\n') + '\r\n';
  430. if (SDPUtil.find_line(this.localSDP.media[i], 'a=mid:')) {
  431. cobbled += SDPUtil.find_line(this.localSDP.media[i], 'a=mid:') + '\r\n';
  432. }
  433. cobbled += 'a=inactive\r\n';
  434. }
  435. this.remoteSDP = new SDP(cobbled);
  436. }
  437. // then add things like ice and dtls from remote candidate
  438. elem.each(function () {
  439. for (var i = 0; i < self.remoteSDP.media.length; i++) {
  440. if (SDPUtil.find_line(self.remoteSDP.media[i], 'a=mid:' + $(this).attr('name')) ||
  441. self.remoteSDP.media[i].indexOf('m=' + $(this).attr('name')) === 0) {
  442. if (!SDPUtil.find_line(self.remoteSDP.media[i], 'a=ice-ufrag:')) {
  443. var tmp = $(this).find('transport');
  444. self.remoteSDP.media[i] += 'a=ice-ufrag:' + tmp.attr('ufrag') + '\r\n';
  445. self.remoteSDP.media[i] += 'a=ice-pwd:' + tmp.attr('pwd') + '\r\n';
  446. tmp = $(this).find('transport>fingerprint');
  447. if (tmp.length) {
  448. self.remoteSDP.media[i] += 'a=fingerprint:' + tmp.attr('hash') + ' ' + tmp.text() + '\r\n';
  449. } else {
  450. console.log('no dtls fingerprint (webrtc issue #1718?)');
  451. self.remoteSDP.media[i] += 'a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:BAADBAADBAADBAADBAADBAADBAADBAADBAADBAAD\r\n';
  452. }
  453. break;
  454. }
  455. }
  456. }
  457. });
  458. this.remoteSDP.raw = this.remoteSDP.session + this.remoteSDP.media.join('');
  459. // we need a complete SDP with ice-ufrag/ice-pwd in all parts
  460. // this makes the assumption that the PRANSWER is constructed such that the ice-ufrag is in all mediaparts
  461. // but it could be in the session part as well. since the code above constructs this sdp this can't happen however
  462. var iscomplete = this.remoteSDP.media.filter(function (mediapart) {
  463. return SDPUtil.find_line(mediapart, 'a=ice-ufrag:');
  464. }).length == this.remoteSDP.media.length;
  465. if (iscomplete) {
  466. console.log('setting pranswer');
  467. try {
  468. this.peerconnection.setRemoteDescription(new RTCSessionDescription({type: 'pranswer', sdp: this.remoteSDP.raw }),
  469. function() {
  470. },
  471. function(e) {
  472. console.log('setRemoteDescription pranswer failed', e.toString());
  473. });
  474. } catch (e) {
  475. console.error('setting pranswer failed', e);
  476. }
  477. } else {
  478. //console.log('not yet setting pranswer');
  479. }
  480. }
  481. // operate on each content element
  482. elem.each(function () {
  483. // would love to deactivate this, but firefox still requires it
  484. var idx = -1;
  485. var i;
  486. for (i = 0; i < self.remoteSDP.media.length; i++) {
  487. if (SDPUtil.find_line(self.remoteSDP.media[i], 'a=mid:' + $(this).attr('name')) ||
  488. self.remoteSDP.media[i].indexOf('m=' + $(this).attr('name')) === 0) {
  489. idx = i;
  490. break;
  491. }
  492. }
  493. if (idx == -1) { // fall back to localdescription
  494. for (i = 0; i < self.localSDP.media.length; i++) {
  495. if (SDPUtil.find_line(self.localSDP.media[i], 'a=mid:' + $(this).attr('name')) ||
  496. self.localSDP.media[i].indexOf('m=' + $(this).attr('name')) === 0) {
  497. idx = i;
  498. break;
  499. }
  500. }
  501. }
  502. var name = $(this).attr('name');
  503. // TODO: check ice-pwd and ice-ufrag?
  504. $(this).find('transport>candidate').each(function () {
  505. var line, candidate;
  506. line = SDPUtil.candidateFromJingle(this);
  507. candidate = new RTCIceCandidate({sdpMLineIndex: idx,
  508. sdpMid: name,
  509. candidate: line});
  510. try {
  511. self.peerconnection.addIceCandidate(candidate);
  512. } catch (e) {
  513. console.error('addIceCandidate failed', e.toString(), line);
  514. }
  515. });
  516. });
  517. };
  518. JingleSession.prototype.sendAnswer = function (provisional) {
  519. //console.log('createAnswer', provisional);
  520. var self = this;
  521. this.peerconnection.createAnswer(
  522. function (sdp) {
  523. self.createdAnswer(sdp, provisional);
  524. },
  525. function (e) {
  526. console.error('createAnswer failed', e);
  527. },
  528. this.media_constraints
  529. );
  530. };
  531. JingleSession.prototype.createdAnswer = function (sdp, provisional) {
  532. //console.log('createAnswer callback');
  533. var self = this;
  534. this.localSDP = new SDP(sdp.sdp);
  535. //this.localSDP.mangle();
  536. this.usepranswer = provisional === true;
  537. if (this.usetrickle) {
  538. if (this.usepranswer) {
  539. sdp.type = 'pranswer';
  540. for (var i = 0; i < this.localSDP.media.length; i++) {
  541. this.localSDP.media[i] = this.localSDP.media[i].replace('a=sendrecv\r\n', 'a=inactive\r\n');
  542. }
  543. this.localSDP.raw = this.localSDP.session + '\r\n' + this.localSDP.media.join('');
  544. }
  545. }
  546. var self = this;
  547. var sendJingle = function (ssrcs) {
  548. var accept = $iq({to: self.peerjid,
  549. type: 'set'})
  550. .c('jingle', {xmlns: 'urn:xmpp:jingle:1',
  551. action: 'session-accept',
  552. initiator: self.initiator,
  553. responder: self.responder,
  554. sid: self.sid });
  555. var publicLocalDesc = simulcast.reverseTransformLocalDescription(sdp);
  556. var publicLocalSDP = new SDP(publicLocalDesc.sdp);
  557. publicLocalSDP.toJingle(accept, self.initiator == self.me ? 'initiator' : 'responder', ssrcs);
  558. this.connection.sendIQ(accept,
  559. function () {
  560. var ack = {};
  561. ack.source = 'answer';
  562. $(document).trigger('ack.jingle', [self.sid, ack]);
  563. },
  564. function (stanza) {
  565. var error = ($(stanza).find('error').length) ? {
  566. code: $(stanza).find('error').attr('code'),
  567. reason: $(stanza).find('error :first')[0].tagName,
  568. }:{};
  569. error.source = 'answer';
  570. JingleSession.onJingleError(self.sid, error);
  571. },
  572. 10000);
  573. }
  574. sdp.sdp = this.localSDP.raw;
  575. this.peerconnection.setLocalDescription(sdp,
  576. function () {
  577. //console.log('setLocalDescription success');
  578. if (self.usetrickle && !self.usepranswer) {
  579. sendJingle();
  580. $(document).trigger('setLocalDescription.jingle', [self.sid]);
  581. }
  582. else
  583. $(document).trigger('setLocalDescription.jingle', [self.sid]);
  584. },
  585. function (e) {
  586. console.error('setLocalDescription failed', e);
  587. }
  588. );
  589. var cands = SDPUtil.find_lines(this.localSDP.raw, 'a=candidate:');
  590. for (var j = 0; j < cands.length; j++) {
  591. var cand = SDPUtil.parse_icecandidate(cands[j]);
  592. if (cand.type == 'srflx') {
  593. this.hadstuncandidate = true;
  594. } else if (cand.type == 'relay') {
  595. this.hadturncandidate = true;
  596. }
  597. }
  598. };
  599. JingleSession.prototype.sendTerminate = function (reason, text) {
  600. var self = this,
  601. term = $iq({to: this.peerjid,
  602. type: 'set'})
  603. .c('jingle', {xmlns: 'urn:xmpp:jingle:1',
  604. action: 'session-terminate',
  605. initiator: this.initiator,
  606. sid: this.sid})
  607. .c('reason')
  608. .c(reason || 'success');
  609. if (text) {
  610. term.up().c('text').t(text);
  611. }
  612. this.connection.sendIQ(term,
  613. function () {
  614. self.peerconnection.close();
  615. self.peerconnection = null;
  616. self.terminate();
  617. var ack = {};
  618. ack.source = 'terminate';
  619. $(document).trigger('ack.jingle', [self.sid, ack]);
  620. },
  621. function (stanza) {
  622. var error = ($(stanza).find('error').length) ? {
  623. code: $(stanza).find('error').attr('code'),
  624. reason: $(stanza).find('error :first')[0].tagName,
  625. }:{};
  626. $(document).trigger('ack.jingle', [self.sid, error]);
  627. },
  628. 10000);
  629. if (this.statsinterval !== null) {
  630. window.clearInterval(this.statsinterval);
  631. this.statsinterval = null;
  632. }
  633. };
  634. JingleSession.prototype.addSource = function (elem, fromJid) {
  635. var self = this;
  636. // FIXME: dirty waiting
  637. if (!this.peerconnection.localDescription)
  638. {
  639. console.warn("addSource - localDescription not ready yet")
  640. setTimeout(function()
  641. {
  642. self.addSource(elem, fromJid);
  643. },
  644. 200
  645. );
  646. return;
  647. }
  648. console.log('addssrc', new Date().getTime());
  649. console.log('ice', this.peerconnection.iceConnectionState);
  650. var sdp = new SDP(this.peerconnection.remoteDescription.sdp);
  651. var mySdp = new SDP(this.peerconnection.localDescription.sdp);
  652. $(elem).each(function (idx, content) {
  653. var name = $(content).attr('name');
  654. var lines = '';
  655. tmp = $(content).find('ssrc-group[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]').each(function() {
  656. var semantics = this.getAttribute('semantics');
  657. var ssrcs = $(this).find('>source').map(function () {
  658. return this.getAttribute('ssrc');
  659. }).get();
  660. if (ssrcs.length != 0) {
  661. lines += 'a=ssrc-group:' + semantics + ' ' + ssrcs.join(' ') + '\r\n';
  662. }
  663. });
  664. tmp = $(content).find('source[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]'); // can handle both >source and >description>source
  665. tmp.each(function () {
  666. var ssrc = $(this).attr('ssrc');
  667. if(mySdp.containsSSRC(ssrc)){
  668. /**
  669. * This happens when multiple participants change their streams at the same time and
  670. * ColibriFocus.modifySources have to wait for stable state. In the meantime multiple
  671. * addssrc are scheduled for update IQ. See
  672. */
  673. console.warn("Got add stream request for my own ssrc: "+ssrc);
  674. return;
  675. }
  676. $(this).find('>parameter').each(function () {
  677. lines += 'a=ssrc:' + ssrc + ' ' + $(this).attr('name');
  678. if ($(this).attr('value') && $(this).attr('value').length)
  679. lines += ':' + $(this).attr('value');
  680. lines += '\r\n';
  681. });
  682. });
  683. sdp.media.forEach(function(media, idx) {
  684. if (!SDPUtil.find_line(media, 'a=mid:' + name))
  685. return;
  686. sdp.media[idx] += lines;
  687. if (!self.addssrc[idx]) self.addssrc[idx] = '';
  688. self.addssrc[idx] += lines;
  689. });
  690. sdp.raw = sdp.session + sdp.media.join('');
  691. });
  692. this.modifySources();
  693. };
  694. JingleSession.prototype.removeSource = function (elem, fromJid) {
  695. var self = this;
  696. // FIXME: dirty waiting
  697. if (!this.peerconnection.localDescription)
  698. {
  699. console.warn("removeSource - localDescription not ready yet")
  700. setTimeout(function()
  701. {
  702. self.removeSource(elem, fromJid);
  703. },
  704. 200
  705. );
  706. return;
  707. }
  708. console.log('removessrc', new Date().getTime());
  709. console.log('ice', this.peerconnection.iceConnectionState);
  710. var sdp = new SDP(this.peerconnection.remoteDescription.sdp);
  711. var mySdp = new SDP(this.peerconnection.localDescription.sdp);
  712. $(elem).each(function (idx, content) {
  713. var name = $(content).attr('name');
  714. var lines = '';
  715. tmp = $(content).find('ssrc-group[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]').each(function() {
  716. var semantics = this.getAttribute('semantics');
  717. var ssrcs = $(this).find('>source').map(function () {
  718. return this.getAttribute('ssrc');
  719. }).get();
  720. if (ssrcs.length != 0) {
  721. lines += 'a=ssrc-group:' + semantics + ' ' + ssrcs.join(' ') + '\r\n';
  722. }
  723. });
  724. tmp = $(content).find('source[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]'); // can handle both >source and >description>source
  725. tmp.each(function () {
  726. var ssrc = $(this).attr('ssrc');
  727. // This should never happen, but can be useful for bug detection
  728. if(mySdp.containsSSRC(ssrc)){
  729. console.error("Got remove stream request for my own ssrc: "+ssrc);
  730. return;
  731. }
  732. $(this).find('>parameter').each(function () {
  733. lines += 'a=ssrc:' + ssrc + ' ' + $(this).attr('name');
  734. if ($(this).attr('value') && $(this).attr('value').length)
  735. lines += ':' + $(this).attr('value');
  736. lines += '\r\n';
  737. });
  738. });
  739. sdp.media.forEach(function(media, idx) {
  740. if (!SDPUtil.find_line(media, 'a=mid:' + name))
  741. return;
  742. sdp.media[idx] += lines;
  743. if (!self.removessrc[idx]) self.removessrc[idx] = '';
  744. self.removessrc[idx] += lines;
  745. });
  746. sdp.raw = sdp.session + sdp.media.join('');
  747. });
  748. this.modifySources();
  749. };
  750. JingleSession.prototype.modifySources = function (successCallback) {
  751. var self = this;
  752. if (this.peerconnection.signalingState == 'closed') return;
  753. if (!(this.addssrc.length || this.removessrc.length || this.pendingop !== null || this.switchstreams)){
  754. // There is nothing to do since scheduled job might have been executed by another succeeding call
  755. $(document).trigger('setLocalDescription.jingle', [self.sid]);
  756. if(successCallback){
  757. successCallback();
  758. }
  759. return;
  760. }
  761. // FIXME: this is a big hack
  762. // https://code.google.com/p/webrtc/issues/detail?id=2688
  763. // ^ has been fixed.
  764. if (!(this.peerconnection.signalingState == 'stable' && this.peerconnection.iceConnectionState == 'connected')) {
  765. console.warn('modifySources not yet', this.peerconnection.signalingState, this.peerconnection.iceConnectionState);
  766. this.wait = true;
  767. window.setTimeout(function() { self.modifySources(successCallback); }, 250);
  768. return;
  769. }
  770. if (this.wait) {
  771. window.setTimeout(function() { self.modifySources(successCallback); }, 2500);
  772. this.wait = false;
  773. return;
  774. }
  775. // Reset switch streams flag
  776. this.switchstreams = false;
  777. var sdp = new SDP(this.peerconnection.remoteDescription.sdp);
  778. // add sources
  779. this.addssrc.forEach(function(lines, idx) {
  780. sdp.media[idx] += lines;
  781. });
  782. this.addssrc = [];
  783. // remove sources
  784. this.removessrc.forEach(function(lines, idx) {
  785. lines = lines.split('\r\n');
  786. lines.pop(); // remove empty last element;
  787. lines.forEach(function(line) {
  788. sdp.media[idx] = sdp.media[idx].replace(line + '\r\n', '');
  789. });
  790. });
  791. this.removessrc = [];
  792. // FIXME:
  793. // this was a hack for the situation when only one peer exists
  794. // in the conference.
  795. // check if still required and remove
  796. if (sdp.media[0])
  797. sdp.media[0] = sdp.media[0].replace('a=recvonly', 'a=sendrecv');
  798. if (sdp.media[1])
  799. sdp.media[1] = sdp.media[1].replace('a=recvonly', 'a=sendrecv');
  800. sdp.raw = sdp.session + sdp.media.join('');
  801. this.peerconnection.setRemoteDescription(new RTCSessionDescription({type: 'offer', sdp: sdp.raw}),
  802. function() {
  803. if(self.signalingState == 'closed') {
  804. console.error("createAnswer attempt on closed state");
  805. return;
  806. }
  807. self.peerconnection.createAnswer(
  808. function(modifiedAnswer) {
  809. // change video direction, see https://github.com/jitsi/jitmeet/issues/41
  810. if (self.pendingop !== null) {
  811. var sdp = new SDP(modifiedAnswer.sdp);
  812. if (sdp.media.length > 1) {
  813. switch(self.pendingop) {
  814. case 'mute':
  815. sdp.media[1] = sdp.media[1].replace('a=sendrecv', 'a=recvonly');
  816. break;
  817. case 'unmute':
  818. sdp.media[1] = sdp.media[1].replace('a=recvonly', 'a=sendrecv');
  819. break;
  820. }
  821. sdp.raw = sdp.session + sdp.media.join('');
  822. modifiedAnswer.sdp = sdp.raw;
  823. }
  824. self.pendingop = null;
  825. }
  826. // FIXME: pushing down an answer while ice connection state
  827. // is still checking is bad...
  828. //console.log(self.peerconnection.iceConnectionState);
  829. // trying to work around another chrome bug
  830. //modifiedAnswer.sdp = modifiedAnswer.sdp.replace(/a=setup:active/g, 'a=setup:actpass');
  831. self.peerconnection.setLocalDescription(modifiedAnswer,
  832. function() {
  833. //console.log('modified setLocalDescription ok');
  834. $(document).trigger('setLocalDescription.jingle', [self.sid]);
  835. if(successCallback){
  836. successCallback();
  837. }
  838. },
  839. function(error) {
  840. console.error('modified setLocalDescription failed', error);
  841. }
  842. );
  843. },
  844. function(error) {
  845. console.error('modified answer failed', error);
  846. }
  847. );
  848. },
  849. function(error) {
  850. console.error('modify failed', error);
  851. }
  852. );
  853. };
  854. /**
  855. * Switches video streams.
  856. * @param new_stream new stream that will be used as video of this session.
  857. * @param oldStream old video stream of this session.
  858. * @param success_callback callback executed after successful stream switch.
  859. */
  860. JingleSession.prototype.switchStreams = function (new_stream, oldStream, success_callback) {
  861. var self = this;
  862. // Remember SDP to figure out added/removed SSRCs
  863. var oldSdp = null;
  864. if(self.peerconnection) {
  865. if(self.peerconnection.localDescription) {
  866. oldSdp = new SDP(self.peerconnection.localDescription.sdp);
  867. }
  868. self.peerconnection.removeStream(oldStream, true);
  869. self.peerconnection.addStream(new_stream);
  870. }
  871. RTC.switchVideoStreams(new_stream, oldStream);
  872. // Conference is not active
  873. if(!oldSdp || !self.peerconnection) {
  874. success_callback();
  875. return;
  876. }
  877. self.switchstreams = true;
  878. self.modifySources(function() {
  879. console.log('modify sources done');
  880. success_callback();
  881. var newSdp = new SDP(self.peerconnection.localDescription.sdp);
  882. console.log("SDPs", oldSdp, newSdp);
  883. self.notifyMySSRCUpdate(oldSdp, newSdp);
  884. });
  885. };
  886. /**
  887. * Figures out added/removed ssrcs and send update IQs.
  888. * @param old_sdp SDP object for old description.
  889. * @param new_sdp SDP object for new description.
  890. */
  891. JingleSession.prototype.notifyMySSRCUpdate = function (old_sdp, new_sdp) {
  892. if (!(this.peerconnection.signalingState == 'stable' &&
  893. this.peerconnection.iceConnectionState == 'connected')){
  894. console.log("Too early to send updates");
  895. return;
  896. }
  897. // send source-remove IQ.
  898. sdpDiffer = new SDPDiffer(new_sdp, old_sdp);
  899. var remove = $iq({to: this.peerjid, type: 'set'})
  900. .c('jingle', {
  901. xmlns: 'urn:xmpp:jingle:1',
  902. action: 'source-remove',
  903. initiator: this.initiator,
  904. sid: this.sid
  905. }
  906. );
  907. var removed = sdpDiffer.toJingle(remove);
  908. if (removed) {
  909. this.connection.sendIQ(remove,
  910. function (res) {
  911. console.info('got remove result', res);
  912. },
  913. function (err) {
  914. console.error('got remove error', err);
  915. }
  916. );
  917. } else {
  918. console.log('removal not necessary');
  919. }
  920. // send source-add IQ.
  921. var sdpDiffer = new SDPDiffer(old_sdp, new_sdp);
  922. var add = $iq({to: this.peerjid, type: 'set'})
  923. .c('jingle', {
  924. xmlns: 'urn:xmpp:jingle:1',
  925. action: 'source-add',
  926. initiator: this.initiator,
  927. sid: this.sid
  928. }
  929. );
  930. var added = sdpDiffer.toJingle(add);
  931. if (added) {
  932. this.connection.sendIQ(add,
  933. function (res) {
  934. console.info('got add result', res);
  935. },
  936. function (err) {
  937. console.error('got add error', err);
  938. }
  939. );
  940. } else {
  941. console.log('addition not necessary');
  942. }
  943. };
  944. /**
  945. * Determines whether the (local) video is mute i.e. all video tracks are
  946. * disabled.
  947. *
  948. * @return <tt>true</tt> if the (local) video is mute i.e. all video tracks are
  949. * disabled; otherwise, <tt>false</tt>
  950. */
  951. JingleSession.prototype.isVideoMute = function () {
  952. var tracks = RTC.localVideo.getVideoTracks();
  953. var mute = true;
  954. for (var i = 0; i < tracks.length; ++i) {
  955. if (tracks[i].enabled) {
  956. mute = false;
  957. break;
  958. }
  959. }
  960. return mute;
  961. };
  962. /**
  963. * Mutes/unmutes the (local) video i.e. enables/disables all video tracks.
  964. *
  965. * @param mute <tt>true</tt> to mute the (local) video i.e. to disable all video
  966. * tracks; otherwise, <tt>false</tt>
  967. * @param callback a function to be invoked with <tt>mute</tt> after all video
  968. * tracks have been enabled/disabled. The function may, optionally, return
  969. * another function which is to be invoked after the whole mute/unmute operation
  970. * has completed successfully.
  971. * @param options an object which specifies optional arguments such as the
  972. * <tt>boolean</tt> key <tt>byUser</tt> with default value <tt>true</tt> which
  973. * specifies whether the method was initiated in response to a user command (in
  974. * contrast to an automatic decision made by the application logic)
  975. */
  976. JingleSession.prototype.setVideoMute = function (mute, callback, options) {
  977. var byUser;
  978. if (options) {
  979. byUser = options.byUser;
  980. if (typeof byUser === 'undefined') {
  981. byUser = true;
  982. }
  983. } else {
  984. byUser = true;
  985. }
  986. // The user's command to mute the (local) video takes precedence over any
  987. // automatic decision made by the application logic.
  988. if (byUser) {
  989. this.videoMuteByUser = mute;
  990. } else if (this.videoMuteByUser) {
  991. return;
  992. }
  993. if (mute == RTC.localVideo.isMuted())
  994. {
  995. // Even if no change occurs, the specified callback is to be executed.
  996. // The specified callback may, optionally, return a successCallback
  997. // which is to be executed as well.
  998. var successCallback = callback(mute);
  999. if (successCallback) {
  1000. successCallback();
  1001. }
  1002. } else {
  1003. RTC.localVideo.setMute(!mute);
  1004. this.hardMuteVideo(mute);
  1005. this.modifySources(callback(mute));
  1006. }
  1007. };
  1008. // SDP-based mute by going recvonly/sendrecv
  1009. // FIXME: should probably black out the screen as well
  1010. JingleSession.prototype.toggleVideoMute = function (callback) {
  1011. setVideoMute(RTC.localVideo.isMuted(), callback);
  1012. };
  1013. JingleSession.prototype.hardMuteVideo = function (muted) {
  1014. this.pendingop = muted ? 'mute' : 'unmute';
  1015. };
  1016. JingleSession.prototype.sendMute = function (muted, content) {
  1017. var info = $iq({to: this.peerjid,
  1018. type: 'set'})
  1019. .c('jingle', {xmlns: 'urn:xmpp:jingle:1',
  1020. action: 'session-info',
  1021. initiator: this.initiator,
  1022. sid: this.sid });
  1023. info.c(muted ? 'mute' : 'unmute', {xmlns: 'urn:xmpp:jingle:apps:rtp:info:1'});
  1024. info.attrs({'creator': this.me == this.initiator ? 'creator' : 'responder'});
  1025. if (content) {
  1026. info.attrs({'name': content});
  1027. }
  1028. this.connection.send(info);
  1029. };
  1030. JingleSession.prototype.sendRinging = function () {
  1031. var info = $iq({to: this.peerjid,
  1032. type: 'set'})
  1033. .c('jingle', {xmlns: 'urn:xmpp:jingle:1',
  1034. action: 'session-info',
  1035. initiator: this.initiator,
  1036. sid: this.sid });
  1037. info.c('ringing', {xmlns: 'urn:xmpp:jingle:apps:rtp:info:1'});
  1038. this.connection.send(info);
  1039. };
  1040. JingleSession.prototype.getStats = function (interval) {
  1041. var self = this;
  1042. var recv = {audio: 0, video: 0};
  1043. var lost = {audio: 0, video: 0};
  1044. var lastrecv = {audio: 0, video: 0};
  1045. var lastlost = {audio: 0, video: 0};
  1046. var loss = {audio: 0, video: 0};
  1047. var delta = {audio: 0, video: 0};
  1048. this.statsinterval = window.setInterval(function () {
  1049. if (self && self.peerconnection && self.peerconnection.getStats) {
  1050. self.peerconnection.getStats(function (stats) {
  1051. var results = stats.result();
  1052. // TODO: there are so much statistics you can get from this..
  1053. for (var i = 0; i < results.length; ++i) {
  1054. if (results[i].type == 'ssrc') {
  1055. var packetsrecv = results[i].stat('packetsReceived');
  1056. var packetslost = results[i].stat('packetsLost');
  1057. if (packetsrecv && packetslost) {
  1058. packetsrecv = parseInt(packetsrecv, 10);
  1059. packetslost = parseInt(packetslost, 10);
  1060. if (results[i].stat('googFrameRateReceived')) {
  1061. lastlost.video = lost.video;
  1062. lastrecv.video = recv.video;
  1063. recv.video = packetsrecv;
  1064. lost.video = packetslost;
  1065. } else {
  1066. lastlost.audio = lost.audio;
  1067. lastrecv.audio = recv.audio;
  1068. recv.audio = packetsrecv;
  1069. lost.audio = packetslost;
  1070. }
  1071. }
  1072. }
  1073. }
  1074. delta.audio = recv.audio - lastrecv.audio;
  1075. delta.video = recv.video - lastrecv.video;
  1076. loss.audio = (delta.audio > 0) ? Math.ceil(100 * (lost.audio - lastlost.audio) / delta.audio) : 0;
  1077. loss.video = (delta.video > 0) ? Math.ceil(100 * (lost.video - lastlost.video) / delta.video) : 0;
  1078. $(document).trigger('packetloss.jingle', [self.sid, loss]);
  1079. });
  1080. }
  1081. }, interval || 3000);
  1082. return this.statsinterval;
  1083. };
  1084. JingleSession.onJingleError = function (session, error)
  1085. {
  1086. console.error("Jingle error", error);
  1087. }
  1088. JingleSession.onJingleFatalError = function (session, error)
  1089. {
  1090. sessionTerminated = true;
  1091. connection.emuc.doLeave();
  1092. UI.messageHandler.showError( "Sorry",
  1093. "Internal application error[setRemoteDescription]");
  1094. }