Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

UI.js 29KB

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