Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

UI.js 28KB

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