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.

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