You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UI.js 27KB

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