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

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