Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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