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

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