Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

app.js 48KB

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