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.

app.js 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. /* jshint -W117 */
  2. /* application specific logic */
  3. var connection = null;
  4. var focus = null;
  5. var RTC;
  6. var RTCPeerConnection = null;
  7. var nickname = null;
  8. var sharedKey = '';
  9. var roomUrl = null;
  10. var ssrc2jid = {};
  11. window.onbeforeunload = closePageWarning;
  12. function init() {
  13. RTC = setupRTC();
  14. if (RTC === null) {
  15. window.location.href = 'webrtcrequired.html';
  16. return;
  17. } else if (RTC.browser != 'chrome') {
  18. window.location.href = 'chromeonly.html';
  19. return;
  20. }
  21. RTCPeerconnection = TraceablePeerConnection;
  22. connection = new Strophe.Connection(document.getElementById('boshURL').value || config.bosh || '/http-bind');
  23. if (connection.disco) {
  24. // for chrome, add multistream cap
  25. }
  26. connection.jingle.pc_constraints = RTC.pc_constraints;
  27. var jid = document.getElementById('jid').value || config.hosts.domain || window.location.hostname;
  28. connection.connect(jid, document.getElementById('password').value, function (status) {
  29. if (status == Strophe.Status.CONNECTED) {
  30. console.log('connected');
  31. if (RTC.browser == 'firefox') {
  32. getUserMediaWithConstraints(['audio']);
  33. } else {
  34. getUserMediaWithConstraints(['audio', 'video'], '360');
  35. }
  36. document.getElementById('connect').disabled = true;
  37. } else {
  38. console.log('status', status);
  39. }
  40. });
  41. }
  42. function doJoin() {
  43. var roomnode = null;
  44. var path = window.location.pathname;
  45. var roomjid;
  46. // determinde the room node from the url
  47. // TODO: just the roomnode or the whole bare jid?
  48. if (config.getroomnode && typeof config.getroomnode === 'function') {
  49. // custom function might be responsible for doing the pushstate
  50. roomnode = config.getroomnode(path);
  51. } else {
  52. /* fall back to default strategy
  53. * this is making assumptions about how the URL->room mapping happens.
  54. * It currently assumes deployment at root, with a rewrite like the
  55. * following one (for nginx):
  56. location ~ ^/([a-zA-Z0-9]+)$ {
  57. rewrite ^/(.*)$ / break;
  58. }
  59. */
  60. if (path.length > 1) {
  61. roomnode = path.substr(1).toLowerCase();
  62. } else {
  63. roomnode = Math.random().toString(36).substr(2, 20);
  64. window.history.pushState('VideoChat', 'Room: ' + roomnode, window.location.pathname + roomnode);
  65. }
  66. }
  67. roomjid = roomnode + '@' + config.hosts.muc;
  68. if (config.useNicks) {
  69. var nick = window.prompt('Your nickname (optional)');
  70. if (nick) {
  71. roomjid += '/' + nick;
  72. } else {
  73. roomjid += '/' + Strophe.getNodeFromJid(connection.jid);
  74. }
  75. } else {
  76. roomjid += '/' + Strophe.getNodeFromJid(connection.jid);
  77. }
  78. connection.emuc.doJoin(roomjid);
  79. }
  80. $(document).bind('mediaready.jingle', function (event, stream) {
  81. connection.jingle.localStream = stream;
  82. RTC.attachMediaStream($('#localVideo'), stream);
  83. document.getElementById('localVideo').muted = true;
  84. document.getElementById('localVideo').autoplay = true;
  85. document.getElementById('localVideo').volume = 0;
  86. document.getElementById('largeVideo').volume = 0;
  87. document.getElementById('largeVideo').src = document.getElementById('localVideo').src;
  88. doJoin();
  89. });
  90. $(document).bind('mediafailure.jingle', function () {
  91. // FIXME
  92. });
  93. $(document).bind('remotestreamadded.jingle', function (event, data, sid) {
  94. function waitForRemoteVideo(selector, sid) {
  95. var sess = connection.jingle.sessions[sid];
  96. videoTracks = data.stream.getVideoTracks();
  97. if (videoTracks.length === 0 || selector[0].currentTime > 0) {
  98. RTC.attachMediaStream(selector, data.stream); // FIXME: why do i have to do this for FF?
  99. $(document).trigger('callactive.jingle', [selector, sid]);
  100. console.log('waitForremotevideo', sess.peerconnection.iceConnectionState, sess.peerconnection.signalingState);
  101. } else {
  102. setTimeout(function () { waitForRemoteVideo(selector, sid); }, 100);
  103. }
  104. }
  105. var sess = connection.jingle.sessions[sid];
  106. // look up an associated JID for a stream id
  107. if (data.stream.id.indexOf('mixedmslabel') == -1) {
  108. var ssrclines = SDPUtil.find_lines(sess.peerconnection.remoteDescription.sdp, 'a=ssrc');
  109. ssrclines = ssrclines.filter(function (line) {
  110. return line.indexOf('mslabel:' + data.stream.label) != -1;
  111. })
  112. if (ssrclines.length) {
  113. thessrc = ssrclines[0].substring(7).split(' ')[0];
  114. // ok to overwrite the one from focus? might save work in colibri.js
  115. console.log('associated jid', ssrc2jid[thessrc], data.peerjid);
  116. if (ssrc2jid[thessrc]) {
  117. data.peerjid = ssrc2jid[thessrc];
  118. }
  119. }
  120. }
  121. var vid = document.createElement('video');
  122. // FIXME: the span should not be created here but on muc join
  123. var span = document.createElement('span');
  124. if (data.peerjid) {
  125. // FIXME: how to name this span? data.peerjid is not set for jingle clients
  126. span.id = 'participant_' + Strophe.getResourceFromJid(data.peerjid);
  127. } else if (data.stream.id != 'mixedmslabel') {
  128. console.warn('can not associate stream', data.stream.id, 'with a participant');
  129. }
  130. span.className = 'videocontainer';
  131. var id = 'remoteVideo_' + sid + '_' + data.stream.id;
  132. vid.id = id;
  133. vid.autoplay = true;
  134. vid.oncontextmenu = function () { return false; };
  135. var remotes = document.getElementById('remoteVideos');
  136. span.appendChild(vid);
  137. if (id.indexOf('mixedmslabel') != -1) {
  138. $(span).hide();
  139. }
  140. remotes.appendChild(span);
  141. var sel = $('#' + id);
  142. sel.hide();
  143. RTC.attachMediaStream(sel, data.stream);
  144. waitForRemoteVideo(sel, sid);
  145. data.stream.onended = function () {
  146. console.log('stream ended', this.id);
  147. var src = $('#' + id).attr('src');
  148. // FIXME: likewise, the parent should not be removed here
  149. // but on MUC part
  150. $('#' + id).parent().remove();
  151. if (src === $('#largeVideo').attr('src')) {
  152. // this is currently displayed as large
  153. // pick the last visible video in the row
  154. // if nobody else is left, this picks the local video
  155. var pick = $('#remoteVideos>span:visible:last>video').get(0);
  156. // mute if localvideo
  157. document.getElementById('largeVideo').volume = pick.volume;
  158. document.getElementById('largeVideo').src = pick.src;
  159. }
  160. resizeThumbnails();
  161. };
  162. sel.click(
  163. function () {
  164. console.log('hover in', $(this).attr('src'));
  165. var newSrc = $(this).attr('src');
  166. if ($('#largeVideo').attr('src') != newSrc) {
  167. document.getElementById('largeVideo').volume = 1;
  168. $('#largeVideo').fadeOut(300, function () {
  169. $(this).attr('src', newSrc);
  170. $(this).fadeIn(300);
  171. });
  172. }
  173. }
  174. );
  175. });
  176. $(document).bind('callincoming.jingle', function (event, sid) {
  177. var sess = connection.jingle.sessions[sid];
  178. // TODO: check affiliation and/or role
  179. console.log('emuc data for', sess.peerjid, connection.emuc.members[sess.peerjid]);
  180. sess.sendAnswer();
  181. sess.accept();
  182. });
  183. $(document).bind('callactive.jingle', function (event, videoelem, sid) {
  184. if (videoelem.attr('id').indexOf('mixedmslabel') == -1) {
  185. // ignore mixedmslabela0 and v0
  186. videoelem.show();
  187. resizeThumbnails();
  188. document.getElementById('largeVideo').volume = 1;
  189. $('#largeVideo').attr('src', videoelem.attr('src'));
  190. }
  191. });
  192. $(document).bind('callterminated.jingle', function (event, sid, reason) {
  193. // FIXME
  194. });
  195. $(document).bind('setLocalDescription.jingle', function (event, sid) {
  196. // put our ssrcs into presence so other clients can identify our stream
  197. var sess = connection.jingle.sessions[sid];
  198. var newssrcs = {};
  199. var localSDP = new SDP(sess.peerconnection.localDescription.sdp);
  200. localSDP.media.forEach(function (media) {
  201. var type = SDPUtil.parse_mline(media.split('\r\n')[0]).media;
  202. var ssrc = SDPUtil.find_line(media, 'a=ssrc:').substring(7).split(' ')[0];
  203. // assumes a single local ssrc
  204. newssrcs[type] = ssrc;
  205. });
  206. console.log('new ssrcs', newssrcs);
  207. // just blast off presence for everything -- TODO: optimize
  208. var pres = $pres({to: connection.emuc.myroomjid });
  209. pres.c('x', {xmlns: 'http://jabber.org/protocol/muc'}).up();
  210. pres.c('media', {xmlns: 'http://estos.de/ns/mjs'});
  211. Object.keys(newssrcs).forEach(function (mtype) {
  212. pres.c('source', {type: mtype, ssrc: newssrcs[mtype]}).up();
  213. });
  214. pres.up();
  215. connection.send(pres);
  216. });
  217. $(document).bind('joined.muc', function (event, jid, info) {
  218. updateRoomUrl(window.location.href);
  219. // Once we've joined the muc show the toolbar
  220. showToolbar();
  221. if (Object.keys(connection.emuc.members).length < 1) {
  222. focus = new ColibriFocus(connection, config.hosts.bridge);
  223. }
  224. });
  225. $(document).bind('entered.muc', function (event, jid, info, pres) {
  226. console.log('entered', jid, info);
  227. console.log(focus);
  228. if (focus !== null) {
  229. // FIXME: this should prepare the video
  230. if (focus.confid === null) {
  231. console.log('make new conference with', jid);
  232. focus.makeConference(Object.keys(connection.emuc.members));
  233. } else {
  234. console.log('invite', jid, 'into conference');
  235. focus.addNewParticipant(jid);
  236. }
  237. }
  238. else if (sharedKey) {
  239. updateLockButton();
  240. }
  241. $(pres).find('>media[xmlns="http://estos.de/ns/mjs"]>source').each(function (idx, ssrc) {
  242. //console.log(jid, 'assoc ssrc', ssrc.getAttribute('type'), ssrc.getAttribute('ssrc'));
  243. ssrc2jid[ssrc.getAttribute('ssrc')] = jid;
  244. });
  245. });
  246. $(document).bind('left.muc', function (event, jid) {
  247. console.log('left', jid);
  248. connection.jingle.terminateByJid(jid);
  249. // FIXME: this should actually hide the video already for a nicer UX
  250. if (Object.keys(connection.emuc.members).length === 0) {
  251. console.log('everyone left');
  252. if (focus !== null) {
  253. // FIXME: closing the connection is a hack to avoid some
  254. // problemswith reinit
  255. if (focus.peerconnection !== null) {
  256. focus.peerconnection.close();
  257. }
  258. focus = new ColibriFocus(connection, config.hosts.bridge);
  259. }
  260. }
  261. });
  262. $(document).bind('passwordrequired.muc', function (event, jid) {
  263. console.log('on password required', jid);
  264. $.prompt('<h2>Password required</h2>' +
  265. '<input id="lockKey" type="text" placeholder="shared key" autofocus>',
  266. {
  267. persistent: true,
  268. buttons: { "Ok": true , "Cancel": false},
  269. defaultButton: 1,
  270. loaded: function(event) {
  271. document.getElementById('lockKey').focus();
  272. },
  273. submit: function(e,v,m,f){
  274. if(v)
  275. {
  276. var lockKey = document.getElementById('lockKey');
  277. if (lockKey.value != null)
  278. {
  279. setSharedKey(lockKey);
  280. connection.emuc.doJoin(jid, lockKey.value);
  281. }
  282. }
  283. }
  284. });
  285. $(document).bind('presence.muc', function (event, jid, info, pres) {
  286. $(pres).find('>media[xmlns="http://estos.de/ns/mjs"]>source').each(function (idx, ssrc) {
  287. //console.log(jid, 'assoc ssrc', ssrc.getAttribute('type'), ssrc.getAttribute('ssrc'));
  288. ssrc2jid[ssrc.getAttribute('ssrc')] = jid;
  289. });
  290. $(document).bind('passwordrequired.muc', function (event, jid) {
  291. console.log('on password required', jid);
  292. $.prompt('<h2>Password required</h2>' +
  293. '<input id="lockKey" type="text" placeholder="shared key" autofocus>',
  294. {
  295. persistent: true,
  296. buttons: { "Ok": true , "Cancel": false},
  297. defaultButton: 1,
  298. loaded: function(event) {
  299. document.getElementById('lockKey').focus();
  300. },
  301. submit: function(e,v,m,f){
  302. if(v)
  303. {
  304. var lockKey = document.getElementById('lockKey');
  305. if (lockKey.value != null)
  306. {
  307. setSharedKey(lockKey);
  308. connection.emuc.doJoin(jid, lockKey.value);
  309. }
  310. }
  311. }
  312. });
  313. });
  314. function toggleVideo() {
  315. if (!(connection && connection.jingle.localStream)) return;
  316. for (var idx = 0; idx < connection.jingle.localStream.getVideoTracks().length; idx++) {
  317. connection.jingle.localStream.getVideoTracks()[idx].enabled = !connection.jingle.localStream.getVideoTracks()[idx].enabled;
  318. }
  319. }
  320. function toggleAudio() {
  321. if (!(connection && connection.jingle.localStream)) return;
  322. for (var idx = 0; idx < connection.jingle.localStream.getAudioTracks().length; idx++) {
  323. connection.jingle.localStream.getAudioTracks()[idx].enabled = !connection.jingle.localStream.getAudioTracks()[idx].enabled;
  324. }
  325. }
  326. function resizeLarge() {
  327. var availableHeight = window.innerHeight;
  328. var chatspaceWidth = $('#chatspace').width();
  329. var numvids = $('#remoteVideos>video:visible').length;
  330. if (numvids < 5)
  331. availableHeight -= 100; // min thumbnail height for up to 4 videos
  332. else
  333. availableHeight -= 50; // min thumbnail height for more than 5 videos
  334. availableHeight -= 79; // padding + link ontop
  335. var availableWidth = window.innerWidth - chatspaceWidth;
  336. var aspectRatio = 16.0 / 9.0;
  337. if (availableHeight < availableWidth / aspectRatio) {
  338. availableWidth = Math.floor(availableHeight * aspectRatio);
  339. }
  340. if (availableWidth < 0 || availableHeight < 0) return;
  341. $('#largeVideo').parent().width(availableWidth);
  342. $('#largeVideo').parent().height(availableWidth / aspectRatio);
  343. resizeThumbnails();
  344. }
  345. function resizeThumbnails() {
  346. // Calculate the available height, which is the inner window height minus 39px for the header
  347. // minus 4px for the delimiter lines on the top and bottom of the large video,
  348. // minus the 36px space inside the remoteVideos container used for highlighting shadow.
  349. var availableHeight = window.innerHeight - $('#largeVideo').height() - 79;
  350. var numvids = $('#remoteVideos>span:visible').length;
  351. // Remove the 1px borders arround videos.
  352. var availableWinWidth = $('#remoteVideos').width() - 2 * numvids;
  353. var availableWidth = availableWinWidth / numvids;
  354. var aspectRatio = 16.0 / 9.0;
  355. var maxHeight = Math.min(160, availableHeight);
  356. availableHeight = Math.min(maxHeight, availableWidth / aspectRatio);
  357. if (availableHeight < availableWidth / aspectRatio) {
  358. availableWidth = Math.floor(availableHeight * aspectRatio);
  359. }
  360. // size videos so that while keeping AR and max height, we have a nice fit
  361. $('#remoteVideos').height(availableHeight+26); // add the 2*18px-padding-top border used for highlighting shadow.
  362. $('#remoteVideos>span').width(availableWidth);
  363. $('#remoteVideos>span').height(availableHeight);
  364. }
  365. $(document).ready(function () {
  366. $('#nickinput').keydown(function(event) {
  367. if (event.keyCode == 13) {
  368. event.preventDefault();
  369. var val = this.value;
  370. this.value = '';
  371. if (!nickname) {
  372. nickname = val;
  373. $('#nickname').css({visibility:"hidden"});
  374. $('#chatconversation').css({visibility:'visible'});
  375. $('#usermsg').css({visibility:'visible'});
  376. $('#usermsg').focus();
  377. return;
  378. }
  379. }
  380. });
  381. $('#usermsg').keydown(function(event) {
  382. if (event.keyCode == 13) {
  383. event.preventDefault();
  384. var message = this.value;
  385. $('#usermsg').val('').trigger('autosize.resize');
  386. this.focus();
  387. connection.emuc.sendMessage(message, nickname);
  388. }
  389. });
  390. $('#usermsg').autosize();
  391. resizeLarge();
  392. $(window).resize(function () {
  393. resizeLarge();
  394. });
  395. if (!$('#settings').is(':visible')) {
  396. console.log('init');
  397. init();
  398. } else {
  399. loginInfo.onsubmit = function (e) {
  400. if (e.preventDefault) e.preventDefault();
  401. $('#settings').hide();
  402. init();
  403. };
  404. }
  405. });
  406. $(window).bind('beforeunload', function () {
  407. if (connection && connection.connected) {
  408. // ensure signout
  409. $.ajax({
  410. type: 'POST',
  411. url: config.bosh,
  412. async: false,
  413. cache: false,
  414. contentType: 'application/xml',
  415. 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>",
  416. success: function (data) {
  417. console.log('signed out');
  418. console.log(data);
  419. },
  420. error: function (XMLHttpRequest, textStatus, errorThrown) {
  421. console.log('signout error', textStatus + ' (' + errorThrown + ')');
  422. }
  423. });
  424. }
  425. });
  426. function dump(elem, filename) {
  427. console.log("ELEMENT", elem);
  428. elem = elem.parentNode;
  429. elem.download = filename || 'xmpplog.json';
  430. elem.href = 'data:application/json;charset=utf-8,\n';
  431. var data = {};
  432. data.time = new Date();
  433. data.url = window.location.href;
  434. data.ua = navigator.userAgent;
  435. if (connection.logger) {
  436. data.xmpp = connection.logger.log;
  437. }
  438. if (connection.jingle) {
  439. Object.keys(connection.jingle.sessions).forEach(function (sid) {
  440. var session = connection.jingle.sessions[sid];
  441. if (session.peerconnection && session.peerconnection.updateLog) {
  442. // FIXME: should probably be a .dump call
  443. data["jingle_" + session.sid] = session.peerconnection.updateLog;
  444. }
  445. });
  446. }
  447. elem.href += encodeURIComponent(JSON.stringify(data, null, ' '));
  448. return false;
  449. }
  450. /*
  451. * Appends the given message to the chat conversation.
  452. */
  453. // <a onclick="dump(event.target);">my download button</a>
  454. function dump(elem, filename){
  455. elem = elem.parentNode;
  456. elem.download = filename || 'xmpplog.json';
  457. elem.href = 'data:application/json;charset=utf-8,\n';
  458. var data = {};
  459. data.time = new Date();
  460. data.url = window.location.href;
  461. data.ua = navigator.userAgent;
  462. if (connection.logger) {
  463. data.xmpp = connection.logger.log;
  464. }
  465. if (connection.jingle) {
  466. Object.keys(connection.jingle.sessions).forEach(function (sid) {
  467. var session = connection.jingle.sessions[sid];
  468. if (session.peerconnection && session.peerconnection.updateLog) {
  469. // FIXME: should probably be a .dump call
  470. data["jingle_" + session.sid] = session.peerconnection.updateLog;
  471. }
  472. });
  473. }
  474. elem.href += encodeURIComponent(JSON.stringify(data, null, ' '));
  475. return false;
  476. }
  477. /*
  478. * Appends the given message to the chat conversation.
  479. */
  480. function updateChatConversation(nick, message)
  481. {
  482. var divClassName = '';
  483. if (nickname == nick)
  484. divClassName = "localuser";
  485. else
  486. divClassName = "remoteuser";
  487. $('#chatconversation').append('<div class="' + divClassName + '"><b>' + nick + ': </b>' + message + '</div>');
  488. $('#chatconversation').animate({ scrollTop: $('#chatconversation')[0].scrollHeight}, 1000);
  489. }
  490. /*
  491. * Changes the style class of the element given by id.
  492. */
  493. function buttonClick(id, classname) {
  494. $(id).toggleClass(classname); // add the class to the clicked element
  495. }
  496. /*
  497. * Opens the lock room dialog.
  498. */
  499. function openLockDialog() {
  500. // Only the focus is able to set a shared key.
  501. if (focus == null) {
  502. if (sharedKey)
  503. $.prompt("This conversation is currently protected by a shared secret key.",
  504. {
  505. title: "Secrect key",
  506. persistent: false
  507. });
  508. else
  509. $.prompt("This conversation isn't currently protected by a secret key. Only the owner of the conference could set a shared key.",
  510. {
  511. title: "Secrect key",
  512. persistent: false
  513. });
  514. }
  515. else {
  516. if (sharedKey)
  517. $.prompt("Are you sure you would like to remove your secret key?",
  518. {
  519. title: "Remove secrect key",
  520. persistent: false,
  521. buttons: { "Remove": true, "Cancel": false},
  522. defaultButton: 1,
  523. submit: function(e,v,m,f){
  524. if(v)
  525. {
  526. setSharedKey('');
  527. lockRoom(false);
  528. }
  529. }
  530. });
  531. else
  532. $.prompt('<h2>Set a secrect key to lock your room</h2>' +
  533. '<input id="lockKey" type="text" placeholder="your shared key" autofocus>',
  534. {
  535. persistent: false,
  536. buttons: { "Save": true , "Cancel": false},
  537. defaultButton: 1,
  538. loaded: function(event) {
  539. document.getElementById('lockKey').focus();
  540. },
  541. submit: function(e,v,m,f){
  542. if(v)
  543. {
  544. var lockKey = document.getElementById('lockKey');
  545. if (lockKey.value)
  546. {
  547. setSharedKey(lockKey.value);
  548. lockRoom(true);
  549. }
  550. }
  551. }
  552. });
  553. }
  554. }
  555. /*
  556. * Opens the invite link dialog.
  557. */
  558. function openLinkDialog() {
  559. $.prompt('<input id="inviteLinkRef" type="text" value="' + roomUrl + '" onclick="this.select();">',
  560. {
  561. title: "Share this link with everyone you want to invite",
  562. persistent: false,
  563. buttons: { "Cancel": false},
  564. loaded: function(event) {
  565. document.getElementById('inviteLinkRef').select();
  566. }
  567. });
  568. }
  569. /*
  570. * Locks / unlocks the room.
  571. */
  572. function lockRoom(lock) {
  573. console.log("LOCK", sharedKey);
  574. if (lock)
  575. connection.emuc.lockRoom(sharedKey);
  576. else
  577. connection.emuc.lockRoom('');
  578. updateLockButton();
  579. }
  580. /*
  581. * Sets the shared key.
  582. */
  583. function setSharedKey(sKey) {
  584. sharedKey = sKey;
  585. }
  586. /*
  587. * Updates the lock button state.
  588. */
  589. function updateLockButton() {
  590. buttonClick("#lockIcon", "fa fa-unlock fa-lg fa fa-lock fa-lg");
  591. }
  592. /*
  593. * Opens / closes the chat area.
  594. */
  595. function openChat() {
  596. var chatspace = $('#chatspace');
  597. var videospace = $('#videospace');
  598. var chatspaceWidth = chatspace.width();
  599. if (chatspace.css("opacity") == 1) {
  600. chatspace.animate({opacity: 0}, "fast");
  601. chatspace.animate({width: 0}, "slow");
  602. videospace.animate({right: 0, width:"100%"}, "slow");
  603. }
  604. else {
  605. chatspace.animate({width:"20%"}, "slow");
  606. chatspace.animate({opacity: 1}, "slow");
  607. videospace.animate({right:chatspaceWidth, width:"80%"}, "slow");
  608. }
  609. // Request the focus in the nickname field or the chat input field.
  610. if ($('#nickinput').is(':visible'))
  611. $('#nickinput').focus();
  612. else
  613. $('#usermsg').focus();
  614. }
  615. /*
  616. * Shows the call main toolbar.
  617. */
  618. function showToolbar() {
  619. $('#toolbar').css({visibility:"visible"});
  620. }
  621. /*
  622. * Updates the room invite url.
  623. */
  624. function updateRoomUrl(newRoomUrl) {
  625. roomUrl = newRoomUrl;
  626. }
  627. /*
  628. * Warning to the user that the conference window is about to be closed.
  629. */
  630. function closePageWarning() {
  631. if (focus != null)
  632. return "You are the owner of this conference call and you are about to end it.";
  633. else
  634. return "You are about to leave this conversation.";
  635. }