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

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