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.

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