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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  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. if (isModerator && config.etherpad_base) {
  435. Etherpad.init();
  436. }
  437. };
  438. function onPasswordRequired(callback) {
  439. // password is required
  440. Toolbar.lockLockButton();
  441. var message = '<h2 data-i18n="dialog.passwordRequired">';
  442. message += APP.translation.translateString(
  443. "dialog.passwordRequired");
  444. message += '</h2>' +
  445. '<input name="lockKey" type="text" data-i18n=' +
  446. '"[placeholder]dialog.password" placeholder="' +
  447. APP.translation.translateString("dialog.password") +
  448. '" autofocus>';
  449. messageHandler.openTwoButtonDialog(null, null, null, message,
  450. true,
  451. "dialog.Ok",
  452. function (e, v, m, f) {},
  453. null,
  454. function (e, v, m, f) {
  455. if (v) {
  456. var lockKey = f.lockKey;
  457. if (lockKey) {
  458. Toolbar.setSharedKey(lockKey);
  459. callback(lockKey);
  460. }
  461. }
  462. },
  463. ':input:first'
  464. );
  465. }
  466. /**
  467. * The dialpad button is shown iff there is at least one member that supports
  468. * DTMF (e.g. jigasi).
  469. */
  470. function onDtmfSupportChanged(dtmfSupport) {
  471. //TODO: enable when the UI is ready
  472. //Toolbar.showDialPadButton(dtmfSupport);
  473. }
  474. function onMucMemberJoined(jid, id, displayName) {
  475. messageHandler.notify(displayName,'notify.somebody',
  476. 'connected',
  477. 'notify.connected');
  478. if(!config.startAudioMuted ||
  479. config.startAudioMuted > APP.members.size())
  480. UIUtil.playSoundNotification('userJoined');
  481. // Add Peer's container
  482. VideoLayout.ensurePeerContainerExists(jid,id);
  483. }
  484. function onMucPresenceStatus( jid, info) {
  485. VideoLayout.setPresenceStatus(
  486. 'participant_' + Strophe.getResourceFromJid(jid), info.status);
  487. }
  488. function onMucRoleChanged(role, displayName) {
  489. VideoLayout.showModeratorIndicator();
  490. if (role === 'moderator') {
  491. var messageKey, messageOptions = {};
  492. if (!displayName) {
  493. messageKey = "notify.grantedToUnknown";
  494. }
  495. else
  496. {
  497. messageKey = "notify.grantedTo";
  498. messageOptions = {to: displayName};
  499. }
  500. messageHandler.notify(
  501. displayName,'notify.somebody',
  502. 'connected', messageKey,
  503. messageOptions);
  504. }
  505. }
  506. function onAuthenticationRequired(intervalCallback) {
  507. Authentication.openAuthenticationDialog(
  508. roomName, intervalCallback, function () {
  509. Toolbar.authenticateClicked();
  510. });
  511. };
  512. function onLastNChanged(oldValue, newValue) {
  513. if (config.muteLocalVideoIfNotInLastN) {
  514. setVideoMute(!newValue, { 'byUser': false });
  515. }
  516. }
  517. UI.toggleSmileys = function () {
  518. Chat.toggleSmileys();
  519. };
  520. UI.getSettings = function () {
  521. return Settings.getSettings();
  522. };
  523. UI.toggleFilmStrip = function () {
  524. return BottomToolbar.toggleFilmStrip();
  525. };
  526. UI.toggleChat = function () {
  527. return BottomToolbar.toggleChat();
  528. };
  529. UI.toggleContactList = function () {
  530. return BottomToolbar.toggleContactList();
  531. };
  532. UI.inputDisplayNameHandler = function (value) {
  533. VideoLayout.inputDisplayNameHandler(value);
  534. };
  535. UI.getLargeVideoState = function()
  536. {
  537. return VideoLayout.getLargeVideoState();
  538. };
  539. UI.generateRoomName = function() {
  540. if(roomName)
  541. return roomName;
  542. var roomnode = null;
  543. var path = window.location.pathname;
  544. // determinde the room node from the url
  545. // TODO: just the roomnode or the whole bare jid?
  546. if (config.getroomnode && typeof config.getroomnode === 'function') {
  547. // custom function might be responsible for doing the pushstate
  548. roomnode = config.getroomnode(path);
  549. } else {
  550. /* fall back to default strategy
  551. * this is making assumptions about how the URL->room mapping happens.
  552. * It currently assumes deployment at root, with a rewrite like the
  553. * following one (for nginx):
  554. location ~ ^/([a-zA-Z0-9]+)$ {
  555. rewrite ^/(.*)$ / break;
  556. }
  557. */
  558. if (path.length > 1) {
  559. roomnode = path.substr(1).toLowerCase();
  560. } else {
  561. var word = RoomNameGenerator.generateRoomWithoutSeparator();
  562. roomnode = word.toLowerCase();
  563. window.history.pushState('VideoChat',
  564. 'Room: ' + word, window.location.pathname + word);
  565. }
  566. }
  567. roomName = roomnode + '@' + config.hosts.muc;
  568. return roomName;
  569. };
  570. UI.connectionIndicatorShowMore = function(id)
  571. {
  572. return VideoLayout.connectionIndicators[id].showMore();
  573. };
  574. UI.showLoginPopup = function(callback)
  575. {
  576. console.log('password is required');
  577. var message = '<h2 data-i18n="dialog.passwordRequired">';
  578. message += APP.translation.translateString(
  579. "dialog.passwordRequired");
  580. message += '</h2>' +
  581. '<input name="username" type="text" ' +
  582. 'placeholder="user@domain.net" autofocus>' +
  583. '<input name="password" ' +
  584. 'type="password" data-i18n="[placeholder]dialog.userPassword"' +
  585. ' placeholder="user password">';
  586. UI.messageHandler.openTwoButtonDialog(null, null, null, message,
  587. true,
  588. "dialog.Ok",
  589. function (e, v, m, f) {
  590. if (v) {
  591. if (f.username !== null && f.password != null) {
  592. callback(f.username, f.password);
  593. }
  594. }
  595. },
  596. null, null, ':input:first'
  597. );
  598. }
  599. UI.checkForNicknameAndJoin = function () {
  600. Authentication.closeAuthenticationDialog();
  601. Authentication.stopInterval();
  602. var nick = null;
  603. if (config.useNicks) {
  604. nick = window.prompt('Your nickname (optional)');
  605. }
  606. APP.xmpp.joinRoom(roomName, config.useNicks, nick);
  607. };
  608. function dump(elem, filename) {
  609. elem = elem.parentNode;
  610. elem.download = filename || 'meetlog.json';
  611. elem.href = 'data:application/json;charset=utf-8,\n';
  612. var data = APP.xmpp.populateData();
  613. var metadata = {};
  614. metadata.time = new Date();
  615. metadata.url = window.location.href;
  616. metadata.ua = navigator.userAgent;
  617. var log = APP.xmpp.getLogger();
  618. if (log) {
  619. metadata.xmpp = log;
  620. }
  621. data.metadata = metadata;
  622. elem.href += encodeURIComponent(JSON.stringify(data, null, ' '));
  623. return false;
  624. }
  625. UI.getRoomName = function () {
  626. return roomName;
  627. };
  628. UI.setInitialMuteFromFocus = function (muteAudio, muteVideo) {
  629. if(muteAudio || muteVideo) notifyForInitialMute();
  630. if(muteAudio) UI.setAudioMuted(true);
  631. if(muteVideo) UI.setVideoMute(true);
  632. }
  633. /**
  634. * Mutes/unmutes the local video.
  635. */
  636. UI.toggleVideo = function () {
  637. setVideoMute(!APP.RTC.localVideo.isMuted());
  638. };
  639. /**
  640. * Mutes / unmutes audio for the local participant.
  641. */
  642. UI.toggleAudio = function() {
  643. UI.setAudioMuted(!APP.RTC.localAudio.isMuted());
  644. };
  645. /**
  646. * Sets muted audio state for the local participant.
  647. */
  648. UI.setAudioMuted = function (mute, earlyMute) {
  649. var audioMute = null;
  650. if(earlyMute)
  651. audioMute = function (mute, cb) {
  652. return APP.xmpp.sendAudioInfoPresence(mute, cb);
  653. };
  654. else
  655. audioMute = function (mute, cb) {
  656. return APP.xmpp.setAudioMute(mute, cb);
  657. }
  658. if(!audioMute(mute, function () {
  659. VideoLayout.showLocalAudioIndicator(mute);
  660. UIUtil.buttonClick("#mute", "icon-microphone icon-mic-disabled");
  661. }))
  662. {
  663. // We still click the button.
  664. UIUtil.buttonClick("#mute", "icon-microphone icon-mic-disabled");
  665. return;
  666. }
  667. }
  668. UI.addListener = function (type, listener) {
  669. eventEmitter.on(type, listener);
  670. }
  671. UI.clickOnVideo = function (videoNumber) {
  672. var remoteVideos = $(".videocontainer:not(#mixedstream)");
  673. if (remoteVideos.length > videoNumber) {
  674. remoteVideos[videoNumber].click();
  675. }
  676. }
  677. //Used by torture
  678. UI.showToolbar = function () {
  679. return ToolbarToggler.showToolbar();
  680. }
  681. //Used by torture
  682. UI.dockToolbar = function (isDock) {
  683. return ToolbarToggler.dockToolbar(isDock);
  684. }
  685. UI.setVideoMuteButtonsState = function (mute) {
  686. var video = $('#video');
  687. var communicativeClass = "icon-camera";
  688. var muteClass = "icon-camera icon-camera-disabled";
  689. if (mute) {
  690. video.removeClass(communicativeClass);
  691. video.addClass(muteClass);
  692. } else {
  693. video.removeClass(muteClass);
  694. video.addClass(communicativeClass);
  695. }
  696. }
  697. UI.setVideoMute = setVideoMute;
  698. module.exports = UI;