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 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  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.addListener(RTCEvents.LASTN_CHANGED, onLastNChanged);
  140. APP.RTC.addListener(RTCEvents.DOMINANTSPEAKER_CHANGED,
  141. function (resourceJid) {
  142. VideoLayout.onDominantSpeakerChanged(resourceJid);
  143. });
  144. APP.RTC.addListener(RTCEvents.LASTN_ENDPOINT_CHANGED,
  145. function (lastNEndpoints, endpointsEnteringLastN, stream) {
  146. VideoLayout.onLastNEndpointsChanged(lastNEndpoints,
  147. endpointsEnteringLastN, stream);
  148. });
  149. APP.RTC.addListener(RTCEvents.AVAILABLE_DEVICES_CHANGED,
  150. function (devices) {
  151. VideoLayout.setDeviceAvailabilityIcons(null, devices);
  152. });
  153. APP.RTC.addListener(RTCEvents.VIDEO_MUTE, UI.setVideoMuteButtonsState);
  154. APP.RTC.addListener(RTCEvents.DATA_CHANNEL_OPEN, function() {
  155. // when the data channel becomes available, tell the bridge about video
  156. // selections so that it can do adaptive simulcast,
  157. // we want the notification to trigger even if userJid is undefined,
  158. // or null.
  159. var userJid = APP.UI.getLargeVideoJid();
  160. eventEmitter.emit(UIEvents.SELECTED_ENDPOINT, userJid);
  161. });
  162. APP.statistics.addAudioLevelListener(function(jid, audioLevel) {
  163. var resourceJid;
  164. if(jid === APP.statistics.LOCAL_JID) {
  165. resourceJid = AudioLevels.LOCAL_LEVEL;
  166. if(APP.RTC.localAudio.isMuted()) {
  167. audioLevel = 0;
  168. }
  169. } else {
  170. resourceJid = Strophe.getResourceFromJid(jid);
  171. }
  172. AudioLevels.updateAudioLevel(resourceJid, audioLevel,
  173. UI.getLargeVideoJid());
  174. });
  175. APP.desktopsharing.addListener(function () {
  176. ToolbarToggler.showDesktopSharingButton();
  177. }, DesktopSharingEventTypes.INIT);
  178. APP.desktopsharing.addListener(
  179. Toolbar.changeDesktopSharingButtonState,
  180. DesktopSharingEventTypes.SWITCHING_DONE);
  181. APP.connectionquality.addListener(CQEvents.LOCALSTATS_UPDATED,
  182. VideoLayout.updateLocalConnectionStats);
  183. APP.connectionquality.addListener(CQEvents.REMOTESTATS_UPDATED,
  184. VideoLayout.updateConnectionStats);
  185. APP.connectionquality.addListener(CQEvents.STOP,
  186. VideoLayout.onStatsStop);
  187. APP.xmpp.addListener(XMPPEvents.CONNECTION_FAILED, onXmppConnectionFailed);
  188. APP.xmpp.addListener(XMPPEvents.DISPOSE_CONFERENCE, onDisposeConference);
  189. APP.xmpp.addListener(XMPPEvents.GRACEFUL_SHUTDOWN, function () {
  190. messageHandler.openMessageDialog(
  191. 'dialog.serviceUnavailable',
  192. 'dialog.gracefulShutdown'
  193. );
  194. });
  195. APP.xmpp.addListener(XMPPEvents.RESERVATION_ERROR, function (code, msg) {
  196. var title = APP.translation.generateTranslationHTML(
  197. "dialog.reservationError");
  198. var message = APP.translation.generateTranslationHTML(
  199. "dialog.reservationErrorMsg", {code: code, msg: msg});
  200. messageHandler.openDialog(
  201. title,
  202. message,
  203. true, {},
  204. function (event, value, message, formVals) {
  205. return false;
  206. }
  207. );
  208. });
  209. APP.xmpp.addListener(XMPPEvents.KICKED, function () {
  210. messageHandler.openMessageDialog("dialog.sessTerminated",
  211. "dialog.kickMessage");
  212. });
  213. APP.xmpp.addListener(XMPPEvents.MUC_DESTROYED, function (reason) {
  214. //FIXME: use Session Terminated from translation, but
  215. // 'reason' text comes from XMPP packet and is not translated
  216. var title = APP.translation.generateTranslationHTML("dialog.sessTerminated");
  217. messageHandler.openDialog(
  218. title, reason, true, {},
  219. function (event, value, message, formVals) {
  220. return false;
  221. }
  222. );
  223. });
  224. APP.xmpp.addListener(XMPPEvents.BRIDGE_DOWN, function () {
  225. messageHandler.showError("dialog.error",
  226. "dialog.bridgeUnavailable");
  227. });
  228. APP.xmpp.addListener(XMPPEvents.USER_ID_CHANGED, function (from, id) {
  229. Avatar.setUserAvatar(from, id);
  230. });
  231. APP.xmpp.addListener(XMPPEvents.DISPLAY_NAME_CHANGED, onDisplayNameChanged);
  232. APP.xmpp.addListener(XMPPEvents.MUC_JOINED, onMucJoined);
  233. APP.xmpp.addListener(XMPPEvents.LOCAL_ROLE_CHANGED, onLocalRoleChanged);
  234. APP.xmpp.addListener(XMPPEvents.MUC_MEMBER_JOINED, onMucMemberJoined);
  235. APP.xmpp.addListener(XMPPEvents.MUC_ROLE_CHANGED, onMucRoleChanged);
  236. APP.xmpp.addListener(XMPPEvents.PRESENCE_STATUS, onMucPresenceStatus);
  237. APP.xmpp.addListener(XMPPEvents.SUBJECT_CHANGED, chatSetSubject);
  238. APP.xmpp.addListener(XMPPEvents.MESSAGE_RECEIVED, updateChatConversation);
  239. APP.xmpp.addListener(XMPPEvents.MUC_MEMBER_LEFT, onMucMemberLeft);
  240. APP.xmpp.addListener(XMPPEvents.PASSWORD_REQUIRED, onPasswordRequired);
  241. APP.xmpp.addListener(XMPPEvents.CHAT_ERROR_RECEIVED, chatAddError);
  242. APP.xmpp.addListener(XMPPEvents.ETHERPAD, initEtherpad);
  243. APP.xmpp.addListener(XMPPEvents.AUTHENTICATION_REQUIRED,
  244. onAuthenticationRequired);
  245. APP.xmpp.addListener(XMPPEvents.VIDEO_TYPE, onPeerVideoTypeChanged);
  246. APP.xmpp.addListener(XMPPEvents.DEVICE_AVAILABLE,
  247. function (resource, devices) {
  248. VideoLayout.setDeviceAvailabilityIcons(resource, devices);
  249. });
  250. APP.xmpp.addListener(XMPPEvents.AUDIO_MUTED, VideoLayout.onAudioMute);
  251. APP.xmpp.addListener(XMPPEvents.VIDEO_MUTED, VideoLayout.onVideoMute);
  252. APP.xmpp.addListener(XMPPEvents.AUDIO_MUTED_BY_FOCUS, function(doMuteAudio) {
  253. UI.setAudioMuted(doMuteAudio);
  254. });
  255. APP.members.addListener(MemberEvents.DTMF_SUPPORT_CHANGED,
  256. onDtmfSupportChanged);
  257. APP.xmpp.addListener(XMPPEvents.START_MUTED_SETTING_CHANGED, function (audio, video) {
  258. SettingsMenu.setStartMuted(audio, video);
  259. });
  260. APP.xmpp.addListener(XMPPEvents.START_MUTED_FROM_FOCUS, function (audio, video) {
  261. UI.setInitialMuteFromFocus(audio, video);
  262. });
  263. APP.xmpp.addListener(XMPPEvents.JINGLE_FATAL_ERROR, function (session, error) {
  264. UI.messageHandler.showError("dialog.sorry",
  265. "dialog.internalError");
  266. });
  267. APP.xmpp.addListener(XMPPEvents.SET_LOCAL_DESCRIPTION_ERROR, function() {
  268. messageHandler.showError("dialog.error",
  269. "dialog.SLDFailure");
  270. });
  271. APP.xmpp.addListener(XMPPEvents.SET_REMOTE_DESCRIPTION_ERROR, function() {
  272. messageHandler.showError("dialog.error",
  273. "dialog.SRDFailure");
  274. });
  275. APP.xmpp.addListener(XMPPEvents.CREATE_ANSWER_ERROR, function() {
  276. messageHandler.showError();
  277. });
  278. APP.xmpp.addListener(XMPPEvents.PROMPT_FOR_LOGIN, function() {
  279. // FIXME: re-use LoginDialog which supports retries
  280. UI.showLoginPopup(connect);
  281. });
  282. APP.xmpp.addListener(XMPPEvents.FOCUS_DISCONNECTED, function(focusComponent, retrySec) {
  283. UI.messageHandler.notify(
  284. null, "notify.focus",
  285. 'disconnected', "notify.focusFail",
  286. {component: focusComponent, ms: retrySec});
  287. });
  288. APP.xmpp.addListener(XMPPEvents.ROOM_JOIN_ERROR, function(pres) {
  289. UI.messageHandler.openReportDialog(null,
  290. "dialog.joinError", pres);
  291. });
  292. APP.xmpp.addListener(XMPPEvents.ROOM_CONNECT_ERROR, function(pres) {
  293. UI.messageHandler.openReportDialog(null,
  294. "dialog.connectError", pres);
  295. });
  296. APP.xmpp.addListener(XMPPEvents.READY_TO_JOIN, function() {
  297. var roomName = UI.generateRoomName();
  298. APP.xmpp.allocateConferenceFocus(roomName, UI.checkForNicknameAndJoin);
  299. });
  300. //NicknameHandler emits this event
  301. UI.addListener(UIEvents.NICKNAME_CHANGED, function (nickname) {
  302. APP.xmpp.addToPresence("displayName", nickname);
  303. });
  304. UI.addListener(UIEvents.LARGEVIDEO_INIT, function () {
  305. AudioLevels.init();
  306. });
  307. // Listens for video interruption events.
  308. APP.xmpp.addListener(XMPPEvents.CONNECTION_INTERRUPTED, VideoLayout.onVideoInterrupted);
  309. // Listens for video restores events.
  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 onPeerVideoTypeChanged(resourceJid, newVideoType) {
  528. VideoLayout.onVideoTypeChanged(resourceJid, newVideoType);
  529. }
  530. function onMucRoleChanged(role, displayName) {
  531. VideoLayout.showModeratorIndicator();
  532. if (role === 'moderator') {
  533. var messageKey, messageOptions = {};
  534. if (!displayName) {
  535. messageKey = "notify.grantedToUnknown";
  536. }
  537. else {
  538. messageKey = "notify.grantedTo";
  539. messageOptions = {to: displayName};
  540. }
  541. messageHandler.notify(
  542. displayName,'notify.somebody',
  543. 'connected', messageKey,
  544. messageOptions);
  545. }
  546. }
  547. function onAuthenticationRequired(intervalCallback) {
  548. Authentication.openAuthenticationDialog(
  549. roomName, intervalCallback, function () {
  550. Toolbar.authenticateClicked();
  551. });
  552. }
  553. function onLastNChanged(oldValue, newValue) {
  554. if (config.muteLocalVideoIfNotInLastN) {
  555. setVideoMute(!newValue, { 'byUser': false });
  556. }
  557. }
  558. UI.toggleSmileys = function () {
  559. Chat.toggleSmileys();
  560. };
  561. UI.getSettings = function () {
  562. return Settings.getSettings();
  563. };
  564. UI.toggleFilmStrip = function () {
  565. return BottomToolbar.toggleFilmStrip();
  566. };
  567. UI.toggleChat = function () {
  568. return BottomToolbar.toggleChat();
  569. };
  570. UI.toggleContactList = function () {
  571. return BottomToolbar.toggleContactList();
  572. };
  573. UI.inputDisplayNameHandler = function (value) {
  574. VideoLayout.inputDisplayNameHandler(value);
  575. };
  576. UI.getLargeVideoJid = function() {
  577. return VideoLayout.getLargeVideoJid();
  578. };
  579. UI.generateRoomName = function() {
  580. if(roomName)
  581. return roomName;
  582. var roomnode = null;
  583. var path = window.location.pathname;
  584. // determinde the room node from the url
  585. // TODO: just the roomnode or the whole bare jid?
  586. if (config.getroomnode && typeof config.getroomnode === 'function') {
  587. // custom function might be responsible for doing the pushstate
  588. roomnode = config.getroomnode(path);
  589. } else {
  590. /* fall back to default strategy
  591. * this is making assumptions about how the URL->room mapping happens.
  592. * It currently assumes deployment at root, with a rewrite like the
  593. * following one (for nginx):
  594. location ~ ^/([a-zA-Z0-9]+)$ {
  595. rewrite ^/(.*)$ / break;
  596. }
  597. */
  598. if (path.length > 1) {
  599. roomnode = path.substr(1).toLowerCase();
  600. } else {
  601. var word = RoomNameGenerator.generateRoomWithoutSeparator();
  602. roomnode = word.toLowerCase();
  603. window.history.pushState('VideoChat',
  604. 'Room: ' + word, window.location.pathname + word);
  605. }
  606. }
  607. roomName = roomnode + '@' + config.hosts.muc;
  608. return roomName;
  609. };
  610. UI.connectionIndicatorShowMore = function(jid) {
  611. return VideoLayout.showMore(jid);
  612. };
  613. UI.showLoginPopup = function(callback) {
  614. console.log('password is required');
  615. var message = '<h2 data-i18n="dialog.passwordRequired">';
  616. message += APP.translation.translateString(
  617. "dialog.passwordRequired");
  618. message += '</h2>' +
  619. '<input name="username" type="text" ' +
  620. 'placeholder="user@domain.net" autofocus>' +
  621. '<input name="password" ' +
  622. 'type="password" data-i18n="[placeholder]dialog.userPassword"' +
  623. ' placeholder="user password">';
  624. UI.messageHandler.openTwoButtonDialog(null, null, null, message,
  625. true,
  626. "dialog.Ok",
  627. function (e, v, m, f) {
  628. if (v) {
  629. if (f.username !== null && f.password != null) {
  630. callback(f.username, f.password);
  631. }
  632. }
  633. },
  634. null, null, ':input:first'
  635. );
  636. };
  637. UI.checkForNicknameAndJoin = function () {
  638. Authentication.closeAuthenticationDialog();
  639. Authentication.stopInterval();
  640. var nick = null;
  641. if (config.useNicks) {
  642. nick = window.prompt('Your nickname (optional)');
  643. }
  644. APP.xmpp.joinRoom(roomName, config.useNicks, nick);
  645. };
  646. function dump(elem, filename) {
  647. elem = elem.parentNode;
  648. elem.download = filename || 'meetlog.json';
  649. elem.href = 'data:application/json;charset=utf-8,\n';
  650. var data = APP.xmpp.getJingleLog();
  651. var metadata = {};
  652. metadata.time = new Date();
  653. metadata.url = window.location.href;
  654. metadata.ua = navigator.userAgent;
  655. var log = APP.xmpp.getXmppLog();
  656. if (log) {
  657. metadata.xmpp = log;
  658. }
  659. data.metadata = metadata;
  660. elem.href += encodeURIComponent(JSON.stringify(data, null, ' '));
  661. return false;
  662. }
  663. UI.getRoomName = function () {
  664. return roomName;
  665. };
  666. UI.setInitialMuteFromFocus = function (muteAudio, muteVideo) {
  667. if (muteAudio || muteVideo)
  668. notifyForInitialMute();
  669. if (muteAudio)
  670. UI.setAudioMuted(true);
  671. if (muteVideo)
  672. UI.setVideoMute(true);
  673. };
  674. /**
  675. * Mutes/unmutes the local video.
  676. */
  677. UI.toggleVideo = function () {
  678. setVideoMute(!APP.RTC.localVideo.isMuted());
  679. };
  680. /**
  681. * Mutes / unmutes audio for the local participant.
  682. */
  683. UI.toggleAudio = function() {
  684. UI.setAudioMuted(!APP.RTC.localAudio.isMuted());
  685. };
  686. /**
  687. * Sets muted audio state for the local participant.
  688. */
  689. UI.setAudioMuted = function (mute, earlyMute) {
  690. var audioMute = null;
  691. if (earlyMute)
  692. audioMute = function (mute, cb) {
  693. return APP.xmpp.sendAudioInfoPresence(mute, cb);
  694. };
  695. else
  696. audioMute = function (mute, cb) {
  697. return APP.xmpp.setAudioMute(mute, cb);
  698. };
  699. if (!audioMute(mute, function () {
  700. VideoLayout.showLocalAudioIndicator(mute);
  701. UIUtil.buttonClick("#toolbar_button_mute", "icon-microphone icon-mic-disabled");
  702. })) {
  703. // We still click the button.
  704. UIUtil.buttonClick("#toolbar_button_mute", "icon-microphone icon-mic-disabled");
  705. return;
  706. }
  707. };
  708. UI.addListener = function (type, listener) {
  709. eventEmitter.on(type, listener);
  710. };
  711. UI.clickOnVideo = function (videoNumber) {
  712. var remoteVideos = $(".videocontainer:not(#mixedstream)");
  713. if (remoteVideos.length > videoNumber) {
  714. remoteVideos[videoNumber].click();
  715. }
  716. };
  717. //Used by torture
  718. UI.showToolbar = function () {
  719. return ToolbarToggler.showToolbar();
  720. };
  721. //Used by torture
  722. UI.dockToolbar = function (isDock) {
  723. return ToolbarToggler.dockToolbar(isDock);
  724. };
  725. UI.setVideoMuteButtonsState = function (mute) {
  726. var video = $('#toolbar_button_camera');
  727. var communicativeClass = "icon-camera";
  728. var muteClass = "icon-camera icon-camera-disabled";
  729. if (mute) {
  730. video.removeClass(communicativeClass);
  731. video.addClass(muteClass);
  732. } else {
  733. video.removeClass(muteClass);
  734. video.addClass(communicativeClass);
  735. }
  736. };
  737. UI.userAvatarChanged = function (resourceJid, thumbUrl, contactListUrl) {
  738. VideoLayout.userAvatarChanged(resourceJid, thumbUrl);
  739. ContactList.userAvatarChanged(resourceJid, contactListUrl);
  740. if(resourceJid === APP.xmpp.myResource())
  741. SettingsMenu.changeAvatar(thumbUrl);
  742. };
  743. UI.setVideoMute = setVideoMute;
  744. module.exports = UI;