Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  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 userResource = APP.UI.getLargeVideoResource();
  161. eventEmitter.emit(UIEvents.SELECTED_ENDPOINT, userResource);
  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.getLargeVideoResource());
  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.PARTICIPANT_VIDEO_TYPE_CHANGED,
  245. onPeerVideoTypeChanged);
  246. APP.xmpp.addListener(XMPPEvents.DEVICE_AVAILABLE,
  247. function (resource, devices) {
  248. VideoLayout.setDeviceAvailabilityIcons(resource, devices);
  249. });
  250. APP.xmpp.addListener(XMPPEvents.PARTICIPANT_AUDIO_MUTED,
  251. VideoLayout.onAudioMute);
  252. APP.xmpp.addListener(XMPPEvents.PARTICIPANT_VIDEO_MUTED,
  253. VideoLayout.onVideoMute);
  254. APP.xmpp.addListener(XMPPEvents.AUDIO_MUTED_BY_FOCUS, function (doMuteAudio) {
  255. UI.setAudioMuted(doMuteAudio);
  256. });
  257. APP.members.addListener(MemberEvents.DTMF_SUPPORT_CHANGED,
  258. onDtmfSupportChanged);
  259. APP.xmpp.addListener(XMPPEvents.START_MUTED_SETTING_CHANGED, function (audio, video) {
  260. SettingsMenu.setStartMuted(audio, video);
  261. });
  262. APP.xmpp.addListener(XMPPEvents.START_MUTED_FROM_FOCUS, function (audio, video) {
  263. UI.setInitialMuteFromFocus(audio, video);
  264. });
  265. APP.xmpp.addListener(XMPPEvents.JINGLE_FATAL_ERROR, function (session, error) {
  266. UI.messageHandler.showError("dialog.sorry",
  267. "dialog.internalError");
  268. });
  269. APP.xmpp.addListener(XMPPEvents.SET_LOCAL_DESCRIPTION_ERROR, function () {
  270. messageHandler.showError("dialog.error",
  271. "dialog.SLDFailure");
  272. });
  273. APP.xmpp.addListener(XMPPEvents.SET_REMOTE_DESCRIPTION_ERROR, function () {
  274. messageHandler.showError("dialog.error",
  275. "dialog.SRDFailure");
  276. });
  277. APP.xmpp.addListener(XMPPEvents.CREATE_ANSWER_ERROR, function () {
  278. messageHandler.showError();
  279. });
  280. APP.xmpp.addListener(XMPPEvents.PROMPT_FOR_LOGIN, function () {
  281. // FIXME: re-use LoginDialog which supports retries
  282. UI.showLoginPopup(connect);
  283. });
  284. APP.xmpp.addListener(XMPPEvents.FOCUS_DISCONNECTED, function (focusComponent, retrySec) {
  285. UI.messageHandler.notify(
  286. null, "notify.focus",
  287. 'disconnected', "notify.focusFail",
  288. {component: focusComponent, ms: retrySec});
  289. });
  290. APP.xmpp.addListener(XMPPEvents.ROOM_JOIN_ERROR, function (pres) {
  291. UI.messageHandler.openReportDialog(null,
  292. "dialog.joinError", pres);
  293. });
  294. APP.xmpp.addListener(XMPPEvents.ROOM_CONNECT_ERROR, function (pres) {
  295. UI.messageHandler.openReportDialog(null,
  296. "dialog.connectError", pres);
  297. });
  298. APP.xmpp.addListener(XMPPEvents.READY_TO_JOIN, function () {
  299. var roomName = UI.generateRoomName();
  300. APP.xmpp.allocateConferenceFocus(roomName, UI.checkForNicknameAndJoin);
  301. });
  302. //NicknameHandler emits this event
  303. UI.addListener(UIEvents.NICKNAME_CHANGED, function (nickname) {
  304. APP.xmpp.addToPresence("displayName", nickname);
  305. });
  306. UI.addListener(UIEvents.LARGEVIDEO_INIT, function () {
  307. AudioLevels.init();
  308. });
  309. if (!interfaceConfig.filmStripOnly) {
  310. APP.xmpp.addListener(XMPPEvents.MESSAGE_RECEIVED, updateChatConversation);
  311. APP.xmpp.addListener(XMPPEvents.CHAT_ERROR_RECEIVED, chatAddError);
  312. // Listens for video interruption events.
  313. APP.xmpp.addListener(XMPPEvents.CONNECTION_INTERRUPTED, VideoLayout.onVideoInterrupted);
  314. // Listens for video restores events.
  315. APP.xmpp.addListener(XMPPEvents.CONNECTION_RESTORED, VideoLayout.onVideoRestored);
  316. }
  317. }
  318. /**
  319. * Mutes/unmutes the local video.
  320. *
  321. * @param mute <tt>true</tt> to mute the local video; otherwise, <tt>false</tt>
  322. * @param options an object which specifies optional arguments such as the
  323. * <tt>boolean</tt> key <tt>byUser</tt> with default value <tt>true</tt> which
  324. * specifies whether the method was initiated in response to a user command (in
  325. * contrast to an automatic decision taken by the application logic)
  326. */
  327. function setVideoMute(mute, options) {
  328. APP.RTC.setVideoMute(mute,
  329. UI.setVideoMuteButtonsState,
  330. options);
  331. }
  332. function onResize() {
  333. Chat.resizeChat();
  334. VideoLayout.resizeLargeVideoContainer();
  335. }
  336. function bindEvents() {
  337. /**
  338. * Resizes and repositions videos in full screen mode.
  339. */
  340. $(document).on('webkitfullscreenchange mozfullscreenchange fullscreenchange',
  341. onResize);
  342. $(window).resize(onResize);
  343. }
  344. UI.start = function (init) {
  345. document.title = interfaceConfig.APP_NAME;
  346. var setupWelcomePage = null;
  347. if(config.enableWelcomePage && window.location.pathname == "/" &&
  348. (!window.localStorage.welcomePageDisabled ||
  349. window.localStorage.welcomePageDisabled == "false")) {
  350. $("#videoconference_page").hide();
  351. if (!setupWelcomePage)
  352. setupWelcomePage = require("./welcome_page/WelcomePage");
  353. setupWelcomePage();
  354. return;
  355. }
  356. $("#welcome_page").hide();
  357. // Set the defaults for prompt dialogs.
  358. $.prompt.setDefaults({persistent: false});
  359. registerListeners();
  360. VideoLayout.init(eventEmitter);
  361. NicknameHandler.init(eventEmitter);
  362. bindEvents();
  363. setupPrezi();
  364. if (!interfaceConfig.filmStripOnly) {
  365. $("#videospace").mousemove(function () {
  366. return ToolbarToggler.showToolbar();
  367. });
  368. setupToolbars();
  369. setupChat();
  370. // Display notice message at the top of the toolbar
  371. if (config.noticeMessage) {
  372. $('#noticeText').text(config.noticeMessage);
  373. $('#notice').css({display: 'block'});
  374. }
  375. $("#downloadlog").click(function (event) {
  376. dump(event.target);
  377. });
  378. }
  379. else
  380. {
  381. $("#header").css("display", "none");
  382. $("#bottomToolbar").css("display", "none");
  383. $("#downloadlog").css("display", "none");
  384. $("#remoteVideos").css("padding", "0px 0px 18px 0px");
  385. $("#remoteVideos").css("right", "0px");
  386. messageHandler.disableNotifications();
  387. $('body').popover("disable");
  388. // $("[data-toggle=popover]").popover("disable");
  389. JitsiPopover.enabled = false;
  390. }
  391. document.title = interfaceConfig.APP_NAME;
  392. if(config.requireDisplayName) {
  393. var currentSettings = Settings.getSettings();
  394. if (!currentSettings.displayName) {
  395. promptDisplayName();
  396. }
  397. }
  398. init();
  399. if (!interfaceConfig.filmStripOnly) {
  400. toastr.options = {
  401. "closeButton": true,
  402. "debug": false,
  403. "positionClass": "notification-bottom-right",
  404. "onclick": null,
  405. "showDuration": "300",
  406. "hideDuration": "1000",
  407. "timeOut": "2000",
  408. "extendedTimeOut": "1000",
  409. "showEasing": "swing",
  410. "hideEasing": "linear",
  411. "showMethod": "fadeIn",
  412. "hideMethod": "fadeOut",
  413. "reposition": function () {
  414. if (PanelToggler.isVisible()) {
  415. $("#toast-container").addClass("notification-bottom-right-center");
  416. } else {
  417. $("#toast-container").removeClass("notification-bottom-right-center");
  418. }
  419. },
  420. "newestOnTop": false
  421. };
  422. SettingsMenu.init();
  423. }
  424. };
  425. function chatAddError(errorMessage, originalText) {
  426. return Chat.chatAddError(errorMessage, originalText);
  427. }
  428. function chatSetSubject(text) {
  429. return Chat.chatSetSubject(text);
  430. }
  431. function updateChatConversation(from, displayName, message, myjid, stamp) {
  432. return Chat.updateChatConversation(from, displayName, message, myjid, stamp);
  433. }
  434. function onMucJoined(jid, info) {
  435. Toolbar.updateRoomUrl(window.location.href);
  436. var meHTML = APP.translation.generateTranslationHTML("me");
  437. $("#localNick").html(Strophe.getResourceFromJid(jid) + " (" + meHTML + ")");
  438. var settings = Settings.getSettings();
  439. // Make sure we configure our avatar id, before creating avatar for us
  440. Avatar.setUserAvatar(jid, settings.email || settings.uid);
  441. // Add myself to the contact list.
  442. ContactList.addContact(jid);
  443. // Once we've joined the muc show the toolbar
  444. ToolbarToggler.showToolbar();
  445. var displayName =
  446. config.displayJids ? Strophe.getResourceFromJid(jid) : info.displayName;
  447. if (displayName)
  448. onDisplayNameChanged('localVideoContainer', displayName);
  449. VideoLayout.mucJoined();
  450. }
  451. function initEtherpad(name) {
  452. Etherpad.init(name);
  453. }
  454. function onMucMemberLeft(jid) {
  455. console.log('left.muc', jid);
  456. var displayName = $('#participant_' + Strophe.getResourceFromJid(jid) +
  457. '>.displayname').html();
  458. messageHandler.notify(displayName,'notify.somebody',
  459. 'disconnected',
  460. 'notify.disconnected');
  461. if (!config.startAudioMuted ||
  462. config.startAudioMuted > APP.members.size()) {
  463. UIUtil.playSoundNotification('userLeft');
  464. }
  465. ContactList.removeContact(jid);
  466. VideoLayout.participantLeft(jid);
  467. }
  468. function onLocalRoleChanged(jid, info, pres, isModerator) {
  469. console.info("My role changed, new role: " + info.role);
  470. onModeratorStatusChanged(isModerator);
  471. VideoLayout.showModeratorIndicator();
  472. SettingsMenu.onRoleChanged();
  473. if (isModerator) {
  474. Authentication.closeAuthenticationWindow();
  475. messageHandler.notify(null, "notify.me",
  476. 'connected', "notify.moderator");
  477. Toolbar.checkAutoRecord();
  478. }
  479. }
  480. function onModeratorStatusChanged(isModerator) {
  481. Toolbar.showSipCallButton(isModerator);
  482. Toolbar.showRecordingButton(
  483. isModerator); //&&
  484. // FIXME:
  485. // Recording visible if
  486. // there are at least 2(+ 1 focus) participants
  487. //Object.keys(connection.emuc.members).length >= 3);
  488. }
  489. function onPasswordRequired(callback) {
  490. // password is required
  491. Toolbar.lockLockButton();
  492. var message = '<h2 data-i18n="dialog.passwordRequired">';
  493. message += APP.translation.translateString(
  494. "dialog.passwordRequired");
  495. message += '</h2>' +
  496. '<input name="lockKey" type="text" data-i18n=' +
  497. '"[placeholder]dialog.password" placeholder="' +
  498. APP.translation.translateString("dialog.password") +
  499. '" autofocus>';
  500. messageHandler.openTwoButtonDialog(null, null, null, message,
  501. true,
  502. "dialog.Ok",
  503. function (e, v, m, f) {},
  504. null,
  505. function (e, v, m, f) {
  506. if (v) {
  507. var lockKey = f.lockKey;
  508. if (lockKey) {
  509. Toolbar.setSharedKey(lockKey);
  510. callback(lockKey);
  511. }
  512. }
  513. },
  514. ':input:first'
  515. );
  516. }
  517. /**
  518. * The dialpad button is shown iff there is at least one member that supports
  519. * DTMF (e.g. jigasi).
  520. */
  521. function onDtmfSupportChanged(dtmfSupport) {
  522. //TODO: enable when the UI is ready
  523. //Toolbar.showDialPadButton(dtmfSupport);
  524. }
  525. function onMucMemberJoined(jid, id, displayName) {
  526. messageHandler.notify(displayName,'notify.somebody',
  527. 'connected',
  528. 'notify.connected');
  529. if (!config.startAudioMuted ||
  530. config.startAudioMuted > APP.members.size())
  531. UIUtil.playSoundNotification('userJoined');
  532. // Configure avatar
  533. Avatar.setUserAvatar(jid, id);
  534. // Add Peer's container
  535. VideoLayout.ensurePeerContainerExists(jid);
  536. }
  537. function onMucPresenceStatus(jid, info) {
  538. VideoLayout.setPresenceStatus(Strophe.getResourceFromJid(jid), info.status);
  539. }
  540. function onPeerVideoTypeChanged(resourceJid, newVideoType) {
  541. VideoLayout.onVideoTypeChanged(resourceJid, newVideoType);
  542. }
  543. function onMucRoleChanged(role, displayName) {
  544. VideoLayout.showModeratorIndicator();
  545. if (role === 'moderator') {
  546. var messageKey, messageOptions = {};
  547. if (!displayName) {
  548. messageKey = "notify.grantedToUnknown";
  549. }
  550. else {
  551. messageKey = "notify.grantedTo";
  552. messageOptions = {to: displayName};
  553. }
  554. messageHandler.notify(
  555. displayName,'notify.somebody',
  556. 'connected', messageKey,
  557. messageOptions);
  558. }
  559. }
  560. function onAuthenticationRequired(intervalCallback) {
  561. Authentication.openAuthenticationDialog(
  562. roomName, intervalCallback, function () {
  563. Toolbar.authenticateClicked();
  564. });
  565. }
  566. function onLastNChanged(oldValue, newValue) {
  567. if (config.muteLocalVideoIfNotInLastN) {
  568. setVideoMute(!newValue, { 'byUser': false });
  569. }
  570. }
  571. UI.toggleSmileys = function () {
  572. Chat.toggleSmileys();
  573. };
  574. UI.getSettings = function () {
  575. return Settings.getSettings();
  576. };
  577. UI.toggleFilmStrip = function () {
  578. return BottomToolbar.toggleFilmStrip();
  579. };
  580. UI.toggleChat = function () {
  581. return BottomToolbar.toggleChat();
  582. };
  583. UI.toggleContactList = function () {
  584. return BottomToolbar.toggleContactList();
  585. };
  586. UI.inputDisplayNameHandler = function (value) {
  587. VideoLayout.inputDisplayNameHandler(value);
  588. };
  589. UI.getLargeVideoResource = function () {
  590. return VideoLayout.getLargeVideoResource();
  591. };
  592. UI.generateRoomName = function() {
  593. if(roomName)
  594. return roomName;
  595. var roomnode = null;
  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. roomName = roomnode + '@' + config.hosts.muc;
  621. return roomName;
  622. };
  623. UI.connectionIndicatorShowMore = function(jid) {
  624. return VideoLayout.showMore(jid);
  625. };
  626. UI.showLoginPopup = function(callback) {
  627. console.log('password is required');
  628. var message = '<h2 data-i18n="dialog.passwordRequired">';
  629. message += APP.translation.translateString(
  630. "dialog.passwordRequired");
  631. message += '</h2>' +
  632. '<input name="username" type="text" ' +
  633. 'placeholder="user@domain.net" autofocus>' +
  634. '<input name="password" ' +
  635. 'type="password" data-i18n="[placeholder]dialog.userPassword"' +
  636. ' placeholder="user password">';
  637. UI.messageHandler.openTwoButtonDialog(null, null, null, message,
  638. true,
  639. "dialog.Ok",
  640. function (e, v, m, f) {
  641. if (v) {
  642. if (f.username !== null && f.password != null) {
  643. callback(f.username, f.password);
  644. }
  645. }
  646. },
  647. null, null, ':input:first'
  648. );
  649. };
  650. UI.checkForNicknameAndJoin = function () {
  651. Authentication.closeAuthenticationDialog();
  652. Authentication.stopInterval();
  653. var nick = null;
  654. if (config.useNicks) {
  655. nick = window.prompt('Your nickname (optional)');
  656. }
  657. APP.xmpp.joinRoom(roomName, config.useNicks, nick);
  658. };
  659. function dump(elem, filename) {
  660. elem = elem.parentNode;
  661. elem.download = filename || 'meetlog.json';
  662. elem.href = 'data:application/json;charset=utf-8,\n';
  663. var data = APP.xmpp.getJingleLog();
  664. var metadata = {};
  665. metadata.time = new Date();
  666. metadata.url = window.location.href;
  667. metadata.ua = navigator.userAgent;
  668. var log = APP.xmpp.getXmppLog();
  669. if (log) {
  670. metadata.xmpp = log;
  671. }
  672. data.metadata = metadata;
  673. elem.href += encodeURIComponent(JSON.stringify(data, null, ' '));
  674. return false;
  675. }
  676. UI.getRoomName = function () {
  677. return roomName;
  678. };
  679. UI.setInitialMuteFromFocus = function (muteAudio, muteVideo) {
  680. if (muteAudio || muteVideo)
  681. notifyForInitialMute();
  682. if (muteAudio)
  683. UI.setAudioMuted(true);
  684. if (muteVideo)
  685. UI.setVideoMute(true);
  686. };
  687. /**
  688. * Mutes/unmutes the local video.
  689. */
  690. UI.toggleVideo = function () {
  691. setVideoMute(!APP.RTC.localVideo.isMuted());
  692. };
  693. /**
  694. * Mutes / unmutes audio for the local participant.
  695. */
  696. UI.toggleAudio = function() {
  697. UI.setAudioMuted(!APP.RTC.localAudio.isMuted());
  698. };
  699. /**
  700. * Sets muted audio state for the local participant.
  701. */
  702. UI.setAudioMuted = function (mute, earlyMute) {
  703. var audioMute = null;
  704. if (earlyMute)
  705. audioMute = function (mute, cb) {
  706. return APP.xmpp.sendAudioInfoPresence(mute, cb);
  707. };
  708. else
  709. audioMute = function (mute, cb) {
  710. return APP.xmpp.setAudioMute(mute, cb);
  711. };
  712. if (!audioMute(mute, function () {
  713. VideoLayout.showLocalAudioIndicator(mute);
  714. UIUtil.buttonClick("#toolbar_button_mute", "icon-microphone icon-mic-disabled");
  715. })) {
  716. // We still click the button.
  717. UIUtil.buttonClick("#toolbar_button_mute", "icon-microphone icon-mic-disabled");
  718. return;
  719. }
  720. };
  721. UI.addListener = function (type, listener) {
  722. eventEmitter.on(type, listener);
  723. };
  724. UI.clickOnVideo = function (videoNumber) {
  725. var remoteVideos = $(".videocontainer:not(#mixedstream)");
  726. if (remoteVideos.length > videoNumber) {
  727. remoteVideos[videoNumber].click();
  728. }
  729. };
  730. //Used by torture
  731. UI.showToolbar = function () {
  732. return ToolbarToggler.showToolbar();
  733. };
  734. //Used by torture
  735. UI.dockToolbar = function (isDock) {
  736. return ToolbarToggler.dockToolbar(isDock);
  737. };
  738. UI.setVideoMuteButtonsState = function (mute) {
  739. var video = $('#toolbar_button_camera');
  740. var communicativeClass = "icon-camera";
  741. var muteClass = "icon-camera icon-camera-disabled";
  742. if (mute) {
  743. video.removeClass(communicativeClass);
  744. video.addClass(muteClass);
  745. } else {
  746. video.removeClass(muteClass);
  747. video.addClass(communicativeClass);
  748. }
  749. };
  750. UI.userAvatarChanged = function (resourceJid, thumbUrl, contactListUrl) {
  751. VideoLayout.userAvatarChanged(resourceJid, thumbUrl);
  752. ContactList.userAvatarChanged(resourceJid, contactListUrl);
  753. if(resourceJid === APP.xmpp.myResource())
  754. SettingsMenu.changeAvatar(thumbUrl);
  755. };
  756. UI.setVideoMute = setVideoMute;
  757. module.exports = UI;