You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UI.js 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  1. /*
  2. * Copyright @ 2015 Atlassian Pty Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. var UI = {};
  17. var VideoLayout = require("./videolayout/VideoLayout.js");
  18. var AudioLevels = require("./audio_levels/AudioLevels.js");
  19. var Prezi = require("./prezi/Prezi.js");
  20. var Etherpad = require("./etherpad/Etherpad.js");
  21. var Chat = require("./side_pannels/chat/Chat.js");
  22. var Toolbar = require("./toolbars/Toolbar");
  23. var ToolbarToggler = require("./toolbars/ToolbarToggler");
  24. var BottomToolbar = require("./toolbars/BottomToolbar");
  25. var ContactList = require("./side_pannels/contactlist/ContactList");
  26. var Avatar = require("./avatar/Avatar");
  27. var EventEmitter = require("events");
  28. var SettingsMenu = require("./side_pannels/settings/SettingsMenu");
  29. var Settings = require("./../settings/Settings");
  30. var PanelToggler = require("./side_pannels/SidePanelToggler");
  31. var RoomNameGenerator = require("./welcome_page/RoomnameGenerator");
  32. UI.messageHandler = require("./util/MessageHandler");
  33. var messageHandler = UI.messageHandler;
  34. var Authentication = require("./authentication/Authentication");
  35. var UIUtil = require("./util/UIUtil");
  36. var NicknameHandler = require("./util/NicknameHandler");
  37. var CQEvents = require("../../service/connectionquality/CQEvents");
  38. var DesktopSharingEventTypes
  39. = require("../../service/desktopsharing/DesktopSharingEventTypes");
  40. var RTCEvents = require("../../service/RTC/RTCEvents");
  41. var StreamEventTypes = require("../../service/RTC/StreamEventTypes");
  42. var XMPPEvents = require("../../service/xmpp/XMPPEvents");
  43. var MemberEvents = require("../../service/members/Events");
  44. var eventEmitter = new EventEmitter();
  45. var roomName = null;
  46. function notifyForInitialMute()
  47. {
  48. messageHandler.notify(null, "notify.mutedTitle", "connected",
  49. "notify.muted", null, {timeOut: 120000});
  50. }
  51. function setupPrezi()
  52. {
  53. $("#reloadPresentationLink").click(function()
  54. {
  55. Prezi.reloadPresentation();
  56. });
  57. }
  58. function setupChat()
  59. {
  60. Chat.init();
  61. $("#toggle_smileys").click(function() {
  62. Chat.toggleSmileys();
  63. });
  64. }
  65. function setupToolbars() {
  66. Toolbar.init(UI);
  67. Toolbar.setupButtonsFromConfig();
  68. BottomToolbar.init();
  69. }
  70. function streamHandler(stream, isMuted) {
  71. switch (stream.type)
  72. {
  73. case "audio":
  74. VideoLayout.changeLocalAudio(stream, isMuted);
  75. break;
  76. case "video":
  77. VideoLayout.changeLocalVideo(stream, isMuted);
  78. break;
  79. case "stream":
  80. VideoLayout.changeLocalStream(stream, isMuted);
  81. break;
  82. }
  83. }
  84. function onXmppConnectionFailed(stropheErrorMsg) {
  85. var title = APP.translation.generateTranslatonHTML(
  86. "dialog.error");
  87. var message;
  88. if (stropheErrorMsg) {
  89. message = APP.translation.generateTranslatonHTML(
  90. "dialog.connectErrorWithMsg", {msg: stropheErrorMsg});
  91. } else {
  92. message = APP.translation.generateTranslatonHTML(
  93. "dialog.connectError");
  94. }
  95. messageHandler.openDialog(
  96. title, message, true, {}, function (e, v, m, f) { return false; });
  97. }
  98. function onDisposeConference(unload) {
  99. Toolbar.showAuthenticateButton(false);
  100. }
  101. function onDisplayNameChanged(jid, displayName) {
  102. ContactList.onDisplayNameChange(jid, displayName);
  103. SettingsMenu.onDisplayNameChange(jid, displayName);
  104. VideoLayout.onDisplayNameChanged(jid, displayName);
  105. }
  106. function registerListeners() {
  107. APP.RTC.addStreamListener(streamHandler, StreamEventTypes.EVENT_TYPE_LOCAL_CREATED);
  108. APP.RTC.addStreamListener(streamHandler, StreamEventTypes.EVENT_TYPE_LOCAL_CHANGED);
  109. APP.RTC.addStreamListener(function (stream) {
  110. VideoLayout.onRemoteStreamAdded(stream);
  111. }, StreamEventTypes.EVENT_TYPE_REMOTE_CREATED);
  112. APP.RTC.addStreamListener(function (jid) {
  113. VideoLayout.onVideoTypeChanged(jid);
  114. }, StreamEventTypes.EVENT_TYPE_REMOTE_CHANGED);
  115. APP.RTC.addListener(RTCEvents.LASTN_CHANGED, onLastNChanged);
  116. APP.RTC.addListener(RTCEvents.DOMINANTSPEAKER_CHANGED, function (resourceJid) {
  117. VideoLayout.onDominantSpeakerChanged(resourceJid);
  118. });
  119. APP.RTC.addListener(RTCEvents.LASTN_ENDPOINT_CHANGED,
  120. function (lastNEndpoints, endpointsEnteringLastN, stream) {
  121. VideoLayout.onLastNEndpointsChanged(lastNEndpoints,
  122. endpointsEnteringLastN, stream);
  123. });
  124. APP.RTC.addListener(RTCEvents.AVAILABLE_DEVICES_CHANGED,
  125. function (devices) {
  126. VideoLayout.setDeviceAvailabilityIcons(null, devices);
  127. })
  128. APP.statistics.addAudioLevelListener(function(jid, audioLevel)
  129. {
  130. var resourceJid;
  131. if(jid === APP.statistics.LOCAL_JID)
  132. {
  133. resourceJid = AudioLevels.LOCAL_LEVEL;
  134. if(APP.RTC.localAudio.isMuted())
  135. {
  136. audioLevel = 0;
  137. }
  138. }
  139. else
  140. {
  141. resourceJid = Strophe.getResourceFromJid(jid);
  142. }
  143. AudioLevels.updateAudioLevel(resourceJid, audioLevel,
  144. UI.getLargeVideoState().userResourceJid);
  145. });
  146. APP.desktopsharing.addListener(function () {
  147. ToolbarToggler.showDesktopSharingButton();
  148. }, DesktopSharingEventTypes.INIT);
  149. APP.desktopsharing.addListener(
  150. Toolbar.changeDesktopSharingButtonState,
  151. DesktopSharingEventTypes.SWITCHING_DONE);
  152. APP.connectionquality.addListener(CQEvents.LOCALSTATS_UPDATED,
  153. VideoLayout.updateLocalConnectionStats);
  154. APP.connectionquality.addListener(CQEvents.REMOTESTATS_UPDATED,
  155. VideoLayout.updateConnectionStats);
  156. APP.connectionquality.addListener(CQEvents.STOP,
  157. VideoLayout.onStatsStop);
  158. APP.xmpp.addListener(XMPPEvents.CONNECTION_FAILED, onXmppConnectionFailed);
  159. APP.xmpp.addListener(XMPPEvents.DISPOSE_CONFERENCE, onDisposeConference);
  160. APP.xmpp.addListener(XMPPEvents.GRACEFUL_SHUTDOWN, function () {
  161. messageHandler.openMessageDialog(
  162. 'dialog.serviceUnavailable',
  163. 'dialog.gracefulShutdown'
  164. );
  165. });
  166. APP.xmpp.addListener(XMPPEvents.RESERVATION_ERROR, function (code, msg) {
  167. var title = APP.translation.generateTranslatonHTML(
  168. "dialog.reservationError");
  169. var message = APP.translation.generateTranslatonHTML(
  170. "dialog.reservationErrorMsg", {code: code, msg: msg});
  171. messageHandler.openDialog(
  172. title,
  173. message,
  174. true, {},
  175. function (event, value, message, formVals)
  176. {
  177. return false;
  178. }
  179. );
  180. });
  181. APP.xmpp.addListener(XMPPEvents.KICKED, function () {
  182. messageHandler.openMessageDialog("dialog.sessTerminated",
  183. "dialog.kickMessage");
  184. });
  185. APP.xmpp.addListener(XMPPEvents.MUC_DESTROYED, function (reason) {
  186. //FIXME: use Session Terminated from translation, but
  187. // 'reason' text comes from XMPP packet and is not translated
  188. var title = APP.translation.generateTranslatonHTML("dialog.sessTerminated");
  189. messageHandler.openDialog(
  190. title, reason, true, {},
  191. function (event, value, message, formVals)
  192. {
  193. return false;
  194. }
  195. );
  196. });
  197. APP.xmpp.addListener(XMPPEvents.BRIDGE_DOWN, function () {
  198. messageHandler.showError("dialog.error",
  199. "dialog.bridgeUnavailable");
  200. });
  201. APP.xmpp.addListener(XMPPEvents.USER_ID_CHANGED, function (from, id) {
  202. Avatar.setUserAvatar(from, id);
  203. });
  204. APP.xmpp.addListener(XMPPEvents.STREAMS_CHANGED, function (jid, changedStreams) {
  205. for(stream in changedStreams)
  206. {
  207. // might need to update the direction if participant just went from sendrecv to recvonly
  208. if (stream.type === 'video' || stream.type === 'screen') {
  209. var el = $('#participant_' + Strophe.getResourceFromJid(jid) + '>video');
  210. switch (stream.direction) {
  211. case 'sendrecv':
  212. el.show();
  213. break;
  214. case 'recvonly':
  215. el.hide();
  216. // FIXME: Check if we have to change large video
  217. //VideoLayout.updateLargeVideo(el);
  218. break;
  219. }
  220. }
  221. }
  222. });
  223. APP.xmpp.addListener(XMPPEvents.DISPLAY_NAME_CHANGED, onDisplayNameChanged);
  224. APP.xmpp.addListener(XMPPEvents.MUC_JOINED, onMucJoined);
  225. APP.xmpp.addListener(XMPPEvents.LOCAL_ROLE_CHANGED, onLocalRoleChanged);
  226. APP.xmpp.addListener(XMPPEvents.MUC_MEMBER_JOINED, onMucMemberJoined);
  227. APP.xmpp.addListener(XMPPEvents.MUC_ROLE_CHANGED, onMucRoleChanged);
  228. APP.xmpp.addListener(XMPPEvents.PRESENCE_STATUS, onMucPresenceStatus);
  229. APP.xmpp.addListener(XMPPEvents.SUBJECT_CHANGED, chatSetSubject);
  230. APP.xmpp.addListener(XMPPEvents.MESSAGE_RECEIVED, updateChatConversation);
  231. APP.xmpp.addListener(XMPPEvents.MUC_MEMBER_LEFT, onMucMemberLeft);
  232. APP.xmpp.addListener(XMPPEvents.PASSWORD_REQUIRED, onPasswordRequired);
  233. APP.xmpp.addListener(XMPPEvents.CHAT_ERROR_RECEIVED, chatAddError);
  234. APP.xmpp.addListener(XMPPEvents.ETHERPAD, initEtherpad);
  235. APP.xmpp.addListener(XMPPEvents.AUTHENTICATION_REQUIRED,
  236. onAuthenticationRequired);
  237. APP.xmpp.addListener(XMPPEvents.DEVICE_AVAILABLE,
  238. function (resource, devices) {
  239. VideoLayout.setDeviceAvailabilityIcons(resource, devices);
  240. });
  241. APP.members.addListener(MemberEvents.DTMF_SUPPORT_CHANGED,
  242. onDtmfSupportChanged);
  243. APP.xmpp.addListener(XMPPEvents.START_MUTED, function (audio, video) {
  244. SettingsMenu.setStartMuted(audio, video);
  245. });
  246. }
  247. /**
  248. * Mutes/unmutes the local video.
  249. *
  250. * @param mute <tt>true</tt> to mute the local video; otherwise, <tt>false</tt>
  251. * @param options an object which specifies optional arguments such as the
  252. * <tt>boolean</tt> key <tt>byUser</tt> with default value <tt>true</tt> which
  253. * specifies whether the method was initiated in response to a user command (in
  254. * contrast to an automatic decision taken by the application logic)
  255. */
  256. function setVideoMute(mute, options) {
  257. APP.RTC.setVideoMute(mute,
  258. UI.setVideoMuteButtonsState,
  259. options);
  260. }
  261. function bindEvents()
  262. {
  263. /**
  264. * Resizes and repositions videos in full screen mode.
  265. */
  266. $(document).on('webkitfullscreenchange mozfullscreenchange fullscreenchange',
  267. function () {
  268. VideoLayout.resizeLargeVideoContainer();
  269. VideoLayout.positionLarge();
  270. }
  271. );
  272. $(window).resize(function () {
  273. VideoLayout.resizeLargeVideoContainer();
  274. VideoLayout.positionLarge();
  275. });
  276. }
  277. UI.start = function (init) {
  278. document.title = interfaceConfig.APP_NAME;
  279. if(config.enableWelcomePage && window.location.pathname == "/" &&
  280. (!window.localStorage.welcomePageDisabled || window.localStorage.welcomePageDisabled == "false"))
  281. {
  282. $("#videoconference_page").hide();
  283. var setupWelcomePage = require("./welcome_page/WelcomePage");
  284. setupWelcomePage();
  285. return;
  286. }
  287. if (interfaceConfig.SHOW_JITSI_WATERMARK) {
  288. var leftWatermarkDiv
  289. = $("#largeVideoContainer div[class='watermark leftwatermark']");
  290. leftWatermarkDiv.css({display: 'block'});
  291. leftWatermarkDiv.parent().get(0).href
  292. = interfaceConfig.JITSI_WATERMARK_LINK;
  293. }
  294. if (interfaceConfig.SHOW_BRAND_WATERMARK) {
  295. var rightWatermarkDiv
  296. = $("#largeVideoContainer div[class='watermark rightwatermark']");
  297. rightWatermarkDiv.css({display: 'block'});
  298. rightWatermarkDiv.parent().get(0).href
  299. = interfaceConfig.BRAND_WATERMARK_LINK;
  300. rightWatermarkDiv.get(0).style.backgroundImage
  301. = "url(images/rightwatermark.png)";
  302. }
  303. if (interfaceConfig.SHOW_POWERED_BY) {
  304. $("#largeVideoContainer>a[class='poweredby']").css({display: 'block'});
  305. }
  306. $("#welcome_page").hide();
  307. VideoLayout.resizeLargeVideoContainer();
  308. $("#videospace").mousemove(function () {
  309. return ToolbarToggler.showToolbar();
  310. });
  311. // Set the defaults for prompt dialogs.
  312. jQuery.prompt.setDefaults({persistent: false});
  313. VideoLayout.init(eventEmitter);
  314. AudioLevels.init();
  315. NicknameHandler.init(eventEmitter);
  316. registerListeners();
  317. bindEvents();
  318. setupPrezi();
  319. setupToolbars();
  320. setupChat();
  321. document.title = interfaceConfig.APP_NAME;
  322. $("#downloadlog").click(function (event) {
  323. dump(event.target);
  324. });
  325. if(config.enableWelcomePage && window.location.pathname == "/" &&
  326. (!window.localStorage.welcomePageDisabled || window.localStorage.welcomePageDisabled == "false"))
  327. {
  328. $("#videoconference_page").hide();
  329. var setupWelcomePage = require("./welcome_page/WelcomePage");
  330. setupWelcomePage();
  331. return;
  332. }
  333. $("#welcome_page").hide();
  334. // Display notice message at the top of the toolbar
  335. if (config.noticeMessage) {
  336. $('#noticeText').text(config.noticeMessage);
  337. $('#notice').css({display: 'block'});
  338. }
  339. document.getElementById('largeVideo').volume = 0;
  340. if (!$('#settings').is(':visible')) {
  341. console.log('init');
  342. init();
  343. } else {
  344. loginInfo.onsubmit = function (e) {
  345. if (e.preventDefault) e.preventDefault();
  346. $('#settings').hide();
  347. init();
  348. };
  349. }
  350. toastr.options = {
  351. "closeButton": true,
  352. "debug": false,
  353. "positionClass": "notification-bottom-right",
  354. "onclick": null,
  355. "showDuration": "300",
  356. "hideDuration": "1000",
  357. "timeOut": "2000",
  358. "extendedTimeOut": "1000",
  359. "showEasing": "swing",
  360. "hideEasing": "linear",
  361. "showMethod": "fadeIn",
  362. "hideMethod": "fadeOut",
  363. "reposition": function() {
  364. if(PanelToggler.isVisible()) {
  365. $("#toast-container").addClass("notification-bottom-right-center");
  366. } else {
  367. $("#toast-container").removeClass("notification-bottom-right-center");
  368. }
  369. },
  370. "newestOnTop": false
  371. };
  372. SettingsMenu.init();
  373. };
  374. function chatAddError(errorMessage, originalText)
  375. {
  376. return Chat.chatAddError(errorMessage, originalText);
  377. };
  378. function chatSetSubject(text)
  379. {
  380. return Chat.chatSetSubject(text);
  381. };
  382. function updateChatConversation(from, displayName, message) {
  383. return Chat.updateChatConversation(from, displayName, message);
  384. };
  385. function onMucJoined(jid, info) {
  386. Toolbar.updateRoomUrl(window.location.href);
  387. var meHTML = APP.translation.generateTranslatonHTML("me");
  388. $("#localNick").html(Strophe.getResourceFromJid(jid) + " (" + meHTML + ")");
  389. var settings = Settings.getSettings();
  390. // Add myself to the contact list.
  391. ContactList.addContact(jid, settings.email || settings.uid);
  392. // Once we've joined the muc show the toolbar
  393. ToolbarToggler.showToolbar();
  394. var displayName = !config.displayJids
  395. ? info.displayName : Strophe.getResourceFromJid(jid);
  396. if (displayName)
  397. onDisplayNameChanged('localVideoContainer', displayName);
  398. VideoLayout.mucJoined();
  399. }
  400. function initEtherpad(name) {
  401. Etherpad.init(name);
  402. }
  403. function onMucMemberLeft(jid) {
  404. console.log('left.muc', jid);
  405. var displayName = $('#participant_' + Strophe.getResourceFromJid(jid) +
  406. '>.displayname').html();
  407. messageHandler.notify(displayName,'notify.somebody',
  408. 'disconnected',
  409. 'notify.disconnected');
  410. if(!config.startAudioMuted ||
  411. config.startAudioMuted > APP.members.size())
  412. UIUtil.playSoundNotification('userLeft');
  413. // Need to call this with a slight delay, otherwise the element couldn't be
  414. // found for some reason.
  415. // XXX(gp) it works fine without the timeout for me (with Chrome 38).
  416. window.setTimeout(function () {
  417. var container = document.getElementById(
  418. 'participant_' + Strophe.getResourceFromJid(jid));
  419. if (container) {
  420. ContactList.removeContact(jid);
  421. VideoLayout.removeConnectionIndicator(jid);
  422. // hide here, wait for video to close before removing
  423. $(container).hide();
  424. VideoLayout.resizeThumbnails();
  425. }
  426. }, 10);
  427. VideoLayout.participantLeft(jid);
  428. };
  429. function onLocalRoleChanged(jid, info, pres, isModerator)
  430. {
  431. console.info("My role changed, new role: " + info.role);
  432. onModeratorStatusChanged(isModerator);
  433. VideoLayout.showModeratorIndicator();
  434. SettingsMenu.onRoleChanged();
  435. if (isModerator) {
  436. Authentication.closeAuthenticationWindow();
  437. messageHandler.notify(null, "notify.me",
  438. 'connected', "notify.moderator");
  439. }
  440. }
  441. function onModeratorStatusChanged(isModerator) {
  442. Toolbar.showSipCallButton(isModerator);
  443. Toolbar.showRecordingButton(
  444. isModerator); //&&
  445. // FIXME:
  446. // Recording visible if
  447. // there are at least 2(+ 1 focus) participants
  448. //Object.keys(connection.emuc.members).length >= 3);
  449. }
  450. function onPasswordRequired(callback) {
  451. // password is required
  452. Toolbar.lockLockButton();
  453. var message = '<h2 data-i18n="dialog.passwordRequired">';
  454. message += APP.translation.translateString(
  455. "dialog.passwordRequired");
  456. message += '</h2>' +
  457. '<input name="lockKey" type="text" data-i18n=' +
  458. '"[placeholder]dialog.password" placeholder="' +
  459. APP.translation.translateString("dialog.password") +
  460. '" autofocus>';
  461. messageHandler.openTwoButtonDialog(null, null, null, message,
  462. true,
  463. "dialog.Ok",
  464. function (e, v, m, f) {},
  465. null,
  466. function (e, v, m, f) {
  467. if (v) {
  468. var lockKey = f.lockKey;
  469. if (lockKey) {
  470. Toolbar.setSharedKey(lockKey);
  471. callback(lockKey);
  472. }
  473. }
  474. },
  475. ':input:first'
  476. );
  477. }
  478. /**
  479. * The dialpad button is shown iff there is at least one member that supports
  480. * DTMF (e.g. jigasi).
  481. */
  482. function onDtmfSupportChanged(dtmfSupport) {
  483. //TODO: enable when the UI is ready
  484. //Toolbar.showDialPadButton(dtmfSupport);
  485. }
  486. function onMucMemberJoined(jid, id, displayName) {
  487. messageHandler.notify(displayName,'notify.somebody',
  488. 'connected',
  489. 'notify.connected');
  490. if(!config.startAudioMuted ||
  491. config.startAudioMuted > APP.members.size())
  492. UIUtil.playSoundNotification('userJoined');
  493. // Add Peer's container
  494. VideoLayout.ensurePeerContainerExists(jid,id);
  495. }
  496. function onMucPresenceStatus( jid, info) {
  497. VideoLayout.setPresenceStatus(
  498. 'participant_' + Strophe.getResourceFromJid(jid), info.status);
  499. }
  500. function onMucRoleChanged(role, displayName) {
  501. VideoLayout.showModeratorIndicator();
  502. if (role === 'moderator') {
  503. var messageKey, messageOptions = {};
  504. if (!displayName) {
  505. messageKey = "notify.grantedToUnknown";
  506. }
  507. else
  508. {
  509. messageKey = "notify.grantedTo";
  510. messageOptions = {to: displayName};
  511. }
  512. messageHandler.notify(
  513. displayName,'notify.somebody',
  514. 'connected', messageKey,
  515. messageOptions);
  516. }
  517. }
  518. function onAuthenticationRequired(intervalCallback) {
  519. Authentication.openAuthenticationDialog(
  520. roomName, intervalCallback, function () {
  521. Toolbar.authenticateClicked();
  522. });
  523. };
  524. function onLastNChanged(oldValue, newValue) {
  525. if (config.muteLocalVideoIfNotInLastN) {
  526. setVideoMute(!newValue, { 'byUser': false });
  527. }
  528. }
  529. UI.toggleSmileys = function () {
  530. Chat.toggleSmileys();
  531. };
  532. UI.getSettings = function () {
  533. return Settings.getSettings();
  534. };
  535. UI.toggleFilmStrip = function () {
  536. return BottomToolbar.toggleFilmStrip();
  537. };
  538. UI.toggleChat = function () {
  539. return BottomToolbar.toggleChat();
  540. };
  541. UI.toggleContactList = function () {
  542. return BottomToolbar.toggleContactList();
  543. };
  544. UI.inputDisplayNameHandler = function (value) {
  545. VideoLayout.inputDisplayNameHandler(value);
  546. };
  547. UI.getLargeVideoState = function()
  548. {
  549. return VideoLayout.getLargeVideoState();
  550. };
  551. UI.generateRoomName = function() {
  552. if(roomName)
  553. return roomName;
  554. var roomnode = null;
  555. var path = window.location.pathname;
  556. // determinde the room node from the url
  557. // TODO: just the roomnode or the whole bare jid?
  558. if (config.getroomnode && typeof config.getroomnode === 'function') {
  559. // custom function might be responsible for doing the pushstate
  560. roomnode = config.getroomnode(path);
  561. } else {
  562. /* fall back to default strategy
  563. * this is making assumptions about how the URL->room mapping happens.
  564. * It currently assumes deployment at root, with a rewrite like the
  565. * following one (for nginx):
  566. location ~ ^/([a-zA-Z0-9]+)$ {
  567. rewrite ^/(.*)$ / break;
  568. }
  569. */
  570. if (path.length > 1) {
  571. roomnode = path.substr(1).toLowerCase();
  572. } else {
  573. var word = RoomNameGenerator.generateRoomWithoutSeparator();
  574. roomnode = word.toLowerCase();
  575. window.history.pushState('VideoChat',
  576. 'Room: ' + word, window.location.pathname + word);
  577. }
  578. }
  579. roomName = roomnode + '@' + config.hosts.muc;
  580. return roomName;
  581. };
  582. UI.connectionIndicatorShowMore = function(id)
  583. {
  584. return VideoLayout.connectionIndicators[id].showMore();
  585. };
  586. UI.showLoginPopup = function(callback)
  587. {
  588. console.log('password is required');
  589. var message = '<h2 data-i18n="dialog.passwordRequired">';
  590. message += APP.translation.translateString(
  591. "dialog.passwordRequired");
  592. message += '</h2>' +
  593. '<input name="username" type="text" ' +
  594. 'placeholder="user@domain.net" autofocus>' +
  595. '<input name="password" ' +
  596. 'type="password" data-i18n="[placeholder]dialog.userPassword"' +
  597. ' placeholder="user password">';
  598. UI.messageHandler.openTwoButtonDialog(null, null, null, message,
  599. true,
  600. "dialog.Ok",
  601. function (e, v, m, f) {
  602. if (v) {
  603. if (f.username !== null && f.password != null) {
  604. callback(f.username, f.password);
  605. }
  606. }
  607. },
  608. null, null, ':input:first'
  609. );
  610. }
  611. UI.checkForNicknameAndJoin = function () {
  612. Authentication.closeAuthenticationDialog();
  613. Authentication.stopInterval();
  614. var nick = null;
  615. if (config.useNicks) {
  616. nick = window.prompt('Your nickname (optional)');
  617. }
  618. APP.xmpp.joinRoom(roomName, config.useNicks, nick);
  619. };
  620. function dump(elem, filename) {
  621. elem = elem.parentNode;
  622. elem.download = filename || 'meetlog.json';
  623. elem.href = 'data:application/json;charset=utf-8,\n';
  624. var data = APP.xmpp.populateData();
  625. var metadata = {};
  626. metadata.time = new Date();
  627. metadata.url = window.location.href;
  628. metadata.ua = navigator.userAgent;
  629. var log = APP.xmpp.getLogger();
  630. if (log) {
  631. metadata.xmpp = log;
  632. }
  633. data.metadata = metadata;
  634. elem.href += encodeURIComponent(JSON.stringify(data, null, ' '));
  635. return false;
  636. }
  637. UI.getRoomName = function () {
  638. return roomName;
  639. };
  640. UI.setInitialMuteFromFocus = function (muteAudio, muteVideo) {
  641. if(muteAudio || muteVideo) notifyForInitialMute();
  642. if(muteAudio) UI.setAudioMuted(true);
  643. if(muteVideo) UI.setVideoMute(true);
  644. }
  645. /**
  646. * Mutes/unmutes the local video.
  647. */
  648. UI.toggleVideo = function () {
  649. setVideoMute(!APP.RTC.localVideo.isMuted());
  650. };
  651. /**
  652. * Mutes / unmutes audio for the local participant.
  653. */
  654. UI.toggleAudio = function() {
  655. UI.setAudioMuted(!APP.RTC.localAudio.isMuted());
  656. };
  657. /**
  658. * Sets muted audio state for the local participant.
  659. */
  660. UI.setAudioMuted = function (mute, earlyMute) {
  661. var audioMute = null;
  662. if(earlyMute)
  663. audioMute = function (mute, cb) {
  664. return APP.xmpp.sendAudioInfoPresence(mute, cb);
  665. };
  666. else
  667. audioMute = function (mute, cb) {
  668. return APP.xmpp.setAudioMute(mute, cb);
  669. }
  670. if(!audioMute(mute, function () {
  671. VideoLayout.showLocalAudioIndicator(mute);
  672. UIUtil.buttonClick("#mute", "icon-microphone icon-mic-disabled");
  673. }))
  674. {
  675. // We still click the button.
  676. UIUtil.buttonClick("#mute", "icon-microphone icon-mic-disabled");
  677. return;
  678. }
  679. }
  680. UI.addListener = function (type, listener) {
  681. eventEmitter.on(type, listener);
  682. }
  683. UI.clickOnVideo = function (videoNumber) {
  684. var remoteVideos = $(".videocontainer:not(#mixedstream)");
  685. if (remoteVideos.length > videoNumber) {
  686. remoteVideos[videoNumber].click();
  687. }
  688. }
  689. //Used by torture
  690. UI.showToolbar = function () {
  691. return ToolbarToggler.showToolbar();
  692. }
  693. //Used by torture
  694. UI.dockToolbar = function (isDock) {
  695. return ToolbarToggler.dockToolbar(isDock);
  696. }
  697. UI.setVideoMuteButtonsState = function (mute) {
  698. var video = $('#video');
  699. var communicativeClass = "icon-camera";
  700. var muteClass = "icon-camera icon-camera-disabled";
  701. if (mute) {
  702. video.removeClass(communicativeClass);
  703. video.addClass(muteClass);
  704. } else {
  705. video.removeClass(muteClass);
  706. video.addClass(communicativeClass);
  707. }
  708. }
  709. UI.setVideoMute = setVideoMute;
  710. module.exports = UI;