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 45KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329
  1. /* jshint -W117 */
  2. /* application specific logic */
  3. var connection = null;
  4. var focus = null;
  5. var activecall = null;
  6. var RTC = null;
  7. var RTCPeerConnection = null;
  8. var nickname = null;
  9. var sharedKey = '';
  10. var roomUrl = null;
  11. var ssrc2jid = {};
  12. var localVideoSrc = null;
  13. var preziPlayer = null;
  14. /* window.onbeforeunload = closePageWarning; */
  15. function init() {
  16. RTC = setupRTC();
  17. if (RTC === null) {
  18. window.location.href = 'webrtcrequired.html';
  19. return;
  20. } else if (RTC.browser !== 'chrome') {
  21. window.location.href = 'chromeonly.html';
  22. return;
  23. }
  24. RTCPeerconnection = TraceablePeerConnection;
  25. connection = new Strophe.Connection(document.getElementById('boshURL').value || config.bosh || '/http-bind');
  26. if (nickname) {
  27. connection.emuc.addDisplayNameToPresence(nickname);
  28. }
  29. if (connection.disco) {
  30. // for chrome, add multistream cap
  31. }
  32. connection.jingle.pc_constraints = RTC.pc_constraints;
  33. if (config.useIPv6) {
  34. // https://code.google.com/p/webrtc/issues/detail?id=2828
  35. if (!connection.jingle.pc_constraints.optional) connection.jingle.pc_constraints.optional = [];
  36. connection.jingle.pc_constraints.optional.push({googIPv6: true});
  37. }
  38. var jid = document.getElementById('jid').value || config.hosts.domain || window.location.hostname;
  39. connection.connect(jid, document.getElementById('password').value, function (status) {
  40. if (status === Strophe.Status.CONNECTED) {
  41. console.log('connected');
  42. if (config.useStunTurn) {
  43. connection.jingle.getStunAndTurnCredentials();
  44. }
  45. if (RTC.browser === 'firefox') {
  46. getUserMediaWithConstraints(['audio']);
  47. } else {
  48. getUserMediaWithConstraints(['audio', 'video'], config.resolution || '360');
  49. }
  50. document.getElementById('connect').disabled = true;
  51. } else {
  52. console.log('status', status);
  53. }
  54. });
  55. }
  56. function doJoin() {
  57. var roomnode = null;
  58. var path = window.location.pathname;
  59. var roomjid;
  60. // determinde the room node from the url
  61. // TODO: just the roomnode or the whole bare jid?
  62. if (config.getroomnode && typeof config.getroomnode === 'function') {
  63. // custom function might be responsible for doing the pushstate
  64. roomnode = config.getroomnode(path);
  65. } else {
  66. /* fall back to default strategy
  67. * this is making assumptions about how the URL->room mapping happens.
  68. * It currently assumes deployment at root, with a rewrite like the
  69. * following one (for nginx):
  70. location ~ ^/([a-zA-Z0-9]+)$ {
  71. rewrite ^/(.*)$ / break;
  72. }
  73. */
  74. if (path.length > 1) {
  75. roomnode = path.substr(1).toLowerCase();
  76. } else {
  77. roomnode = Math.random().toString(36).substr(2, 20);
  78. window.history.pushState('VideoChat',
  79. 'Room: ' + roomnode, window.location.pathname + roomnode);
  80. }
  81. }
  82. roomjid = roomnode + '@' + config.hosts.muc;
  83. if (config.useNicks) {
  84. var nick = window.prompt('Your nickname (optional)');
  85. if (nick) {
  86. roomjid += '/' + nick;
  87. } else {
  88. roomjid += '/' + Strophe.getNodeFromJid(connection.jid);
  89. }
  90. } else {
  91. roomjid += '/' + Strophe.getNodeFromJid(connection.jid).substr(0,8);
  92. }
  93. connection.emuc.doJoin(roomjid);
  94. }
  95. $(document).bind('mediaready.jingle', function (event, stream) {
  96. connection.jingle.localStream = stream;
  97. RTC.attachMediaStream($('#localVideo'), stream);
  98. document.getElementById('localVideo').autoplay = true;
  99. document.getElementById('localVideo').volume = 0;
  100. localVideoSrc = document.getElementById('localVideo').src;
  101. updateLargeVideo(localVideoSrc, true, 0);
  102. $('#localVideo').click(function () {
  103. $(document).trigger("video.selected", [false]);
  104. updateLargeVideo($(this).attr('src'), true, 0);
  105. $('video').each(function (idx, el) {
  106. if (el.id.indexOf('mixedmslabel') !== -1) {
  107. el.volume = 0;
  108. el.volume = 1;
  109. }
  110. });
  111. });
  112. doJoin();
  113. });
  114. $(document).bind('mediafailure.jingle', function () {
  115. // FIXME
  116. });
  117. $(document).bind('remotestreamadded.jingle', function (event, data, sid) {
  118. function waitForRemoteVideo(selector, sid) {
  119. var sess = connection.jingle.sessions[sid];
  120. if (data.stream.id === 'mixedmslabel') return;
  121. videoTracks = data.stream.getVideoTracks();
  122. if (videoTracks.length === 0 || selector[0].currentTime > 0) {
  123. RTC.attachMediaStream(selector, data.stream); // FIXME: why do i have to do this for FF?
  124. $(document).trigger('callactive.jingle', [selector, sid]);
  125. console.log('waitForremotevideo', sess.peerconnection.iceConnectionState, sess.peerconnection.signalingState);
  126. } else {
  127. setTimeout(function () { waitForRemoteVideo(selector, sid); }, 250);
  128. }
  129. }
  130. var sess = connection.jingle.sessions[sid];
  131. // look up an associated JID for a stream id
  132. if (data.stream.id.indexOf('mixedmslabel') === -1) {
  133. var ssrclines = SDPUtil.find_lines(sess.peerconnection.remoteDescription.sdp, 'a=ssrc');
  134. ssrclines = ssrclines.filter(function (line) {
  135. return line.indexOf('mslabel:' + data.stream.label) !== -1;
  136. });
  137. if (ssrclines.length) {
  138. thessrc = ssrclines[0].substring(7).split(' ')[0];
  139. // ok to overwrite the one from focus? might save work in colibri.js
  140. console.log('associated jid', ssrc2jid[thessrc], data.peerjid);
  141. if (ssrc2jid[thessrc]) {
  142. data.peerjid = ssrc2jid[thessrc];
  143. }
  144. }
  145. }
  146. var container;
  147. var remotes = document.getElementById('remoteVideos');
  148. if (data.peerjid) {
  149. container = document.getElementById(
  150. 'participant_' + Strophe.getResourceFromJid(data.peerjid));
  151. if (!container) {
  152. console.warn('no container for', data.peerjid);
  153. // create for now...
  154. // FIXME: should be removed
  155. container = addRemoteVideoContainer(
  156. 'participant_' + Strophe.getResourceFromJid(data.peerjid));
  157. } else {
  158. //console.log('found container for', data.peerjid);
  159. }
  160. } else {
  161. if (data.stream.id !== 'mixedmslabel') {
  162. console.warn('can not associate stream', data.stream.id, 'with a participant');
  163. }
  164. // FIXME: for the mixed ms we dont need a video -- currently
  165. container = document.createElement('span');
  166. container.className = 'videocontainer';
  167. remotes.appendChild(container);
  168. Util.playSoundNotification('userJoined');
  169. }
  170. var vid = document.createElement('video');
  171. var id = 'remoteVideo_' + sid + '_' + data.stream.id;
  172. vid.id = id;
  173. vid.autoplay = true;
  174. vid.oncontextmenu = function () { return false; };
  175. container.appendChild(vid);
  176. // TODO: make mixedstream display:none via css?
  177. if (id.indexOf('mixedmslabel') !== -1) {
  178. container.id = 'mixedstream';
  179. $(container).hide();
  180. }
  181. var sel = $('#' + id);
  182. sel.hide();
  183. RTC.attachMediaStream(sel, data.stream);
  184. waitForRemoteVideo(sel, sid);
  185. data.stream.onended = function () {
  186. console.log('stream ended', this.id);
  187. var src = $('#' + id).attr('src');
  188. if (src === $('#largeVideo').attr('src')) {
  189. // this is currently displayed as large
  190. // pick the last visible video in the row
  191. // if nobody else is left, this picks the local video
  192. var pick = $('#remoteVideos>span[id!="mixedstream"]:visible:last>video').get(0);
  193. // mute if localvideo
  194. var isLocalVideo = false;
  195. if (pick) {
  196. if (pick.src === localVideoSrc)
  197. isLocalVideo = true;
  198. updateLargeVideo(pick.src, isLocalVideo, pick.volume);
  199. }
  200. }
  201. $('#' + id).parent().remove();
  202. Util.playSoundNotification('userLeft');
  203. resizeThumbnails();
  204. };
  205. sel.click(
  206. function () {
  207. $(document).trigger("video.selected", [false]);
  208. updateLargeVideo($(this).attr('src'), false, 1);
  209. }
  210. );
  211. // an attempt to work around https://github.com/jitsi/jitmeet/issues/32
  212. if (data.peerjid && sess.peerjid === data.peerjid &&
  213. data.stream.getVideoTracks().length === 0 &&
  214. connection.jingle.localStream.getVideoTracks().length > 0) {
  215. window.setTimeout(function() {
  216. sendKeyframe(sess.peerconnection);
  217. }, 3000);
  218. }
  219. });
  220. // an attempt to work around https://github.com/jitsi/jitmeet/issues/32
  221. function sendKeyframe(pc) {
  222. console.log('sendkeyframe', pc.iceConnectionState);
  223. if (pc.iceConnectionState !== 'connected') return; // safe...
  224. pc.setRemoteDescription(
  225. pc.remoteDescription,
  226. function () {
  227. pc.createAnswer(
  228. function (modifiedAnswer) {
  229. pc.setLocalDescription(modifiedAnswer,
  230. function () {
  231. },
  232. function (error) {
  233. console.log('triggerKeyframe setLocalDescription failed', error);
  234. }
  235. );
  236. },
  237. function (error) {
  238. console.log('triggerKeyframe createAnswer failed', error);
  239. }
  240. );
  241. },
  242. function (error) {
  243. console.log('triggerKeyframe setRemoteDescription failed', error);
  244. }
  245. );
  246. }
  247. function demonstrateabug(pc) {
  248. // funny way of doing mute. the subsequent offer contains things like rtcp-mux
  249. // and triggers all new ice candidates (ice restart)
  250. // this code is here to demonstrate a bug
  251. pc.createOffer(
  252. function (offer) {
  253. console.log(offer);
  254. var sdp = new SDP(offer.sdp);
  255. if (sdp.media.length > 1) {
  256. sdp.media[1] = sdp.media[1].replace('a=sendrecv', 'a=recvonly');
  257. sdp.raw = sdp.session + sdp.media.join('');
  258. offer.sdp = sdp.raw;
  259. pc.setLocalDescription(offer,
  260. function () {
  261. console.log('mute SLD ok');
  262. },
  263. function(error) {
  264. console.log('mute SLD error');
  265. }
  266. );
  267. }
  268. },
  269. function (error) {
  270. console.warn(error);
  271. },
  272. {mandatory: {OfferToReceiveAudio: true, OfferToReceiveVideo: false}}
  273. );
  274. }
  275. // really mute video, i.e. dont even send black frames
  276. function muteVideo(pc, unmute) {
  277. // FIXME: this probably needs another of those lovely state safeguards...
  278. // which checks for iceconn == connected and sigstate == stable
  279. pc.setRemoteDescription(pc.remoteDescription,
  280. function () {
  281. pc.createAnswer(
  282. function (answer) {
  283. var sdp = new SDP(answer.sdp);
  284. if (sdp.media.length > 1) {
  285. if (unmute)
  286. sdp.media[1] = sdp.media[1].replace('a=recvonly', 'a=sendrecv');
  287. else
  288. sdp.media[1] = sdp.media[1].replace('a=sendrecv', 'a=recvonly');
  289. sdp.raw = sdp.session + sdp.media.join('');
  290. answer.sdp = sdp.raw;
  291. }
  292. pc.setLocalDescription(answer,
  293. function () {
  294. console.log('mute SLD ok');
  295. },
  296. function(error) {
  297. console.log('mute SLD error');
  298. }
  299. );
  300. },
  301. function (error) {
  302. console.log(error);
  303. }
  304. );
  305. },
  306. function (error) {
  307. console.log('muteVideo SRD error');
  308. }
  309. );
  310. }
  311. $(document).bind('callincoming.jingle', function (event, sid) {
  312. var sess = connection.jingle.sessions[sid];
  313. // TODO: do we check activecall == null?
  314. activecall = sess;
  315. // TODO: check affiliation and/or role
  316. console.log('emuc data for', sess.peerjid, connection.emuc.members[sess.peerjid]);
  317. sess.usedrip = true; // not-so-naive trickle ice
  318. sess.sendAnswer();
  319. sess.accept();
  320. });
  321. $(document).bind('callactive.jingle', function (event, videoelem, sid) {
  322. if (videoelem.attr('id').indexOf('mixedmslabel') === -1) {
  323. // ignore mixedmslabela0 and v0
  324. videoelem.show();
  325. resizeThumbnails();
  326. updateLargeVideo(videoelem.attr('src'), false, 1);
  327. showFocusIndicator();
  328. }
  329. });
  330. $(document).bind('callterminated.jingle', function (event, sid, reason) {
  331. // FIXME
  332. });
  333. $(document).bind('setLocalDescription.jingle', function (event, sid) {
  334. // put our ssrcs into presence so other clients can identify our stream
  335. var sess = connection.jingle.sessions[sid];
  336. var newssrcs = {};
  337. var directions = {};
  338. var localSDP = new SDP(sess.peerconnection.localDescription.sdp);
  339. localSDP.media.forEach(function (media) {
  340. var type = SDPUtil.parse_mline(media.split('\r\n')[0]).media;
  341. if (SDPUtil.find_line(media, 'a=ssrc:')) {
  342. // assumes a single local ssrc
  343. var ssrc = SDPUtil.find_line(media, 'a=ssrc:').substring(7).split(' ')[0];
  344. newssrcs[type] = ssrc;
  345. directions[type] = (SDPUtil.find_line(media, 'a=sendrecv') || SDPUtil.find_line(media, 'a=recvonly') || SDPUtil.find_line('a=sendonly') || SDPUtil.find_line('a=inactive') || 'a=sendrecv').substr(2);
  346. }
  347. });
  348. console.log('new ssrcs', newssrcs);
  349. var i = 0;
  350. Object.keys(newssrcs).forEach(function (mtype) {
  351. i++;
  352. connection.emuc.addMediaToPresence(i, mtype, newssrcs[mtype], directions[mtype]);
  353. });
  354. if (i > 0) {
  355. connection.emuc.sendPresence();
  356. }
  357. });
  358. $(document).bind('joined.muc', function (event, jid, info) {
  359. updateRoomUrl(window.location.href);
  360. document.getElementById('localNick').appendChild(
  361. document.createTextNode(Strophe.getResourceFromJid(jid) + ' (me)')
  362. );
  363. if (Object.keys(connection.emuc.members).length < 1) {
  364. focus = new ColibriFocus(connection, config.hosts.bridge);
  365. }
  366. if (focus && config.etherpad_base) {
  367. Etherpad.init();
  368. }
  369. showFocusIndicator();
  370. // Once we've joined the muc show the toolbar
  371. showToolbar();
  372. var displayName = '';
  373. if (info.displayName)
  374. displayName = info.displayName + ' (me)';
  375. showDisplayName('localVideoContainer', displayName);
  376. });
  377. $(document).bind('entered.muc', function (event, jid, info, pres) {
  378. console.log('entered', jid, info);
  379. console.log(focus);
  380. var videoSpanId = 'participant_' + Strophe.getResourceFromJid(jid);
  381. var container = addRemoteVideoContainer(videoSpanId);
  382. if (info.displayName)
  383. showDisplayName(videoSpanId, info.displayName);
  384. var nickfield = document.createElement('span');
  385. nickfield.appendChild(document.createTextNode(Strophe.getResourceFromJid(jid)));
  386. container.appendChild(nickfield);
  387. resizeThumbnails();
  388. if (focus !== null) {
  389. // FIXME: this should prepare the video
  390. if (focus.confid === null) {
  391. console.log('make new conference with', jid);
  392. focus.makeConference(Object.keys(connection.emuc.members));
  393. } else {
  394. console.log('invite', jid, 'into conference');
  395. focus.addNewParticipant(jid);
  396. }
  397. }
  398. else if (sharedKey) {
  399. updateLockButton();
  400. }
  401. $(pres).find('>media[xmlns="http://estos.de/ns/mjs"]>source').each(function (idx, ssrc) {
  402. //console.log(jid, 'assoc ssrc', ssrc.getAttribute('type'), ssrc.getAttribute('ssrc'));
  403. ssrc2jid[ssrc.getAttribute('ssrc')] = jid;
  404. });
  405. });
  406. $(document).bind('left.muc', function (event, jid) {
  407. console.log('left', jid);
  408. connection.jingle.terminateByJid(jid);
  409. var container = document.getElementById('participant_' + Strophe.getResourceFromJid(jid));
  410. if (container) {
  411. // hide here, wait for video to close before removing
  412. $(container).hide();
  413. resizeThumbnails();
  414. }
  415. if (focus === null && connection.emuc.myroomjid === connection.emuc.list_members[0]) {
  416. console.log('welcome to our new focus... myself');
  417. focus = new ColibriFocus(connection, config.hosts.bridge);
  418. if (Object.keys(connection.emuc.members).length > 0) {
  419. focus.makeConference(Object.keys(connection.emuc.members));
  420. }
  421. $(document).trigger('focusechanged.muc', [focus]);
  422. }
  423. else if (focus && Object.keys(connection.emuc.members).length === 0) {
  424. console.log('everyone left');
  425. if (focus !== null) {
  426. // FIXME: closing the connection is a hack to avoid some
  427. // problemswith reinit
  428. if (focus.peerconnection !== null) {
  429. focus.peerconnection.close();
  430. }
  431. focus = new ColibriFocus(connection, config.hosts.bridge);
  432. }
  433. }
  434. if (connection.emuc.getPrezi(jid)) {
  435. $(document).trigger('presentationremoved.muc', [jid, connection.emuc.getPrezi(jid)]);
  436. }
  437. });
  438. $(document).bind('presence.muc', function (event, jid, info, pres) {
  439. $(pres).find('>media[xmlns="http://estos.de/ns/mjs"]>source').each(function (idx, ssrc) {
  440. //console.log(jid, 'assoc ssrc', ssrc.getAttribute('type'), ssrc.getAttribute('ssrc'));
  441. ssrc2jid[ssrc.getAttribute('ssrc')] = jid;
  442. // might need to update the direction if participant just went from sendrecv to recvonly
  443. if (ssrc.getAttribute('type') === 'video') {
  444. var el = $('#participant_' + Strophe.getResourceFromJid(jid) + '>video');
  445. switch(ssrc.getAttribute('direction')) {
  446. case 'sendrecv':
  447. el.show();
  448. break;
  449. case 'recvonly':
  450. el.hide();
  451. break;
  452. }
  453. }
  454. });
  455. if (info.displayName) {
  456. if (jid === connection.emuc.myroomjid)
  457. showDisplayName('localVideoContainer', info.displayName + ' (me)');
  458. else
  459. showDisplayName('participant_' + Strophe.getResourceFromJid(jid), info.displayName);
  460. }
  461. });
  462. $(document).bind('passwordrequired.muc', function (event, jid) {
  463. console.log('on password required', jid);
  464. $.prompt('<h2>Password required</h2>' +
  465. '<input id="lockKey" type="text" placeholder="shared key" autofocus>',
  466. {
  467. persistent: true,
  468. buttons: { "Ok": true , "Cancel": false},
  469. defaultButton: 1,
  470. loaded: function(event) {
  471. document.getElementById('lockKey').focus();
  472. },
  473. submit: function(e,v,m,f){
  474. if(v)
  475. {
  476. var lockKey = document.getElementById('lockKey');
  477. if (lockKey.value !== null)
  478. {
  479. setSharedKey(lockKey.value);
  480. connection.emuc.doJoin(jid, lockKey.value);
  481. }
  482. }
  483. }
  484. });
  485. });
  486. /*
  487. * Presentation has been removed.
  488. */
  489. $(document).bind('presentationremoved.muc', function(event, jid, presUrl) {
  490. console.log('presentation removed', presUrl);
  491. var presId = getPresentationId(presUrl);
  492. setPresentationVisible(false);
  493. $('#participant_' + Strophe.getResourceFromJid(jid) + '_' + presId).remove();
  494. $('#presentation>iframe').remove();
  495. if (preziPlayer !== null) {
  496. preziPlayer.destroy();
  497. preziPlayer = null;
  498. }
  499. });
  500. /*
  501. * Presentation has been added.
  502. */
  503. $(document).bind('presentationadded.muc', function (event, jid, presUrl, currentSlide) {
  504. console.log("presentation added", presUrl);
  505. var presId = getPresentationId(presUrl);
  506. var elementId = 'participant_' + Strophe.getResourceFromJid(jid) + '_' + presId;
  507. var container = addRemoteVideoContainer(elementId);
  508. resizeThumbnails();
  509. var controlsEnabled = false;
  510. if (jid === connection.emuc.myroomjid)
  511. controlsEnabled = true;
  512. setPresentationVisible(true);
  513. $('#largeVideoContainer').hover(
  514. function (event) {
  515. if (isPresentationVisible())
  516. $('#reloadPresentation').css({display:'inline-block'});
  517. },
  518. function (event) {
  519. if (!isPresentationVisible())
  520. $('#reloadPresentation').css({display:'none'});
  521. else {
  522. var e = event.toElement || event.relatedTarget;
  523. while(e && e.parentNode && e.parentNode !== window) {
  524. if (e.parentNode === this || e === this) {
  525. return false;
  526. }
  527. e = e.parentNode;
  528. }
  529. $('#reloadPresentation').css({display:'none'});
  530. }
  531. });
  532. preziPlayer = new PreziPlayer(
  533. 'presentation',
  534. {preziId: presId,
  535. width: $('#largeVideoContainer').width(),
  536. height: $('#largeVideoContainer').height(),
  537. controls: controlsEnabled,
  538. debug: true
  539. });
  540. $('#presentation>iframe').attr('id', preziPlayer.options.preziId);
  541. preziPlayer.on(PreziPlayer.EVENT_STATUS, function(event) {
  542. console.log("prezi status", event.value);
  543. if (event.value === PreziPlayer.STATUS_CONTENT_READY) {
  544. if (jid !== connection.emuc.myroomjid)
  545. preziPlayer.flyToStep(currentSlide);
  546. }
  547. });
  548. preziPlayer.on(PreziPlayer.EVENT_CURRENT_STEP, function(event) {
  549. console.log("event value", event.value);
  550. connection.emuc.addCurrentSlideToPresence(event.value);
  551. connection.emuc.sendPresence();
  552. });
  553. $("#" + elementId).css('background-image','url(../images/avatarprezi.png)');
  554. $("#" + elementId).click(
  555. function () {
  556. setPresentationVisible(true);
  557. }
  558. );
  559. });
  560. /*
  561. * Indicates presentation slide change.
  562. */
  563. $(document).bind('gotoslide.muc', function (event, jid, presUrl, current) {
  564. if (preziPlayer) {
  565. preziPlayer.flyToStep(current);
  566. }
  567. });
  568. /**
  569. * Returns the presentation id from the given url.
  570. */
  571. function getPresentationId (presUrl) {
  572. var presIdTmp = presUrl.substring(presUrl.indexOf("prezi.com/") + 10);
  573. return presIdTmp.substring(0, presIdTmp.indexOf('/'));
  574. }
  575. /*
  576. * Reloads the current presentation.
  577. */
  578. function reloadPresentation() {
  579. var iframe = document.getElementById(preziPlayer.options.preziId);
  580. iframe.src = iframe.src;
  581. }
  582. /*
  583. * Shows/hides a presentation.
  584. */
  585. function setPresentationVisible(visible) {
  586. if (visible) {
  587. // Trigger the video.selected event to indicate a change in the large video.
  588. $(document).trigger("video.selected", [true]);
  589. $('#largeVideo').fadeOut(300, function () {
  590. $('#largeVideo').css({visibility:'hidden'});
  591. $('#presentation>iframe').fadeIn(300, function() {
  592. $('#presentation>iframe').css({opacity:'1'});
  593. });
  594. });
  595. }
  596. else {
  597. if ($('#presentation>iframe')) {
  598. $('#presentation>iframe').fadeOut(300, function () {
  599. $('#presentation>iframe').css({opacity:'0'});
  600. $('#largeVideo').fadeIn(300, function() {
  601. $('#largeVideo').css({visibility:'visible'});
  602. });
  603. });
  604. }
  605. }
  606. }
  607. function isPresentationVisible() {
  608. return ($('#presentation>iframe') !== null && $('#presentation>iframe').css('opacity') == 1);
  609. }
  610. /**
  611. * Updates the large video with the given new video source.
  612. */
  613. function updateLargeVideo(newSrc, localVideo, vol) {
  614. console.log('hover in', newSrc);
  615. setPresentationVisible(false);
  616. if ($('#largeVideo').attr('src') !== newSrc) {
  617. document.getElementById('largeVideo').volume = vol;
  618. $('#largeVideo').fadeOut(300, function () {
  619. $(this).attr('src', newSrc);
  620. var videoTransform = document.getElementById('largeVideo').style.webkitTransform;
  621. if (localVideo && videoTransform !== 'scaleX(-1)') {
  622. document.getElementById('largeVideo').style.webkitTransform = "scaleX(-1)";
  623. }
  624. else if (!localVideo && videoTransform === 'scaleX(-1)') {
  625. document.getElementById('largeVideo').style.webkitTransform = "none";
  626. }
  627. $(this).fadeIn(300);
  628. });
  629. }
  630. }
  631. function toggleVideo() {
  632. if (!(connection && connection.jingle.localStream)) return;
  633. var ismuted = false;
  634. for (var idx = 0; idx < connection.jingle.localStream.getVideoTracks().length; idx++) {
  635. ismuted = !connection.jingle.localStream.getVideoTracks()[idx].enabled;
  636. }
  637. for (var idx = 0; idx < connection.jingle.localStream.getVideoTracks().length; idx++) {
  638. connection.jingle.localStream.getVideoTracks()[idx].enabled = !connection.jingle.localStream.getVideoTracks()[idx].enabled;
  639. }
  640. var sess = focus || activecall;
  641. if (!sess) {
  642. return;
  643. }
  644. sess.pendingop = ismuted ? 'unmute' : 'mute';
  645. sess.modifySources();
  646. }
  647. function toggleAudio() {
  648. if (!(connection && connection.jingle.localStream)) return;
  649. for (var idx = 0; idx < connection.jingle.localStream.getAudioTracks().length; idx++) {
  650. connection.jingle.localStream.getAudioTracks()[idx].enabled = !connection.jingle.localStream.getAudioTracks()[idx].enabled;
  651. }
  652. }
  653. var resizeLarge = function () {
  654. Chat.resizeChat();
  655. var availableHeight = window.innerHeight;
  656. var chatspaceWidth = $('#chatspace').is(":visible")
  657. ? $('#chatspace').width()
  658. : 0;
  659. var numvids = $('#remoteVideos>video:visible').length;
  660. if (numvids < 5)
  661. availableHeight -= 100; // min thumbnail height for up to 4 videos
  662. else
  663. availableHeight -= 50; // min thumbnail height for more than 5 videos
  664. availableHeight -= 79; // padding + link ontop
  665. var availableWidth = window.innerWidth - chatspaceWidth;
  666. var aspectRatio = 16.0 / 9.0;
  667. if (availableHeight < availableWidth / aspectRatio) {
  668. availableWidth = Math.floor(availableHeight * aspectRatio);
  669. }
  670. if (availableWidth < 0 || availableHeight < 0) return;
  671. $('#largeVideo').parent().width(availableWidth);
  672. $('#largeVideo').parent().height(availableWidth / aspectRatio);
  673. if ($('#presentation>iframe')) {
  674. $('#presentation>iframe').width(availableWidth);
  675. $('#presentation>iframe').height(availableWidth / aspectRatio);
  676. }
  677. if ($('#etherpad>iframe')) {
  678. $('#etherpad>iframe').width(availableWidth);
  679. $('#etherpad>iframe').height(availableWidth / aspectRatio);
  680. }
  681. resizeThumbnails();
  682. };
  683. function resizeThumbnails() {
  684. // Calculate the available height, which is the inner window height minus 39px for the header
  685. // minus 2px for the delimiter lines on the top and bottom of the large video,
  686. // minus the 36px space inside the remoteVideos container used for highlighting shadow.
  687. var availableHeight = window.innerHeight - $('#largeVideo').height() - 59;
  688. var numvids = $('#remoteVideos>span:visible').length;
  689. // Remove the 1px borders arround videos and the chat width.
  690. var availableWinWidth = $('#remoteVideos').width() - 2 * numvids - 50;
  691. var availableWidth = availableWinWidth / numvids;
  692. var aspectRatio = 16.0 / 9.0;
  693. var maxHeight = Math.min(160, availableHeight);
  694. availableHeight = Math.min(maxHeight, availableWidth / aspectRatio);
  695. if (availableHeight < availableWidth / aspectRatio) {
  696. availableWidth = Math.floor(availableHeight * aspectRatio);
  697. }
  698. // size videos so that while keeping AR and max height, we have a nice fit
  699. $('#remoteVideos').height(availableHeight);
  700. $('#remoteVideos>span').width(availableWidth);
  701. $('#remoteVideos>span').height(availableHeight);
  702. }
  703. $(document).ready(function () {
  704. Chat.init();
  705. // Set the defaults for prompt dialogs.
  706. jQuery.prompt.setDefaults({persistent: false});
  707. resizeLarge();
  708. $(window).resize(function () {
  709. resizeLarge();
  710. });
  711. if (!$('#settings').is(':visible')) {
  712. console.log('init');
  713. init();
  714. } else {
  715. loginInfo.onsubmit = function (e) {
  716. if (e.preventDefault) e.preventDefault();
  717. $('#settings').hide();
  718. init();
  719. };
  720. }
  721. });
  722. $(window).bind('beforeunload', function () {
  723. if (connection && connection.connected) {
  724. // ensure signout
  725. $.ajax({
  726. type: 'POST',
  727. url: config.bosh,
  728. async: false,
  729. cache: false,
  730. contentType: 'application/xml',
  731. 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>",
  732. success: function (data) {
  733. console.log('signed out');
  734. console.log(data);
  735. },
  736. error: function (XMLHttpRequest, textStatus, errorThrown) {
  737. console.log('signout error', textStatus + ' (' + errorThrown + ')');
  738. }
  739. });
  740. }
  741. });
  742. function dump(elem, filename){
  743. elem = elem.parentNode;
  744. elem.download = filename || 'meetlog.json';
  745. elem.href = 'data:application/json;charset=utf-8,\n';
  746. var data = {};
  747. if (connection.jingle) {
  748. Object.keys(connection.jingle.sessions).forEach(function (sid) {
  749. var session = connection.jingle.sessions[sid];
  750. if (session.peerconnection && session.peerconnection.updateLog) {
  751. // FIXME: should probably be a .dump call
  752. data["jingle_" + session.sid] = {
  753. updateLog: session.peerconnection.updateLog,
  754. stats: session.peerconnection.stats,
  755. url: window.location.href}
  756. ;
  757. }
  758. });
  759. }
  760. metadata = {};
  761. metadata.time = new Date();
  762. metadata.url = window.location.href;
  763. metadata.ua = navigator.userAgent;
  764. if (connection.logger) {
  765. metadata.xmpp = connection.logger.log;
  766. }
  767. data.metadata = metadata;
  768. elem.href += encodeURIComponent(JSON.stringify(data, null, ' '));
  769. return false;
  770. }
  771. /*
  772. * Changes the style class of the element given by id.
  773. */
  774. function buttonClick(id, classname) {
  775. $(id).toggleClass(classname); // add the class to the clicked element
  776. }
  777. /*
  778. * Opens the lock room dialog.
  779. */
  780. function openLockDialog() {
  781. // Only the focus is able to set a shared key.
  782. if (focus === null) {
  783. if (sharedKey)
  784. $.prompt("This conversation is currently protected by a shared secret key.",
  785. {
  786. title: "Secrect key",
  787. persistent: false
  788. });
  789. else
  790. $.prompt("This conversation isn't currently protected by a secret key. Only the owner of the conference could set a shared key.",
  791. {
  792. title: "Secrect key",
  793. persistent: false
  794. });
  795. }
  796. else {
  797. if (sharedKey)
  798. $.prompt("Are you sure you would like to remove your secret key?",
  799. {
  800. title: "Remove secrect key",
  801. persistent: false,
  802. buttons: { "Remove": true, "Cancel": false},
  803. defaultButton: 1,
  804. submit: function(e,v,m,f){
  805. if(v)
  806. {
  807. setSharedKey('');
  808. lockRoom(false);
  809. }
  810. }
  811. });
  812. else
  813. $.prompt('<h2>Set a secrect key to lock your room</h2>' +
  814. '<input id="lockKey" type="text" placeholder="your shared key" autofocus>',
  815. {
  816. persistent: false,
  817. buttons: { "Save": true , "Cancel": false},
  818. defaultButton: 1,
  819. loaded: function(event) {
  820. document.getElementById('lockKey').focus();
  821. },
  822. submit: function(e,v,m,f){
  823. if(v)
  824. {
  825. var lockKey = document.getElementById('lockKey');
  826. if (lockKey.value)
  827. {
  828. setSharedKey(Util.escapeHtml(lockKey.value));
  829. lockRoom(true);
  830. }
  831. }
  832. }
  833. });
  834. }
  835. }
  836. /*
  837. * Opens the invite link dialog.
  838. */
  839. function openLinkDialog() {
  840. $.prompt('<input id="inviteLinkRef" type="text" value="'
  841. + encodeURI(roomUrl) + '" onclick="this.select();" readonly>',
  842. {
  843. title: "Share this link with everyone you want to invite",
  844. persistent: false,
  845. buttons: { "Cancel": false},
  846. loaded: function(event) {
  847. document.getElementById('inviteLinkRef').select();
  848. }
  849. });
  850. }
  851. /*
  852. * Opens the settings dialog.
  853. */
  854. function openSettingsDialog() {
  855. $.prompt('<h2>Configure your conference</h2>' +
  856. '<input type="checkbox" id="initMuted"> Participants join muted<br/>' +
  857. '<input type="checkbox" id="requireNicknames"> Require nicknames<br/><br/>' +
  858. 'Set a secrect key to lock your room: <input id="lockKey" type="text" placeholder="your shared key" autofocus>',
  859. {
  860. persistent: false,
  861. buttons: { "Save": true , "Cancel": false},
  862. defaultButton: 1,
  863. loaded: function(event) {
  864. document.getElementById('lockKey').focus();
  865. },
  866. submit: function(e,v,m,f){
  867. if(v)
  868. {
  869. if ($('#initMuted').is(":checked"))
  870. {
  871. // it is checked
  872. }
  873. if ($('#requireNicknames').is(":checked"))
  874. {
  875. // it is checked
  876. }
  877. /*
  878. var lockKey = document.getElementById('lockKey');
  879. if (lockKey.value)
  880. {
  881. setSharedKey(lockKey.value);
  882. lockRoom(true);
  883. }
  884. */
  885. }
  886. }
  887. });
  888. }
  889. /*
  890. * Opens the Prezi dialog, from which the user could choose a presentation to load.
  891. */
  892. function openPreziDialog() {
  893. var myprezi = connection.emuc.getPrezi(connection.emuc.myroomjid);
  894. if (myprezi) {
  895. $.prompt("Are you sure you would like to remove your Prezi?",
  896. {
  897. title: "Remove Prezi",
  898. buttons: { "Remove": true, "Cancel": false},
  899. defaultButton: 1,
  900. submit: function(e,v,m,f){
  901. if(v)
  902. {
  903. connection.emuc.removePreziFromPresence();
  904. connection.emuc.sendPresence();
  905. }
  906. }
  907. });
  908. }
  909. else if (preziPlayer !== null) {
  910. $.prompt("Another participant is already sharing a Prezi." +
  911. "This conference allows only one Prezi at a time.",
  912. {
  913. title: "Share a Prezi",
  914. buttons: { "Ok": true},
  915. defaultButton: 0,
  916. submit: function(e,v,m,f){
  917. $.prompt.close();
  918. }
  919. });
  920. }
  921. else {
  922. var openPreziState = {
  923. state0: {
  924. html: '<h2>Share a Prezi</h2>' +
  925. '<input id="preziUrl" type="text" placeholder="e.g. http://prezi.com/wz7vhjycl7e6/my-prezi" autofocus>',
  926. persistent: false,
  927. buttons: { "Share": true , "Cancel": false},
  928. defaultButton: 1,
  929. submit: function(e,v,m,f){
  930. e.preventDefault();
  931. if(v)
  932. {
  933. var preziUrl = document.getElementById('preziUrl');
  934. if (preziUrl.value)
  935. {
  936. var urlValue
  937. = encodeURI(Util.escapeHtml(preziUrl.value));
  938. if (urlValue.indexOf('http://prezi.com/') !== 0
  939. && urlValue.indexOf('https://prezi.com/') !== 0)
  940. {
  941. $.prompt.goToState('state1');
  942. return false;
  943. }
  944. else {
  945. var presIdTmp = urlValue.substring(urlValue.indexOf("prezi.com/") + 10);
  946. if (!Util.isAlphanumeric(presIdTmp)
  947. || presIdTmp.indexOf('/') < 2) {
  948. $.prompt.goToState('state1');
  949. return false;
  950. }
  951. else {
  952. connection.emuc.addPreziToPresence(urlValue, 0);
  953. connection.emuc.sendPresence();
  954. $.prompt.close();
  955. }
  956. }
  957. }
  958. }
  959. else
  960. $.prompt.close();
  961. }
  962. },
  963. state1: {
  964. html: '<h2>Share a Prezi</h2>' +
  965. 'Please provide a correct prezi link.',
  966. persistent: false,
  967. buttons: { "Back": true, "Cancel": false },
  968. defaultButton: 1,
  969. submit:function(e,v,m,f) {
  970. e.preventDefault();
  971. if (v === 0)
  972. $.prompt.close();
  973. else
  974. $.prompt.goToState('state0');
  975. }
  976. }
  977. };
  978. var myPrompt = jQuery.prompt(openPreziState);
  979. myPrompt.on('impromptu:loaded', function(e) {
  980. document.getElementById('preziUrl').focus();
  981. });
  982. myPrompt.on('impromptu:statechanged', function(e) {
  983. document.getElementById('preziUrl').focus();
  984. });
  985. }
  986. }
  987. /*
  988. * Locks / unlocks the room.
  989. */
  990. function lockRoom(lock) {
  991. if (lock)
  992. connection.emuc.lockRoom(sharedKey);
  993. else
  994. connection.emuc.lockRoom('');
  995. updateLockButton();
  996. }
  997. /*
  998. * Sets the shared key.
  999. */
  1000. function setSharedKey(sKey) {
  1001. sharedKey = sKey;
  1002. }
  1003. /*
  1004. * Updates the lock button state.
  1005. */
  1006. function updateLockButton() {
  1007. buttonClick("#lockIcon", "fa fa-unlock fa-lg fa fa-lock fa-lg");
  1008. }
  1009. /*
  1010. * Shows the call main toolbar.
  1011. */
  1012. function showToolbar() {
  1013. $('#toolbar').css({visibility:"visible"});
  1014. if (focus !== null)
  1015. {
  1016. // TODO: Enable settings functionality. Need to uncomment the settings button in index.html.
  1017. // $('#settingsButton').css({visibility:"visible"});
  1018. }
  1019. }
  1020. /*
  1021. * Updates the room invite url.
  1022. */
  1023. function updateRoomUrl(newRoomUrl) {
  1024. roomUrl = newRoomUrl;
  1025. }
  1026. /*
  1027. * Warning to the user that the conference window is about to be closed.
  1028. */
  1029. function closePageWarning() {
  1030. if (focus !== null)
  1031. return "You are the owner of this conference call and you are about to end it.";
  1032. else
  1033. return "You are about to leave this conversation.";
  1034. }
  1035. /*
  1036. * Shows a visual indicator for the focus of the conference.
  1037. * Currently if we're not the owner of the conference we obtain the focus
  1038. * from the connection.jingle.sessions.
  1039. */
  1040. function showFocusIndicator() {
  1041. if (focus !== null) {
  1042. var indicatorSpan = $('#localVideoContainer .focusindicator');
  1043. if (indicatorSpan.children().length === 0)
  1044. {
  1045. createFocusIndicatorElement(indicatorSpan[0]);
  1046. }
  1047. }
  1048. else if (Object.keys(connection.jingle.sessions).length > 0) {
  1049. // If we're only a participant the focus will be the only session we have.
  1050. var session = connection.jingle.sessions[Object.keys(connection.jingle.sessions)[0]];
  1051. var focusId = 'participant_' + Strophe.getResourceFromJid(session.peerjid);
  1052. var focusContainer = document.getElementById(focusId);
  1053. var indicatorSpan = $('#' + focusId + ' .focusindicator');
  1054. if (!indicatorSpan || indicatorSpan.length === 0) {
  1055. indicatorSpan = document.createElement('span');
  1056. indicatorSpan.className = 'focusindicator';
  1057. focusContainer.appendChild(indicatorSpan);
  1058. createFocusIndicatorElement(indicatorSpan);
  1059. }
  1060. }
  1061. }
  1062. function addRemoteVideoContainer(id) {
  1063. var container = document.createElement('span');
  1064. container.id = id;
  1065. container.className = 'videocontainer';
  1066. var remotes = document.getElementById('remoteVideos');
  1067. remotes.appendChild(container);
  1068. return container;
  1069. }
  1070. /**
  1071. * Creates the element indicating the focus of the conference.
  1072. */
  1073. function createFocusIndicatorElement(parentElement) {
  1074. var focusIndicator = document.createElement('i');
  1075. focusIndicator.className = 'fa fa-star';
  1076. focusIndicator.title = "The owner of this conference";
  1077. parentElement.appendChild(focusIndicator);
  1078. }
  1079. /**
  1080. * Toggles the application in and out of full screen mode
  1081. * (a.k.a. presentation mode in Chrome).
  1082. */
  1083. function toggleFullScreen() {
  1084. var fsElement = document.documentElement;
  1085. if (!document.mozFullScreen && !document.webkitIsFullScreen){
  1086. //Enter Full Screen
  1087. if (fsElement.mozRequestFullScreen) {
  1088. fsElement.mozRequestFullScreen();
  1089. }
  1090. else {
  1091. fsElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
  1092. }
  1093. } else {
  1094. //Exit Full Screen
  1095. if (document.mozCancelFullScreen) {
  1096. document.mozCancelFullScreen();
  1097. } else {
  1098. document.webkitCancelFullScreen();
  1099. document.webkitCancelFullScreen();
  1100. }
  1101. }
  1102. }
  1103. /**
  1104. * Shows the display name for the given video.
  1105. */
  1106. function showDisplayName(videoSpanId, displayName) {
  1107. var escDisplayName = Util.escapeHtml(displayName);
  1108. var nameSpan = $('#' + videoSpanId + '>span.displayname');
  1109. // If we already have a display name for this video.
  1110. if (nameSpan.length > 0) {
  1111. var nameSpanElement = nameSpan.get(0);
  1112. if (nameSpanElement.id === 'localDisplayName'
  1113. && $('#localDisplayName').html() !== escDisplayName)
  1114. $('#localDisplayName').html(escDisplayName);
  1115. else
  1116. $('#' + videoSpanId + '_name').html(escDisplayName);
  1117. }
  1118. else {
  1119. var editButton = null;
  1120. if (videoSpanId === 'localVideoContainer') {
  1121. editButton = createEditDisplayNameButton();
  1122. }
  1123. if (escDisplayName.length) {
  1124. nameSpan = document.createElement('span');
  1125. nameSpan.className = 'displayname';
  1126. nameSpan.innerHTML = escDisplayName;
  1127. $('#' + videoSpanId)[0].appendChild(nameSpan);
  1128. }
  1129. if (!editButton) {
  1130. nameSpan.id = videoSpanId + '_name';
  1131. }
  1132. else {
  1133. nameSpan.id = 'localDisplayName';
  1134. $('#' + videoSpanId)[0].appendChild(editButton);
  1135. var editableText = document.createElement('input');
  1136. editableText.className = 'displayname';
  1137. editableText.id = 'editDisplayName';
  1138. if (escDisplayName.length)
  1139. editableText.value
  1140. = escDisplayName.substring(0, escDisplayName.indexOf(' (me)'));
  1141. editableText.setAttribute('style', 'display:none;');
  1142. editableText.setAttribute('placeholder', 'ex. Jane Pink');
  1143. $('#' + videoSpanId)[0].appendChild(editableText);
  1144. $('#localVideoContainer .displayname').bind("click", function(e) {
  1145. e.preventDefault();
  1146. $('#localDisplayName').hide();
  1147. $('#editDisplayName').show();
  1148. $('#editDisplayName').focus();
  1149. $('#editDisplayName').select();
  1150. var inputDisplayNameHandler = function(name) {
  1151. if (nickname !== name) {
  1152. nickname = Util.escapeHtml(name);
  1153. window.localStorage.displayname = nickname;
  1154. connection.emuc.addDisplayNameToPresence(nickname);
  1155. connection.emuc.sendPresence();
  1156. Chat.setChatConversationMode(true);
  1157. }
  1158. if (!$('#localDisplayName').is(":visible")) {
  1159. $('#localDisplayName').html(nickname + " (me)");
  1160. $('#localDisplayName').show();
  1161. $('#editDisplayName').hide();
  1162. }
  1163. };
  1164. $('#editDisplayName').one("focusout", function (e) {
  1165. inputDisplayNameHandler(this.value);
  1166. });
  1167. $('#editDisplayName').on('keydown', function (e) {
  1168. if (e.keyCode === 13) {
  1169. e.preventDefault();
  1170. inputDisplayNameHandler(this.value);
  1171. }
  1172. });
  1173. });
  1174. }
  1175. }
  1176. }
  1177. function createEditDisplayNameButton() {
  1178. var editButton = document.createElement('a');
  1179. editButton.className = 'displayname';
  1180. editButton.innerHTML = '<i class="fa fa-pencil"></i>';
  1181. return editButton;
  1182. }