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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412
  1. /* jshint -W117 */
  2. /* application specific logic */
  3. var connection = null;
  4. var authenticatedUser = false;
  5. var focus = null;
  6. var activecall = null;
  7. var RTC = null;
  8. var nickname = null;
  9. var sharedKey = '';
  10. var recordingToken ='';
  11. var roomUrl = null;
  12. var roomName = null;
  13. var ssrc2jid = {};
  14. var mediaStreams = [];
  15. /**
  16. * The stats collector that process stats data and triggers updates to app.js.
  17. * @type {StatsCollector}
  18. */
  19. var statsCollector = null;
  20. /**
  21. * The stats collector for the local stream.
  22. * @type {LocalStatsCollector}
  23. */
  24. var localStatsCollector = null;
  25. /**
  26. * Indicates whether ssrc is camera video or desktop stream.
  27. * FIXME: remove those maps
  28. */
  29. var ssrc2videoType = {};
  30. var videoSrcToSsrc = {};
  31. /**
  32. * Currently focused video "src"(displayed in large video).
  33. * @type {String}
  34. */
  35. var focusedVideoSrc = null;
  36. var mutedAudios = {};
  37. var localVideoSrc = null;
  38. var flipXLocalVideo = true;
  39. var isFullScreen = false;
  40. var toolbarTimeout = null;
  41. var currentVideoWidth = null;
  42. var currentVideoHeight = null;
  43. /**
  44. * Method used to calculate large video size.
  45. * @type {function ()}
  46. */
  47. var getVideoSize;
  48. /**
  49. * Method used to get large video position.
  50. * @type {function ()}
  51. */
  52. var getVideoPosition;
  53. /* window.onbeforeunload = closePageWarning; */
  54. var sessionTerminated = false;
  55. function init() {
  56. RTC = setupRTC();
  57. if (RTC === null) {
  58. window.location.href = 'webrtcrequired.html';
  59. return;
  60. } else if (RTC.browser !== 'chrome') {
  61. window.location.href = 'chromeonly.html';
  62. return;
  63. }
  64. obtainAudioAndVideoPermissions(function (stream) {
  65. var audioStream = new webkitMediaStream(stream);
  66. var videoStream = new webkitMediaStream(stream);
  67. var videoTracks = stream.getVideoTracks();
  68. var audioTracks = stream.getAudioTracks();
  69. for (var i = 0; i < videoTracks.length; i++) {
  70. audioStream.removeTrack(videoTracks[i]);
  71. }
  72. VideoLayout.changeLocalAudio(audioStream);
  73. startLocalRtpStatsCollector(audioStream);
  74. for (i = 0; i < audioTracks.length; i++) {
  75. videoStream.removeTrack(audioTracks[i]);
  76. }
  77. VideoLayout.changeLocalVideo(videoStream, true);
  78. maybeDoJoin();
  79. });
  80. var jid = document.getElementById('jid').value || config.hosts.anonymousdomain || config.hosts.domain || window.location.hostname;
  81. connect(jid);
  82. }
  83. function connect(jid, password) {
  84. var localAudio, localVideo;
  85. if (connection && connection.jingle) {
  86. localAudio = connection.jingle.localAudio;
  87. localVideo = connection.jingle.localVideo;
  88. }
  89. connection = new Strophe.Connection(document.getElementById('boshURL').value || config.bosh || '/http-bind');
  90. if (nickname) {
  91. connection.emuc.addDisplayNameToPresence(nickname);
  92. }
  93. if (connection.disco) {
  94. // for chrome, add multistream cap
  95. }
  96. connection.jingle.pc_constraints = RTC.pc_constraints;
  97. if (config.useIPv6) {
  98. // https://code.google.com/p/webrtc/issues/detail?id=2828
  99. if (!connection.jingle.pc_constraints.optional) connection.jingle.pc_constraints.optional = [];
  100. connection.jingle.pc_constraints.optional.push({googIPv6: true});
  101. }
  102. if (localAudio) connection.jingle.localAudio = localAudio;
  103. if (localVideo) connection.jingle.localVideo = localVideo;
  104. if(!password)
  105. password = document.getElementById('password').value;
  106. var anonymousConnectionFailed = false;
  107. connection.connect(jid, password, function (status, msg) {
  108. if (status === Strophe.Status.CONNECTED) {
  109. console.log('connected');
  110. if (config.useStunTurn) {
  111. connection.jingle.getStunAndTurnCredentials();
  112. }
  113. document.getElementById('connect').disabled = true;
  114. if(password)
  115. authenticatedUser = true;
  116. maybeDoJoin();
  117. } else if (status === Strophe.Status.CONNFAIL) {
  118. if(msg === 'x-strophe-bad-non-anon-jid') {
  119. anonymousConnectionFailed = true;
  120. }
  121. console.log('status', status);
  122. } else if (status === Strophe.Status.DISCONNECTED) {
  123. if(anonymousConnectionFailed) {
  124. // prompt user for username and password
  125. $(document).trigger('passwordrequired.main');
  126. }
  127. } else if (status === Strophe.Status.AUTHFAIL) {
  128. // wrong password or username, prompt user
  129. $(document).trigger('passwordrequired.main');
  130. } else {
  131. console.log('status', status);
  132. }
  133. });
  134. }
  135. /**
  136. * We ask for audio and video combined stream in order to get permissions and
  137. * not to ask twice.
  138. */
  139. function obtainAudioAndVideoPermissions(callback) {
  140. // Get AV
  141. getUserMediaWithConstraints(
  142. ['audio', 'video'],
  143. function (avStream) {
  144. callback(avStream);
  145. },
  146. function (error) {
  147. console.error('failed to obtain audio/video stream - stop', error);
  148. },
  149. config.resolution || '360');
  150. }
  151. function maybeDoJoin() {
  152. if (connection && connection.connected && Strophe.getResourceFromJid(connection.jid) // .connected is true while connecting?
  153. && (connection.jingle.localAudio || connection.jingle.localVideo)) {
  154. doJoin();
  155. }
  156. }
  157. function doJoin() {
  158. var roomnode = null;
  159. var path = window.location.pathname;
  160. var roomjid;
  161. // determinde the room node from the url
  162. // TODO: just the roomnode or the whole bare jid?
  163. if (config.getroomnode && typeof config.getroomnode === 'function') {
  164. // custom function might be responsible for doing the pushstate
  165. roomnode = config.getroomnode(path);
  166. } else {
  167. /* fall back to default strategy
  168. * this is making assumptions about how the URL->room mapping happens.
  169. * It currently assumes deployment at root, with a rewrite like the
  170. * following one (for nginx):
  171. location ~ ^/([a-zA-Z0-9]+)$ {
  172. rewrite ^/(.*)$ / break;
  173. }
  174. */
  175. if (path.length > 1) {
  176. roomnode = path.substr(1).toLowerCase();
  177. } else {
  178. var word = RoomNameGenerator.generateRoomWithoutSeparator(3);
  179. roomnode = word.toLowerCase();
  180. window.history.pushState('VideoChat',
  181. 'Room: ' + word, window.location.pathname + word);
  182. }
  183. }
  184. roomName = roomnode + '@' + config.hosts.muc;
  185. roomjid = roomName;
  186. if (config.useNicks) {
  187. var nick = window.prompt('Your nickname (optional)');
  188. if (nick) {
  189. roomjid += '/' + nick;
  190. } else {
  191. roomjid += '/' + Strophe.getNodeFromJid(connection.jid);
  192. }
  193. } else {
  194. var tmpJid = Strophe.getNodeFromJid(connection.jid);
  195. if(!authenticatedUser)
  196. tmpJid = tmpJid.substr(0, 8);
  197. roomjid += '/' + tmpJid;
  198. }
  199. connection.emuc.doJoin(roomjid);
  200. }
  201. function waitForRemoteVideo(selector, ssrc, stream) {
  202. if (selector.removed || !selector.parent().is(":visible")) {
  203. console.warn("Media removed before had started", selector);
  204. return;
  205. }
  206. if (stream.id === 'mixedmslabel') return;
  207. if (selector[0].currentTime > 0) {
  208. RTC.attachMediaStream(selector, stream); // FIXME: why do i have to do this for FF?
  209. // FIXME: add a class that will associate peer Jid, video.src, it's ssrc and video type
  210. // in order to get rid of too many maps
  211. if (ssrc && selector.attr('src')) {
  212. videoSrcToSsrc[selector.attr('src')] = ssrc;
  213. } else {
  214. console.warn("No ssrc given for video", selector);
  215. }
  216. $(document).trigger('videoactive.jingle', [selector]);
  217. } else {
  218. setTimeout(function () {
  219. waitForRemoteVideo(selector, ssrc, stream);
  220. }, 250);
  221. }
  222. }
  223. $(document).bind('remotestreamadded.jingle', function (event, data, sid) {
  224. var sess = connection.jingle.sessions[sid];
  225. var thessrc;
  226. // look up an associated JID for a stream id
  227. if (data.stream.id.indexOf('mixedmslabel') === -1) {
  228. var ssrclines
  229. = SDPUtil.find_lines(sess.peerconnection.remoteDescription.sdp, 'a=ssrc');
  230. ssrclines = ssrclines.filter(function (line) {
  231. return line.indexOf('mslabel:' + data.stream.label) !== -1;
  232. });
  233. if (ssrclines.length) {
  234. thessrc = ssrclines[0].substring(7).split(' ')[0];
  235. // ok to overwrite the one from focus? might save work in colibri.js
  236. console.log('associated jid', ssrc2jid[thessrc], data.peerjid);
  237. if (ssrc2jid[thessrc]) {
  238. data.peerjid = ssrc2jid[thessrc];
  239. }
  240. }
  241. }
  242. mediaStreams.push(new MediaStream(data, sid, thessrc));
  243. var container;
  244. var remotes = document.getElementById('remoteVideos');
  245. if (data.peerjid) {
  246. VideoLayout.ensurePeerContainerExists(data.peerjid);
  247. container = document.getElementById(
  248. 'participant_' + Strophe.getResourceFromJid(data.peerjid));
  249. } else {
  250. if (data.stream.id !== 'mixedmslabel') {
  251. console.error( 'can not associate stream',
  252. data.stream.id,
  253. 'with a participant');
  254. // We don't want to add it here since it will cause troubles
  255. return;
  256. }
  257. // FIXME: for the mixed ms we dont need a video -- currently
  258. container = document.createElement('span');
  259. container.id = 'mixedstream';
  260. container.className = 'videocontainer';
  261. remotes.appendChild(container);
  262. Util.playSoundNotification('userJoined');
  263. }
  264. var isVideo = data.stream.getVideoTracks().length > 0;
  265. if (container) {
  266. VideoLayout.addRemoteStreamElement( container,
  267. sid,
  268. data.stream,
  269. data.peerjid,
  270. thessrc);
  271. }
  272. // an attempt to work around https://github.com/jitsi/jitmeet/issues/32
  273. if (isVideo &&
  274. data.peerjid && sess.peerjid === data.peerjid &&
  275. data.stream.getVideoTracks().length === 0 &&
  276. connection.jingle.localVideo.getVideoTracks().length > 0) {
  277. //
  278. window.setTimeout(function () {
  279. sendKeyframe(sess.peerconnection);
  280. }, 3000);
  281. }
  282. });
  283. /**
  284. * Returns the JID of the user to whom given <tt>videoSrc</tt> belongs.
  285. * @param videoSrc the video "src" identifier.
  286. * @returns {null | String} the JID of the user to whom given <tt>videoSrc</tt>
  287. * belongs.
  288. */
  289. function getJidFromVideoSrc(videoSrc)
  290. {
  291. if (videoSrc === localVideoSrc)
  292. return connection.emuc.myroomjid;
  293. var ssrc = videoSrcToSsrc[videoSrc];
  294. if (!ssrc)
  295. {
  296. return null;
  297. }
  298. return ssrc2jid[ssrc];
  299. }
  300. // an attempt to work around https://github.com/jitsi/jitmeet/issues/32
  301. function sendKeyframe(pc) {
  302. console.log('sendkeyframe', pc.iceConnectionState);
  303. if (pc.iceConnectionState !== 'connected') return; // safe...
  304. pc.setRemoteDescription(
  305. pc.remoteDescription,
  306. function () {
  307. pc.createAnswer(
  308. function (modifiedAnswer) {
  309. pc.setLocalDescription(
  310. modifiedAnswer,
  311. function () {
  312. // noop
  313. },
  314. function (error) {
  315. console.log('triggerKeyframe setLocalDescription failed', error);
  316. }
  317. );
  318. },
  319. function (error) {
  320. console.log('triggerKeyframe createAnswer failed', error);
  321. }
  322. );
  323. },
  324. function (error) {
  325. console.log('triggerKeyframe setRemoteDescription failed', error);
  326. }
  327. );
  328. }
  329. // Really mute video, i.e. dont even send black frames
  330. function muteVideo(pc, unmute) {
  331. // FIXME: this probably needs another of those lovely state safeguards...
  332. // which checks for iceconn == connected and sigstate == stable
  333. pc.setRemoteDescription(pc.remoteDescription,
  334. function () {
  335. pc.createAnswer(
  336. function (answer) {
  337. var sdp = new SDP(answer.sdp);
  338. if (sdp.media.length > 1) {
  339. if (unmute)
  340. sdp.media[1] = sdp.media[1].replace('a=recvonly', 'a=sendrecv');
  341. else
  342. sdp.media[1] = sdp.media[1].replace('a=sendrecv', 'a=recvonly');
  343. sdp.raw = sdp.session + sdp.media.join('');
  344. answer.sdp = sdp.raw;
  345. }
  346. pc.setLocalDescription(answer,
  347. function () {
  348. console.log('mute SLD ok');
  349. },
  350. function (error) {
  351. console.log('mute SLD error');
  352. }
  353. );
  354. },
  355. function (error) {
  356. console.log(error);
  357. }
  358. );
  359. },
  360. function (error) {
  361. console.log('muteVideo SRD error');
  362. }
  363. );
  364. }
  365. /**
  366. * Callback for audio levels changed.
  367. * @param jid JID of the user
  368. * @param audioLevel the audio level value
  369. */
  370. function audioLevelUpdated(jid, audioLevel)
  371. {
  372. var resourceJid;
  373. if(jid === LocalStatsCollector.LOCAL_JID)
  374. {
  375. resourceJid = AudioLevels.LOCAL_LEVEL;
  376. if(isAudioMuted())
  377. return;
  378. }
  379. else
  380. {
  381. resourceJid = Strophe.getResourceFromJid(jid);
  382. }
  383. AudioLevels.updateAudioLevel(resourceJid, audioLevel);
  384. }
  385. /**
  386. * Starts the {@link StatsCollector} if the feature is enabled in config.js.
  387. */
  388. function startRtpStatsCollector()
  389. {
  390. stopRTPStatsCollector();
  391. if (config.enableRtpStats)
  392. {
  393. statsCollector = new StatsCollector(
  394. getConferenceHandler().peerconnection, 200, audioLevelUpdated);
  395. statsCollector.start();
  396. }
  397. }
  398. /**
  399. * Stops the {@link StatsCollector}.
  400. */
  401. function stopRTPStatsCollector()
  402. {
  403. if (statsCollector)
  404. {
  405. statsCollector.stop();
  406. statsCollector = null;
  407. }
  408. }
  409. /**
  410. * Starts the {@link LocalStatsCollector} if the feature is enabled in config.js
  411. * @param stream the stream that will be used for collecting statistics.
  412. */
  413. function startLocalRtpStatsCollector(stream)
  414. {
  415. if(config.enableRtpStats)
  416. {
  417. localStatsCollector = new LocalStatsCollector(stream, 100, audioLevelUpdated);
  418. localStatsCollector.start();
  419. }
  420. }
  421. /**
  422. * Stops the {@link LocalStatsCollector}.
  423. */
  424. function stopLocalRtpStatsCollector()
  425. {
  426. if(localStatsCollector)
  427. {
  428. localStatsCollector.stop();
  429. localStatsCollector = null;
  430. }
  431. }
  432. $(document).bind('callincoming.jingle', function (event, sid) {
  433. var sess = connection.jingle.sessions[sid];
  434. // TODO: do we check activecall == null?
  435. activecall = sess;
  436. startRtpStatsCollector();
  437. // Bind data channel listener in case we're a regular participant
  438. if (config.openSctp)
  439. {
  440. bindDataChannelListener(sess.peerconnection);
  441. }
  442. // TODO: check affiliation and/or role
  443. console.log('emuc data for', sess.peerjid, connection.emuc.members[sess.peerjid]);
  444. sess.usedrip = true; // not-so-naive trickle ice
  445. sess.sendAnswer();
  446. sess.accept();
  447. });
  448. $(document).bind('conferenceCreated.jingle', function (event, focus)
  449. {
  450. startRtpStatsCollector();
  451. });
  452. $(document).bind('conferenceCreated.jingle', function (event, focus)
  453. {
  454. // Bind data channel listener in case we're the focus
  455. if (config.openSctp)
  456. {
  457. bindDataChannelListener(focus.peerconnection);
  458. }
  459. });
  460. $(document).bind('callterminated.jingle', function (event, sid, jid, reason) {
  461. // Leave the room if my call has been remotely terminated.
  462. if (connection.emuc.joined && focus == null && reason === 'kick') {
  463. sessionTerminated = true;
  464. connection.emuc.doLeave();
  465. openMessageDialog( "Session Terminated",
  466. "Ouch! You have been kicked out of the meet!");
  467. }
  468. });
  469. $(document).bind('setLocalDescription.jingle', function (event, sid) {
  470. // put our ssrcs into presence so other clients can identify our stream
  471. var sess = connection.jingle.sessions[sid];
  472. var newssrcs = {};
  473. var directions = {};
  474. var localSDP = new SDP(sess.peerconnection.localDescription.sdp);
  475. localSDP.media.forEach(function (media) {
  476. var type = SDPUtil.parse_mid(SDPUtil.find_line(media, 'a=mid:'));
  477. if (SDPUtil.find_line(media, 'a=ssrc:')) {
  478. // assumes a single local ssrc
  479. var ssrc = SDPUtil.find_line(media, 'a=ssrc:').substring(7).split(' ')[0];
  480. newssrcs[type] = ssrc;
  481. directions[type] = (
  482. SDPUtil.find_line(media, 'a=sendrecv') ||
  483. SDPUtil.find_line(media, 'a=recvonly') ||
  484. SDPUtil.find_line(media, 'a=sendonly') ||
  485. SDPUtil.find_line(media, 'a=inactive') ||
  486. 'a=sendrecv').substr(2);
  487. }
  488. });
  489. console.log('new ssrcs', newssrcs);
  490. // Have to clear presence map to get rid of removed streams
  491. connection.emuc.clearPresenceMedia();
  492. var i = 0;
  493. Object.keys(newssrcs).forEach(function (mtype) {
  494. i++;
  495. var type = mtype;
  496. // Change video type to screen
  497. if (mtype === 'video' && isUsingScreenStream) {
  498. type = 'screen';
  499. }
  500. connection.emuc.addMediaToPresence(i, type, newssrcs[mtype], directions[mtype]);
  501. });
  502. if (i > 0) {
  503. connection.emuc.sendPresence();
  504. }
  505. });
  506. $(document).bind('joined.muc', function (event, jid, info) {
  507. updateRoomUrl(window.location.href);
  508. document.getElementById('localNick').appendChild(
  509. document.createTextNode(Strophe.getResourceFromJid(jid) + ' (me)')
  510. );
  511. if (Object.keys(connection.emuc.members).length < 1) {
  512. focus = new ColibriFocus(connection, config.hosts.bridge);
  513. if (nickname !== null) {
  514. focus.setEndpointDisplayName(connection.emuc.myroomjid,
  515. nickname);
  516. }
  517. Toolbar.showSipCallButton(true);
  518. Toolbar.showRecordingButton(false);
  519. }
  520. if (!focus)
  521. {
  522. Toolbar.showSipCallButton(false);
  523. }
  524. if (focus && config.etherpad_base) {
  525. Etherpad.init();
  526. }
  527. VideoLayout.showFocusIndicator();
  528. // Add myself to the contact list.
  529. ContactList.addContact(jid);
  530. // Once we've joined the muc show the toolbar
  531. Toolbar.showToolbar();
  532. if (info.displayName)
  533. $(document).trigger('displaynamechanged',
  534. ['localVideoContainer', info.displayName + ' (me)']);
  535. });
  536. $(document).bind('entered.muc', function (event, jid, info, pres) {
  537. console.log('entered', jid, info);
  538. console.log('is focus?' + focus ? 'true' : 'false');
  539. // Add Peer's container
  540. VideoLayout.ensurePeerContainerExists(jid);
  541. if (focus !== null) {
  542. // FIXME: this should prepare the video
  543. if (focus.confid === null) {
  544. console.log('make new conference with', jid);
  545. focus.makeConference(Object.keys(connection.emuc.members));
  546. Toolbar.showRecordingButton(true);
  547. } else {
  548. console.log('invite', jid, 'into conference');
  549. focus.addNewParticipant(jid);
  550. }
  551. }
  552. else if (sharedKey) {
  553. Toolbar.updateLockButton();
  554. }
  555. });
  556. $(document).bind('left.muc', function (event, jid) {
  557. console.log('left.muc', jid);
  558. // Need to call this with a slight delay, otherwise the element couldn't be
  559. // found for some reason.
  560. window.setTimeout(function () {
  561. var container = document.getElementById(
  562. 'participant_' + Strophe.getResourceFromJid(jid));
  563. if (container) {
  564. // hide here, wait for video to close before removing
  565. $(container).hide();
  566. VideoLayout.resizeThumbnails();
  567. }
  568. }, 10);
  569. // Unlock large video
  570. if (focusedVideoSrc)
  571. {
  572. if (getJidFromVideoSrc(focusedVideoSrc) === jid)
  573. {
  574. console.info("Focused video owner has left the conference");
  575. focusedVideoSrc = null;
  576. }
  577. }
  578. connection.jingle.terminateByJid(jid);
  579. if (focus == null
  580. // I shouldn't be the one that left to enter here.
  581. && jid !== connection.emuc.myroomjid
  582. && connection.emuc.myroomjid === connection.emuc.list_members[0]
  583. // If our session has been terminated for some reason
  584. // (kicked, hangup), don't try to become the focus
  585. && !sessionTerminated) {
  586. console.log('welcome to our new focus... myself');
  587. focus = new ColibriFocus(connection, config.hosts.bridge);
  588. if (nickname !== null) {
  589. focus.setEndpointDisplayName(connection.emuc.myroomjid,
  590. nickname);
  591. }
  592. Toolbar.showSipCallButton(true);
  593. if (Object.keys(connection.emuc.members).length > 0) {
  594. focus.makeConference(Object.keys(connection.emuc.members));
  595. Toolbar.showRecordingButton(true);
  596. }
  597. $(document).trigger('focusechanged.muc', [focus]);
  598. }
  599. else if (focus && Object.keys(connection.emuc.members).length === 0) {
  600. console.log('everyone left');
  601. // FIXME: closing the connection is a hack to avoid some
  602. // problems with reinit
  603. disposeConference();
  604. focus = new ColibriFocus(connection, config.hosts.bridge);
  605. if (nickname !== null) {
  606. focus.setEndpointDisplayName(connection.emuc.myroomjid,
  607. nickname);
  608. }
  609. Toolbar.showSipCallButton(true);
  610. Toolbar.showRecordingButton(false);
  611. }
  612. if (connection.emuc.getPrezi(jid)) {
  613. $(document).trigger('presentationremoved.muc',
  614. [jid, connection.emuc.getPrezi(jid)]);
  615. }
  616. });
  617. $(document).bind('presence.muc', function (event, jid, info, pres) {
  618. // Remove old ssrcs coming from the jid
  619. Object.keys(ssrc2jid).forEach(function (ssrc) {
  620. if (ssrc2jid[ssrc] == jid) {
  621. delete ssrc2jid[ssrc];
  622. }
  623. if (ssrc2videoType[ssrc] == jid) {
  624. delete ssrc2videoType[ssrc];
  625. }
  626. });
  627. $(pres).find('>media[xmlns="http://estos.de/ns/mjs"]>source').each(function (idx, ssrc) {
  628. //console.log(jid, 'assoc ssrc', ssrc.getAttribute('type'), ssrc.getAttribute('ssrc'));
  629. var ssrcV = ssrc.getAttribute('ssrc');
  630. ssrc2jid[ssrcV] = jid;
  631. var type = ssrc.getAttribute('type');
  632. ssrc2videoType[ssrcV] = type;
  633. // might need to update the direction if participant just went from sendrecv to recvonly
  634. if (type === 'video' || type === 'screen') {
  635. var el = $('#participant_' + Strophe.getResourceFromJid(jid) + '>video');
  636. switch (ssrc.getAttribute('direction')) {
  637. case 'sendrecv':
  638. el.show();
  639. break;
  640. case 'recvonly':
  641. el.hide();
  642. // FIXME: Check if we have to change large video
  643. //VideoLayout.updateLargeVideo(el);
  644. break;
  645. }
  646. }
  647. });
  648. if (info.displayName && info.displayName.length > 0)
  649. $(document).trigger('displaynamechanged',
  650. [jid, info.displayName]);
  651. if (focus !== null && info.displayName !== null) {
  652. focus.setEndpointDisplayName(jid, info.displayName);
  653. }
  654. });
  655. $(document).bind('presence.status.muc', function (event, jid, info, pres) {
  656. VideoLayout.setPresenceStatus(
  657. 'participant_' + Strophe.getResourceFromJid(jid), info.status);
  658. });
  659. $(document).bind('passwordrequired.muc', function (event, jid) {
  660. console.log('on password required', jid);
  661. $.prompt('<h2>Password required</h2>' +
  662. '<input id="lockKey" type="text" placeholder="shared key" autofocus>', {
  663. persistent: true,
  664. buttons: { "Ok": true, "Cancel": false},
  665. defaultButton: 1,
  666. loaded: function (event) {
  667. document.getElementById('lockKey').focus();
  668. },
  669. submit: function (e, v, m, f) {
  670. if (v) {
  671. var lockKey = document.getElementById('lockKey');
  672. if (lockKey.value !== null) {
  673. setSharedKey(lockKey.value);
  674. connection.emuc.doJoin(jid, lockKey.value);
  675. }
  676. }
  677. }
  678. });
  679. });
  680. $(document).bind('passwordrequired.main', function (event) {
  681. console.log('password is required');
  682. $.prompt('<h2>Password required</h2>' +
  683. '<input id="passwordrequired.username" type="text" placeholder="user@domain.net" autofocus>' +
  684. '<input id="passwordrequired.password" type="password" placeholder="user password">', {
  685. persistent: true,
  686. buttons: { "Ok": true, "Cancel": false},
  687. defaultButton: 1,
  688. loaded: function (event) {
  689. document.getElementById('passwordrequired.username').focus();
  690. },
  691. submit: function (e, v, m, f) {
  692. if (v) {
  693. var username = document.getElementById('passwordrequired.username');
  694. var password = document.getElementById('passwordrequired.password');
  695. if (username.value !== null && password.value != null) {
  696. connect(username.value, password.value);
  697. }
  698. }
  699. }
  700. });
  701. });
  702. /**
  703. * Checks if video identified by given src is desktop stream.
  704. * @param videoSrc eg.
  705. * blob:https%3A//pawel.jitsi.net/9a46e0bd-131e-4d18-9c14-a9264e8db395
  706. * @returns {boolean}
  707. */
  708. function isVideoSrcDesktop(videoSrc) {
  709. // FIXME: fix this mapping mess...
  710. // figure out if large video is desktop stream or just a camera
  711. var isDesktop = false;
  712. if (localVideoSrc === videoSrc) {
  713. // local video
  714. isDesktop = isUsingScreenStream;
  715. } else {
  716. // Do we have associations...
  717. var videoSsrc = videoSrcToSsrc[videoSrc];
  718. if (videoSsrc) {
  719. var videoType = ssrc2videoType[videoSsrc];
  720. if (videoType) {
  721. // Finally there...
  722. isDesktop = videoType === 'screen';
  723. } else {
  724. console.error("No video type for ssrc: " + videoSsrc);
  725. }
  726. } else {
  727. console.error("No ssrc for src: " + videoSrc);
  728. }
  729. }
  730. return isDesktop;
  731. }
  732. function getConferenceHandler() {
  733. return focus ? focus : activecall;
  734. }
  735. function toggleVideo() {
  736. if (!(connection && connection.jingle.localVideo))
  737. return;
  738. var sess = getConferenceHandler();
  739. if (sess) {
  740. sess.toggleVideoMute(
  741. function (isMuted) {
  742. if (isMuted) {
  743. $('#video').removeClass("icon-camera");
  744. $('#video').addClass("icon-camera icon-camera-disabled");
  745. } else {
  746. $('#video').removeClass("icon-camera icon-camera-disabled");
  747. $('#video').addClass("icon-camera");
  748. }
  749. }
  750. );
  751. }
  752. sess = focus || activecall;
  753. if (!sess) {
  754. return;
  755. }
  756. sess.pendingop = ismuted ? 'unmute' : 'mute';
  757. // connection.emuc.addVideoInfoToPresence(!ismuted);
  758. // connection.emuc.sendPresence();
  759. sess.modifySources();
  760. }
  761. /**
  762. * Mutes / unmutes audio for the local participant.
  763. */
  764. function toggleAudio() {
  765. if (!(connection && connection.jingle.localAudio)) {
  766. preMuted = true;
  767. // We still click the button.
  768. buttonClick("#mute", "icon-microphone icon-mic-disabled");
  769. return;
  770. }
  771. var localAudio = connection.jingle.localAudio;
  772. for (var idx = 0; idx < localAudio.getAudioTracks().length; idx++) {
  773. var audioEnabled = localAudio.getAudioTracks()[idx].enabled;
  774. localAudio.getAudioTracks()[idx].enabled = !audioEnabled;
  775. // isMuted is the opposite of audioEnabled
  776. connection.emuc.addAudioInfoToPresence(audioEnabled);
  777. connection.emuc.sendPresence();
  778. }
  779. buttonClick("#mute", "icon-microphone icon-mic-disabled");
  780. }
  781. /**
  782. * Checks whether the audio is muted or not.
  783. * @returns {boolean} true if audio is muted and false if not.
  784. */
  785. function isAudioMuted()
  786. {
  787. var localAudio = connection.jingle.localAudio;
  788. for (var idx = 0; idx < localAudio.getAudioTracks().length; idx++) {
  789. if(localAudio.getAudioTracks()[idx].enabled === true)
  790. return false;
  791. }
  792. return true;
  793. }
  794. // Starts or stops the recording for the conference.
  795. function toggleRecording() {
  796. if (focus === null || focus.confid === null) {
  797. console.log('non-focus, or conference not yet organized: not enabling recording');
  798. return;
  799. }
  800. if (!recordingToken)
  801. {
  802. $.prompt('<h2>Enter recording token</h2>' +
  803. '<input id="recordingToken" type="text" placeholder="token" autofocus>',
  804. {
  805. persistent: false,
  806. buttons: { "Save": true, "Cancel": false},
  807. defaultButton: 1,
  808. loaded: function (event) {
  809. document.getElementById('recordingToken').focus();
  810. },
  811. submit: function (e, v, m, f) {
  812. if (v) {
  813. var token = document.getElementById('recordingToken');
  814. if (token.value) {
  815. setRecordingToken(Util.escapeHtml(token.value));
  816. toggleRecording();
  817. }
  818. }
  819. }
  820. }
  821. );
  822. return;
  823. }
  824. var oldState = focus.recordingEnabled;
  825. Toolbar.toggleRecordingButtonState();
  826. focus.setRecording(!oldState,
  827. recordingToken,
  828. function (state) {
  829. console.log("New recording state: ", state);
  830. if (state == oldState) //failed to change, reset the token because it might have been wrong
  831. {
  832. Toolbar.toggleRecordingButtonState();
  833. setRecordingToken(null);
  834. }
  835. }
  836. );
  837. }
  838. /**
  839. * Returns an array of the video horizontal and vertical indents,
  840. * so that if fits its parent.
  841. *
  842. * @return an array with 2 elements, the horizontal indent and the vertical
  843. * indent
  844. */
  845. function getCameraVideoPosition(videoWidth,
  846. videoHeight,
  847. videoSpaceWidth,
  848. videoSpaceHeight) {
  849. // Parent height isn't completely calculated when we position the video in
  850. // full screen mode and this is why we use the screen height in this case.
  851. // Need to think it further at some point and implement it properly.
  852. var isFullScreen = document.fullScreen ||
  853. document.mozFullScreen ||
  854. document.webkitIsFullScreen;
  855. if (isFullScreen)
  856. videoSpaceHeight = window.innerHeight;
  857. var horizontalIndent = (videoSpaceWidth - videoWidth) / 2;
  858. var verticalIndent = (videoSpaceHeight - videoHeight) / 2;
  859. return [horizontalIndent, verticalIndent];
  860. }
  861. /**
  862. * Returns an array of the video horizontal and vertical indents.
  863. * Centers horizontally and top aligns vertically.
  864. *
  865. * @return an array with 2 elements, the horizontal indent and the vertical
  866. * indent
  867. */
  868. function getDesktopVideoPosition(videoWidth,
  869. videoHeight,
  870. videoSpaceWidth,
  871. videoSpaceHeight) {
  872. var horizontalIndent = (videoSpaceWidth - videoWidth) / 2;
  873. var verticalIndent = 0;// Top aligned
  874. return [horizontalIndent, verticalIndent];
  875. }
  876. /**
  877. * Returns an array of the video dimensions, so that it covers the screen.
  878. * It leaves no empty areas, but some parts of the video might not be visible.
  879. *
  880. * @return an array with 2 elements, the video width and the video height
  881. */
  882. function getCameraVideoSize(videoWidth,
  883. videoHeight,
  884. videoSpaceWidth,
  885. videoSpaceHeight) {
  886. if (!videoWidth)
  887. videoWidth = currentVideoWidth;
  888. if (!videoHeight)
  889. videoHeight = currentVideoHeight;
  890. var aspectRatio = videoWidth / videoHeight;
  891. var availableWidth = Math.max(videoWidth, videoSpaceWidth);
  892. var availableHeight = Math.max(videoHeight, videoSpaceHeight);
  893. if (availableWidth / aspectRatio < videoSpaceHeight) {
  894. availableHeight = videoSpaceHeight;
  895. availableWidth = availableHeight * aspectRatio;
  896. }
  897. if (availableHeight * aspectRatio < videoSpaceWidth) {
  898. availableWidth = videoSpaceWidth;
  899. availableHeight = availableWidth / aspectRatio;
  900. }
  901. return [availableWidth, availableHeight];
  902. }
  903. $(document).ready(function () {
  904. document.title = brand.appName;
  905. if(config.enableWelcomePage && window.location.pathname == "/" &&
  906. (!window.localStorage.welcomePageDisabled || window.localStorage.welcomePageDisabled == "false"))
  907. {
  908. $("#videoconference_page").hide();
  909. $("#domain_name").text(window.location.protocol + "//" + window.location.host + "/");
  910. $("span[name='appName']").text(brand.appName);
  911. function enter_room()
  912. {
  913. var val = $("#enter_room_field").val();
  914. if(!val)
  915. val = $("#enter_room_field").attr("room_name");
  916. window.location.pathname = "/" + val;
  917. }
  918. $("#enter_room_button").click(function()
  919. {
  920. enter_room();
  921. });
  922. $("#enter_room_field").keydown(function (event) {
  923. if (event.keyCode === 13) {
  924. enter_room();
  925. }
  926. });
  927. var updateTimeout;
  928. var animateTimeout;
  929. $("#reload_roomname").click(function () {
  930. clearTimeout(updateTimeout);
  931. clearTimeout(animateTimeout);
  932. update_roomname();
  933. });
  934. function animate(word) {
  935. var currentVal = $("#enter_room_field").attr("placeholder");
  936. $("#enter_room_field").attr("placeholder", currentVal + word.substr(0, 1));
  937. animateTimeout = setTimeout(function() {
  938. animate(word.substring(1, word.length))
  939. }, 70);
  940. }
  941. function update_roomname()
  942. {
  943. var word = RoomNameGenerator.generateRoomWithoutSeparator();
  944. $("#enter_room_field").attr("room_name", word);
  945. $("#enter_room_field").attr("placeholder", "");
  946. animate(word);
  947. updateTimeout = setTimeout(update_roomname, 10000);
  948. }
  949. update_roomname();
  950. $("#disable_welcome").click(function () {
  951. window.localStorage.welcomePageDisabled = $("#disable_welcome").is(":checked");
  952. });
  953. return;
  954. }
  955. $("#welcome_page").hide();
  956. Chat.init();
  957. $('body').popover({ selector: '[data-toggle=popover]',
  958. trigger: 'click hover'});
  959. // Set the defaults for prompt dialogs.
  960. jQuery.prompt.setDefaults({persistent: false});
  961. // Set default desktop sharing method
  962. setDesktopSharing(config.desktopSharing);
  963. // Initialize Chrome extension inline installs
  964. if (config.chromeExtensionId) {
  965. initInlineInstalls();
  966. }
  967. // By default we use camera
  968. getVideoSize = getCameraVideoSize;
  969. getVideoPosition = getCameraVideoPosition;
  970. VideoLayout.resizeLargeVideoContainer();
  971. $(window).resize(function () {
  972. VideoLayout.resizeLargeVideoContainer();
  973. VideoLayout.positionLarge();
  974. });
  975. // Listen for large video size updates
  976. document.getElementById('largeVideo')
  977. .addEventListener('loadedmetadata', function (e) {
  978. currentVideoWidth = this.videoWidth;
  979. currentVideoHeight = this.videoHeight;
  980. VideoLayout.positionLarge(currentVideoWidth, currentVideoHeight);
  981. });
  982. if (!$('#settings').is(':visible')) {
  983. console.log('init');
  984. init();
  985. } else {
  986. loginInfo.onsubmit = function (e) {
  987. if (e.preventDefault) e.preventDefault();
  988. $('#settings').hide();
  989. init();
  990. };
  991. }
  992. });
  993. $(window).bind('beforeunload', function () {
  994. if (connection && connection.connected) {
  995. // ensure signout
  996. $.ajax({
  997. type: 'POST',
  998. url: config.bosh,
  999. async: false,
  1000. cache: false,
  1001. contentType: 'application/xml',
  1002. data: "<body rid='" + (connection.rid || connection._proto.rid) + "' xmlns='http://jabber.org/protocol/httpbind' sid='" + (connection.sid || connection._proto.sid) + "' type='terminate'><presence xmlns='jabber:client' type='unavailable'/></body>",
  1003. success: function (data) {
  1004. console.log('signed out');
  1005. console.log(data);
  1006. },
  1007. error: function (XMLHttpRequest, textStatus, errorThrown) {
  1008. console.log('signout error', textStatus + ' (' + errorThrown + ')');
  1009. }
  1010. });
  1011. }
  1012. disposeConference(true);
  1013. });
  1014. function disposeConference(onUnload) {
  1015. var handler = getConferenceHandler();
  1016. if (handler && handler.peerconnection) {
  1017. // FIXME: probably removing streams is not required and close() should be enough
  1018. if (connection.jingle.localAudio) {
  1019. handler.peerconnection.removeStream(connection.jingle.localAudio);
  1020. }
  1021. if (connection.jingle.localVideo) {
  1022. handler.peerconnection.removeStream(connection.jingle.localVideo);
  1023. }
  1024. handler.peerconnection.close();
  1025. }
  1026. stopRTPStatsCollector();
  1027. if(onUnload) {
  1028. stopLocalRtpStatsCollector();
  1029. }
  1030. focus = null;
  1031. activecall = null;
  1032. }
  1033. function dump(elem, filename) {
  1034. elem = elem.parentNode;
  1035. elem.download = filename || 'meetlog.json';
  1036. elem.href = 'data:application/json;charset=utf-8,\n';
  1037. var data = {};
  1038. if (connection.jingle) {
  1039. Object.keys(connection.jingle.sessions).forEach(function (sid) {
  1040. var session = connection.jingle.sessions[sid];
  1041. if (session.peerconnection && session.peerconnection.updateLog) {
  1042. // FIXME: should probably be a .dump call
  1043. data["jingle_" + session.sid] = {
  1044. updateLog: session.peerconnection.updateLog,
  1045. stats: session.peerconnection.stats,
  1046. url: window.location.href
  1047. };
  1048. }
  1049. });
  1050. }
  1051. metadata = {};
  1052. metadata.time = new Date();
  1053. metadata.url = window.location.href;
  1054. metadata.ua = navigator.userAgent;
  1055. if (connection.logger) {
  1056. metadata.xmpp = connection.logger.log;
  1057. }
  1058. data.metadata = metadata;
  1059. elem.href += encodeURIComponent(JSON.stringify(data, null, ' '));
  1060. return false;
  1061. }
  1062. /**
  1063. * Changes the style class of the element given by id.
  1064. */
  1065. function buttonClick(id, classname) {
  1066. $(id).toggleClass(classname); // add the class to the clicked element
  1067. }
  1068. /**
  1069. * Shows a message to the user.
  1070. *
  1071. * @param titleString the title of the message
  1072. * @param messageString the text of the message
  1073. */
  1074. function openMessageDialog(titleString, messageString) {
  1075. $.prompt(messageString,
  1076. {
  1077. title: titleString,
  1078. persistent: false
  1079. }
  1080. );
  1081. }
  1082. /**
  1083. * Locks / unlocks the room.
  1084. */
  1085. function lockRoom(lock) {
  1086. if (lock)
  1087. connection.emuc.lockRoom(sharedKey);
  1088. else
  1089. connection.emuc.lockRoom('');
  1090. Toolbar.updateLockButton();
  1091. }
  1092. /**
  1093. * Sets the shared key.
  1094. */
  1095. function setSharedKey(sKey) {
  1096. sharedKey = sKey;
  1097. }
  1098. function setRecordingToken(token) {
  1099. recordingToken = token;
  1100. }
  1101. /**
  1102. * Updates the room invite url.
  1103. */
  1104. function updateRoomUrl(newRoomUrl) {
  1105. roomUrl = newRoomUrl;
  1106. // If the invite dialog has been already opened we update the information.
  1107. var inviteLink = document.getElementById('inviteLinkRef');
  1108. if (inviteLink) {
  1109. inviteLink.value = roomUrl;
  1110. inviteLink.select();
  1111. document.getElementById('jqi_state0_buttonInvite').disabled = false;
  1112. }
  1113. }
  1114. /**
  1115. * Warning to the user that the conference window is about to be closed.
  1116. */
  1117. function closePageWarning() {
  1118. if (focus !== null)
  1119. return "You are the owner of this conference call and"
  1120. + " you are about to end it.";
  1121. else
  1122. return "You are about to leave this conversation.";
  1123. }
  1124. /**
  1125. * Resizes and repositions videos in full screen mode.
  1126. */
  1127. $(document).on('webkitfullscreenchange mozfullscreenchange fullscreenchange',
  1128. function () {
  1129. VideoLayout.resizeLargeVideoContainer();
  1130. VideoLayout.positionLarge();
  1131. isFullScreen = document.fullScreen ||
  1132. document.mozFullScreen ||
  1133. document.webkitIsFullScreen;
  1134. if (isFullScreen) {
  1135. setView("fullscreen");
  1136. }
  1137. else {
  1138. setView("default");
  1139. }
  1140. }
  1141. );
  1142. /**
  1143. * Sets the current view.
  1144. */
  1145. function setView(viewName) {
  1146. // if (viewName == "fullscreen") {
  1147. // document.getElementById('videolayout_fullscreen').disabled = false;
  1148. // document.getElementById('videolayout_default').disabled = true;
  1149. // }
  1150. // else {
  1151. // document.getElementById('videolayout_default').disabled = false;
  1152. // document.getElementById('videolayout_fullscreen').disabled = true;
  1153. // }
  1154. }
  1155. function hangUp() {
  1156. if (connection && connection.connected) {
  1157. // ensure signout
  1158. $.ajax({
  1159. type: 'POST',
  1160. url: config.bosh,
  1161. async: false,
  1162. cache: false,
  1163. contentType: 'application/xml',
  1164. data: "<body rid='" + (connection.rid || connection._proto.rid) + "' xmlns='http://jabber.org/protocol/httpbind' sid='" + (connection.sid || connection._proto.sid) + "' type='terminate'><presence xmlns='jabber:client' type='unavailable'/></body>",
  1165. success: function (data) {
  1166. console.log('signed out');
  1167. console.log(data);
  1168. },
  1169. error: function (XMLHttpRequest, textStatus, errorThrown) {
  1170. console.log('signout error', textStatus + ' (' + errorThrown + ')');
  1171. }
  1172. });
  1173. }
  1174. disposeConference(true);
  1175. }
  1176. $(document).bind('fatalError.jingle',
  1177. function (event, session, error)
  1178. {
  1179. sessionTerminated = true;
  1180. connection.emuc.doLeave();
  1181. openMessageDialog( "Sorry",
  1182. "Your browser version is too old. Please update and try again...");
  1183. }
  1184. );
  1185. function callSipButtonClicked()
  1186. {
  1187. $.prompt('<h2>Enter SIP number</h2>' +
  1188. '<input id="sipNumber" type="text" value="" autofocus>',
  1189. {
  1190. persistent: false,
  1191. buttons: { "Dial": true, "Cancel": false},
  1192. defaultButton: 2,
  1193. loaded: function (event)
  1194. {
  1195. document.getElementById('sipNumber').focus();
  1196. },
  1197. submit: function (e, v, m, f)
  1198. {
  1199. if (v)
  1200. {
  1201. var numberInput = document.getElementById('sipNumber');
  1202. if (numberInput.value && numberInput.value.length)
  1203. {
  1204. connection.rayo.dial(
  1205. numberInput.value, 'fromnumber', roomName);
  1206. }
  1207. }
  1208. }
  1209. }
  1210. );
  1211. }
  1212. function hangup() {
  1213. disposeConference();
  1214. sessionTerminated = true;
  1215. connection.emuc.doLeave();
  1216. var buttons = {};
  1217. if(config.enableWelcomePage)
  1218. {
  1219. setTimeout(function()
  1220. {
  1221. window.localStorage.welcomePageDisabled = false;
  1222. window.location.pathname = "/";
  1223. }, 10000);
  1224. }
  1225. $.prompt("Session Terminated",
  1226. {
  1227. title: "You hung up the call",
  1228. persistent: true,
  1229. buttons: {
  1230. "Join again": true
  1231. },
  1232. closeText: '',
  1233. submit: function(event, value, message, formVals)
  1234. {
  1235. window.location.reload();
  1236. return false;
  1237. }
  1238. }
  1239. );
  1240. }