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

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