Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

UI.js 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  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 (!interfaceConfig.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 (!interfaceConfig.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 (!interfaceConfig.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. Toolbar.checkAutoRecord();
  475. }
  476. }
  477. function onModeratorStatusChanged(isModerator) {
  478. Toolbar.showSipCallButton(isModerator);
  479. Toolbar.showRecordingButton(
  480. isModerator); //&&
  481. // FIXME:
  482. // Recording visible if
  483. // there are at least 2(+ 1 focus) participants
  484. //Object.keys(connection.emuc.members).length >= 3);
  485. }
  486. function onPasswordRequired(callback) {
  487. // password is required
  488. Toolbar.lockLockButton();
  489. var message = '<h2 data-i18n="dialog.passwordRequired">';
  490. message += APP.translation.translateString(
  491. "dialog.passwordRequired");
  492. message += '</h2>' +
  493. '<input name="lockKey" type="text" data-i18n=' +
  494. '"[placeholder]dialog.password" placeholder="' +
  495. APP.translation.translateString("dialog.password") +
  496. '" autofocus>';
  497. messageHandler.openTwoButtonDialog(null, null, null, message,
  498. true,
  499. "dialog.Ok",
  500. function (e, v, m, f) {},
  501. null,
  502. function (e, v, m, f) {
  503. if (v) {
  504. var lockKey = f.lockKey;
  505. if (lockKey) {
  506. Toolbar.setSharedKey(lockKey);
  507. callback(lockKey);
  508. }
  509. }
  510. },
  511. ':input:first'
  512. );
  513. }
  514. /**
  515. * The dialpad button is shown iff there is at least one member that supports
  516. * DTMF (e.g. jigasi).
  517. */
  518. function onDtmfSupportChanged(dtmfSupport) {
  519. //TODO: enable when the UI is ready
  520. //Toolbar.showDialPadButton(dtmfSupport);
  521. }
  522. function onMucMemberJoined(jid, id, displayName) {
  523. messageHandler.notify(displayName,'notify.somebody',
  524. 'connected',
  525. 'notify.connected');
  526. if (!config.startAudioMuted ||
  527. config.startAudioMuted > APP.members.size())
  528. UIUtil.playSoundNotification('userJoined');
  529. // Configure avatar
  530. Avatar.setUserAvatar(jid, id);
  531. // Add Peer's container
  532. VideoLayout.ensurePeerContainerExists(jid);
  533. }
  534. function onMucPresenceStatus(jid, info) {
  535. VideoLayout.setPresenceStatus(Strophe.getResourceFromJid(jid), info.status);
  536. }
  537. function onPeerVideoTypeChanged(resourceJid, newVideoType) {
  538. VideoLayout.onVideoTypeChanged(resourceJid, newVideoType);
  539. }
  540. function onMucRoleChanged(role, displayName) {
  541. VideoLayout.showModeratorIndicator();
  542. if (role === 'moderator') {
  543. var messageKey, messageOptions = {};
  544. if (!displayName) {
  545. messageKey = "notify.grantedToUnknown";
  546. }
  547. else {
  548. messageKey = "notify.grantedTo";
  549. messageOptions = {to: displayName};
  550. }
  551. messageHandler.notify(
  552. displayName,'notify.somebody',
  553. 'connected', messageKey,
  554. messageOptions);
  555. }
  556. }
  557. function onAuthenticationRequired(intervalCallback) {
  558. Authentication.openAuthenticationDialog(
  559. roomName, intervalCallback, function () {
  560. Toolbar.authenticateClicked();
  561. });
  562. }
  563. function onLastNChanged(oldValue, newValue) {
  564. if (config.muteLocalVideoIfNotInLastN) {
  565. setVideoMute(!newValue, { 'byUser': false });
  566. }
  567. }
  568. UI.toggleSmileys = function () {
  569. Chat.toggleSmileys();
  570. };
  571. UI.getSettings = function () {
  572. return Settings.getSettings();
  573. };
  574. UI.toggleFilmStrip = function () {
  575. return BottomToolbar.toggleFilmStrip();
  576. };
  577. UI.toggleChat = function () {
  578. return BottomToolbar.toggleChat();
  579. };
  580. UI.toggleContactList = function () {
  581. return BottomToolbar.toggleContactList();
  582. };
  583. UI.inputDisplayNameHandler = function (value) {
  584. VideoLayout.inputDisplayNameHandler(value);
  585. };
  586. UI.getLargeVideoJid = function() {
  587. return VideoLayout.getLargeVideoJid();
  588. };
  589. UI.generateRoomName = function() {
  590. if(roomName)
  591. return roomName;
  592. var roomnode = null;
  593. var path = window.location.pathname;
  594. // determinde the room node from the url
  595. // TODO: just the roomnode or the whole bare jid?
  596. if (config.getroomnode && typeof config.getroomnode === 'function') {
  597. // custom function might be responsible for doing the pushstate
  598. roomnode = config.getroomnode(path);
  599. } else {
  600. /* fall back to default strategy
  601. * this is making assumptions about how the URL->room mapping happens.
  602. * It currently assumes deployment at root, with a rewrite like the
  603. * following one (for nginx):
  604. location ~ ^/([a-zA-Z0-9]+)$ {
  605. rewrite ^/(.*)$ / break;
  606. }
  607. */
  608. if (path.length > 1) {
  609. roomnode = path.substr(1).toLowerCase();
  610. } else {
  611. var word = RoomNameGenerator.generateRoomWithoutSeparator();
  612. roomnode = word.toLowerCase();
  613. window.history.pushState('VideoChat',
  614. 'Room: ' + word, window.location.pathname + word);
  615. }
  616. }
  617. roomName = roomnode + '@' + config.hosts.muc;
  618. return roomName;
  619. };
  620. UI.connectionIndicatorShowMore = function(jid) {
  621. return VideoLayout.showMore(jid);
  622. };
  623. UI.showLoginPopup = function(callback) {
  624. console.log('password is required');
  625. var message = '<h2 data-i18n="dialog.passwordRequired">';
  626. message += APP.translation.translateString(
  627. "dialog.passwordRequired");
  628. message += '</h2>' +
  629. '<input name="username" type="text" ' +
  630. 'placeholder="user@domain.net" autofocus>' +
  631. '<input name="password" ' +
  632. 'type="password" data-i18n="[placeholder]dialog.userPassword"' +
  633. ' placeholder="user password">';
  634. UI.messageHandler.openTwoButtonDialog(null, null, null, message,
  635. true,
  636. "dialog.Ok",
  637. function (e, v, m, f) {
  638. if (v) {
  639. if (f.username !== null && f.password != null) {
  640. callback(f.username, f.password);
  641. }
  642. }
  643. },
  644. null, null, ':input:first'
  645. );
  646. };
  647. UI.checkForNicknameAndJoin = function () {
  648. Authentication.closeAuthenticationDialog();
  649. Authentication.stopInterval();
  650. var nick = null;
  651. if (config.useNicks) {
  652. nick = window.prompt('Your nickname (optional)');
  653. }
  654. APP.xmpp.joinRoom(roomName, config.useNicks, nick);
  655. };
  656. function dump(elem, filename) {
  657. elem = elem.parentNode;
  658. elem.download = filename || 'meetlog.json';
  659. elem.href = 'data:application/json;charset=utf-8,\n';
  660. var data = APP.xmpp.getJingleLog();
  661. var metadata = {};
  662. metadata.time = new Date();
  663. metadata.url = window.location.href;
  664. metadata.ua = navigator.userAgent;
  665. var log = APP.xmpp.getXmppLog();
  666. if (log) {
  667. metadata.xmpp = log;
  668. }
  669. data.metadata = metadata;
  670. elem.href += encodeURIComponent(JSON.stringify(data, null, ' '));
  671. return false;
  672. }
  673. UI.getRoomName = function () {
  674. return roomName;
  675. };
  676. UI.setInitialMuteFromFocus = function (muteAudio, muteVideo) {
  677. if (muteAudio || muteVideo)
  678. notifyForInitialMute();
  679. if (muteAudio)
  680. UI.setAudioMuted(true);
  681. if (muteVideo)
  682. UI.setVideoMute(true);
  683. };
  684. /**
  685. * Mutes/unmutes the local video.
  686. */
  687. UI.toggleVideo = function () {
  688. setVideoMute(!APP.RTC.localVideo.isMuted());
  689. };
  690. /**
  691. * Mutes / unmutes audio for the local participant.
  692. */
  693. UI.toggleAudio = function() {
  694. UI.setAudioMuted(!APP.RTC.localAudio.isMuted());
  695. };
  696. /**
  697. * Sets muted audio state for the local participant.
  698. */
  699. UI.setAudioMuted = function (mute, earlyMute) {
  700. var audioMute = null;
  701. if (earlyMute)
  702. audioMute = function (mute, cb) {
  703. return APP.xmpp.sendAudioInfoPresence(mute, cb);
  704. };
  705. else
  706. audioMute = function (mute, cb) {
  707. return APP.xmpp.setAudioMute(mute, cb);
  708. };
  709. if (!audioMute(mute, function () {
  710. VideoLayout.showLocalAudioIndicator(mute);
  711. UIUtil.buttonClick("#mute", "icon-microphone icon-mic-disabled");
  712. })) {
  713. // We still click the button.
  714. UIUtil.buttonClick("#mute", "icon-microphone icon-mic-disabled");
  715. return;
  716. }
  717. };
  718. UI.addListener = function (type, listener) {
  719. eventEmitter.on(type, listener);
  720. };
  721. UI.clickOnVideo = function (videoNumber) {
  722. var remoteVideos = $(".videocontainer:not(#mixedstream)");
  723. if (remoteVideos.length > videoNumber) {
  724. remoteVideos[videoNumber].click();
  725. }
  726. };
  727. //Used by torture
  728. UI.showToolbar = function () {
  729. return ToolbarToggler.showToolbar();
  730. };
  731. //Used by torture
  732. UI.dockToolbar = function (isDock) {
  733. return ToolbarToggler.dockToolbar(isDock);
  734. };
  735. UI.setVideoMuteButtonsState = function (mute) {
  736. var video = $('#video');
  737. var communicativeClass = "icon-camera";
  738. var muteClass = "icon-camera icon-camera-disabled";
  739. if (mute) {
  740. video.removeClass(communicativeClass);
  741. video.addClass(muteClass);
  742. } else {
  743. video.removeClass(muteClass);
  744. video.addClass(communicativeClass);
  745. }
  746. };
  747. UI.userAvatarChanged = function (resourceJid, thumbUrl, contactListUrl) {
  748. VideoLayout.userAvatarChanged(resourceJid, thumbUrl);
  749. ContactList.userAvatarChanged(resourceJid, contactListUrl);
  750. if(resourceJid === APP.xmpp.myResource())
  751. SettingsMenu.changeAvatar(thumbUrl);
  752. };
  753. UI.setVideoMute = setVideoMute;
  754. module.exports = UI;