您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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