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

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