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

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