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

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