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.

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