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

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