123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580 |
- var UI = {};
-
- var VideoLayout = require("./videolayout/VideoLayout.js");
- var AudioLevels = require("./audio_levels/AudioLevels.js");
- var Prezi = require("./prezi/Prezi.js");
- var Etherpad = require("./etherpad/Etherpad.js");
- var Chat = require("./side_pannels/chat/Chat.js");
- var Toolbar = require("./toolbars/toolbar");
- var ToolbarToggler = require("./toolbars/toolbartoggler");
- var BottomToolbar = require("./toolbars/BottomToolbar");
- var ContactList = require("./side_pannels/contactlist/ContactList");
- var Avatar = require("./avatar/Avatar");
- //var EventEmitter = require("events");
- var SettingsMenu = require("./side_pannels/settings/SettingsMenu");
- var Settings = require("./side_pannels/settings/Settings");
- var PanelToggler = require("./side_pannels/SidePanelToggler");
- var RoomNameGenerator = require("./welcome_page/RoomnameGenerator");
- UI.messageHandler = require("./util/MessageHandler");
- var messageHandler = UI.messageHandler;
-
- //var eventEmitter = new EventEmitter();
-
-
-
- function setupPrezi()
- {
- $("#reloadPresentationLink").click(function()
- {
- Prezi.reloadPresentation();
- });
- }
-
- function setupChat()
- {
- Chat.init();
- $("#toggle_smileys").click(function() {
- Chat.toggleSmileys();
- });
- }
-
- function setupToolbars() {
- Toolbar.init();
- Toolbar.setupButtonsFromConfig();
- BottomToolbar.init();
- }
-
-
- function registerListeners() {
- RTC.addStreamListener(function (stream) {
- switch (stream.type)
- {
- case "audio":
- VideoLayout.changeLocalAudio(stream.getOriginalStream());
- break;
- case "video":
- VideoLayout.changeLocalVideo(stream.getOriginalStream(), true);
- break;
- case "stream":
- VideoLayout.changeLocalStream(stream.getOriginalStream());
- break;
- case "desktop":
- VideoLayout.changeLocalVideo(stream, !isUsingScreenStream);
- break;
- }
- }, StreamEventTypes.EVENT_TYPE_LOCAL_CREATED);
-
- RTC.addStreamListener(function (stream) {
- VideoLayout.onRemoteStreamAdded(stream);
- }, StreamEventTypes.EVENT_TYPE_REMOTE_CREATED);
-
- // Listen for large video size updates
- document.getElementById('largeVideo')
- .addEventListener('loadedmetadata', function (e) {
- currentVideoWidth = this.videoWidth;
- currentVideoHeight = this.videoHeight;
- VideoLayout.positionLarge(currentVideoWidth, currentVideoHeight);
- });
-
-
- statistics.addAudioLevelListener(function(jid, audioLevel)
- {
- var resourceJid;
- if(jid === statistics.LOCAL_JID)
- {
- resourceJid = AudioLevels.LOCAL_LEVEL;
- if(RTC.localAudio.isMuted())
- {
- audioLevel = 0;
- }
- }
- else
- {
- resourceJid = Strophe.getResourceFromJid(jid);
- }
-
- AudioLevels.updateAudioLevel(resourceJid, audioLevel,
- UI.getLargeVideoState().userResourceJid);
- });
-
- }
-
- function bindEvents()
- {
- /**
- * Resizes and repositions videos in full screen mode.
- */
- $(document).on('webkitfullscreenchange mozfullscreenchange fullscreenchange',
- function () {
- VideoLayout.resizeLargeVideoContainer();
- VideoLayout.positionLarge();
- isFullScreen = document.fullScreen ||
- document.mozFullScreen ||
- document.webkitIsFullScreen;
-
- }
- );
-
- $(window).resize(function () {
- VideoLayout.resizeLargeVideoContainer();
- VideoLayout.positionLarge();
- });
- }
-
- UI.start = function () {
- document.title = interfaceConfig.APP_NAME;
- if(config.enableWelcomePage && window.location.pathname == "/" &&
- (!window.localStorage.welcomePageDisabled || window.localStorage.welcomePageDisabled == "false"))
- {
- $("#videoconference_page").hide();
- var setupWelcomePage = require("./welcome_page/WelcomePage");
- setupWelcomePage();
-
- return;
- }
-
- if (interfaceConfig.SHOW_JITSI_WATERMARK) {
- var leftWatermarkDiv
- = $("#largeVideoContainer div[class='watermark leftwatermark']");
-
- leftWatermarkDiv.css({display: 'block'});
- leftWatermarkDiv.parent().get(0).href
- = interfaceConfig.JITSI_WATERMARK_LINK;
- }
-
- if (interfaceConfig.SHOW_BRAND_WATERMARK) {
- var rightWatermarkDiv
- = $("#largeVideoContainer div[class='watermark rightwatermark']");
-
- rightWatermarkDiv.css({display: 'block'});
- rightWatermarkDiv.parent().get(0).href
- = interfaceConfig.BRAND_WATERMARK_LINK;
- rightWatermarkDiv.get(0).style.backgroundImage
- = "url(images/rightwatermark.png)";
- }
-
- if (interfaceConfig.SHOW_POWERED_BY) {
- $("#largeVideoContainer>a[class='poweredby']").css({display: 'block'});
- }
-
- $("#welcome_page").hide();
-
- $('body').popover({ selector: '[data-toggle=popover]',
- trigger: 'click hover',
- content: function() {
- return this.getAttribute("content") +
- KeyboardShortcut.getShortcut(this.getAttribute("shortcut"));
- }
- });
- VideoLayout.resizeLargeVideoContainer();
- $("#videospace").mousemove(function () {
- return ToolbarToggler.showToolbar();
- });
- // Set the defaults for prompt dialogs.
- jQuery.prompt.setDefaults({persistent: false});
-
- // KeyboardShortcut.init();
- registerListeners();
- bindEvents();
- setupPrezi();
- setupToolbars();
- setupChat();
-
- document.title = interfaceConfig.APP_NAME;
-
- $("#downloadlog").click(function (event) {
- dump(event.target);
- });
-
- if(config.enableWelcomePage && window.location.pathname == "/" &&
- (!window.localStorage.welcomePageDisabled || window.localStorage.welcomePageDisabled == "false"))
- {
- $("#videoconference_page").hide();
- var setupWelcomePage = require("./welcome_page/WelcomePage");
- setupWelcomePage();
-
- return;
- }
-
- $("#welcome_page").hide();
-
- document.getElementById('largeVideo').volume = 0;
-
- if (!$('#settings').is(':visible')) {
- console.log('init');
- init();
- } else {
- loginInfo.onsubmit = function (e) {
- if (e.preventDefault) e.preventDefault();
- $('#settings').hide();
- init();
- };
- }
-
- toastr.options = {
- "closeButton": true,
- "debug": false,
- "positionClass": "notification-bottom-right",
- "onclick": null,
- "showDuration": "300",
- "hideDuration": "1000",
- "timeOut": "2000",
- "extendedTimeOut": "1000",
- "showEasing": "swing",
- "hideEasing": "linear",
- "showMethod": "fadeIn",
- "hideMethod": "fadeOut",
- "reposition": function() {
- if(PanelToggler.isVisible()) {
- $("#toast-container").addClass("notification-bottom-right-center");
- } else {
- $("#toast-container").removeClass("notification-bottom-right-center");
- }
- },
- "newestOnTop": false
- };
-
- $('#settingsmenu>input').keyup(function(event){
- if(event.keyCode === 13) {//enter
- SettingsMenu.update();
- }
- });
-
- $("#updateSettings").click(function () {
- SettingsMenu.update();
- });
-
- };
-
-
- UI.setUserAvatar = function (jid, id) {
- Avatar.setUserAvatar(jid, id);
- };
-
- UI.toggleSmileys = function () {
- Chat.toggleSmileys();
- };
-
- UI.chatAddError = function(errorMessage, originalText)
- {
- return Chat.chatAddError(errorMessage, originalText);
- };
-
- UI.chatSetSubject = function(text)
- {
- return Chat.chatSetSubject(text);
- };
-
- UI.updateChatConversation = function (from, displayName, message) {
- return Chat.updateChatConversation(from, displayName, message);
- };
-
- UI.onMucJoined = function (jid, info) {
- Toolbar.updateRoomUrl(window.location.href);
- document.getElementById('localNick').appendChild(
- document.createTextNode(Strophe.getResourceFromJid(jid) + ' (me)')
- );
-
- var settings = Settings.getSettings();
- // Add myself to the contact list.
- ContactList.addContact(jid, settings.email || settings.uid);
-
- // Once we've joined the muc show the toolbar
- ToolbarToggler.showToolbar();
-
- // Show authenticate button if needed
- Toolbar.showAuthenticateButton(
- Moderator.isExternalAuthEnabled() && !Moderator.isModerator());
-
- var displayName = !config.displayJids
- ? info.displayName : Strophe.getResourceFromJid(jid);
-
- if (displayName)
- $(document).trigger('displaynamechanged',
- ['localVideoContainer', displayName + ' (me)']);
- };
-
- UI.initEtherpad = function (name) {
- Etherpad.init(name);
- };
-
- UI.onMucLeft = function (jid) {
- console.log('left.muc', jid);
- var displayName = $('#participant_' + Strophe.getResourceFromJid(jid) +
- '>.displayname').html();
- messageHandler.notify(displayName || 'Somebody',
- 'disconnected',
- 'disconnected');
- // Need to call this with a slight delay, otherwise the element couldn't be
- // found for some reason.
- // XXX(gp) it works fine without the timeout for me (with Chrome 38).
- window.setTimeout(function () {
- var container = document.getElementById(
- 'participant_' + Strophe.getResourceFromJid(jid));
- if (container) {
- ContactList.removeContact(jid);
- VideoLayout.removeConnectionIndicator(jid);
- // hide here, wait for video to close before removing
- $(container).hide();
- VideoLayout.resizeThumbnails();
- }
- }, 10);
-
- // Unlock large video
- if (focusedVideoInfo && focusedVideoInfo.jid === jid)
- {
- console.info("Focused video owner has left the conference");
- focusedVideoInfo = null;
- }
-
- };
-
- UI.getSettings = function () {
- return Settings.getSettings();
- };
-
- UI.toggleFilmStrip = function () {
- return BottomToolbar.toggleFilmStrip();
- };
-
- UI.toggleChat = function () {
- return BottomToolbar.toggleChat();
- };
-
- UI.toggleContactList = function () {
- return BottomToolbar.toggleContactList();
- };
-
- UI.onLocalRoleChange = function (jid, info, pres) {
-
- console.info("My role changed, new role: " + info.role);
- var isModerator = Moderator.isModerator();
-
- VideoLayout.showModeratorIndicator();
- Toolbar.showAuthenticateButton(
- Moderator.isExternalAuthEnabled() && !isModerator);
-
- if (isModerator) {
- Toolbar.closeAuthenticationWindow();
- messageHandler.notify(
- 'Me', 'connected', 'Moderator rights granted !');
- }
- };
-
- UI.onDisposeConference = function (unload) {
- Toolbar.showAuthenticateButton(false);
- };
-
- UI.onModeratorStatusChanged = function (isModerator) {
-
- Toolbar.showSipCallButton(isModerator);
- Toolbar.showRecordingButton(
- isModerator); //&&
- // FIXME:
- // Recording visible if
- // there are at least 2(+ 1 focus) participants
- //Object.keys(connection.emuc.members).length >= 3);
-
- if (isModerator && config.etherpad_base) {
- Etherpad.init();
- }
- };
-
- UI.onPasswordReqiured = function (callback) {
- // password is required
- Toolbar.lockLockButton();
-
- messageHandler.openTwoButtonDialog(null,
- '<h2>Password required</h2>' +
- '<input id="lockKey" type="text" placeholder="password" autofocus>',
- true,
- "Ok",
- function (e, v, m, f) {},
- function (event) {
- document.getElementById('lockKey').focus();
- },
- function (e, v, m, f) {
- if (v) {
- var lockKey = document.getElementById('lockKey');
- if (lockKey.value !== null) {
- Toolbar.setSharedKey(lockKey.value);
- callback(lockKey.value);
- }
- }
- }
- );
- };
-
- UI.onAuthenticationRequired = function () {
- // This is the loop that will wait for the room to be created by
- // someone else. 'auth_required.moderator' will bring us back here.
- authRetryId = window.setTimeout(
- function () {
- Moderator.allocateConferenceFocus(roomName, doJoinAfterFocus);
- }, 5000);
- // Show prompt only if it's not open
- if (authDialog !== null) {
- return;
- }
- // extract room name from 'room@muc.server.net'
- var room = roomName.substr(0, roomName.indexOf('@'));
-
- authDialog = messageHandler.openDialog(
- 'Stop',
- 'Authentication is required to create room:<br/><b>' + room +
- '</b></br> You can either authenticate to create the room or ' +
- 'just wait for someone else to do so.',
- true,
- {
- Authenticate: 'authNow'
- },
- function (onSubmitEvent, submitValue) {
-
- // Do not close the dialog yet
- onSubmitEvent.preventDefault();
-
- // Open login popup
- if (submitValue === 'authNow') {
- Toolbar.authenticateClicked();
- }
- }
- );
- };
-
- UI.setRecordingButtonState = function (state) {
- Toolbar.setRecordingButtonState(state);
- };
-
- UI.changeDesktopSharingButtonState = function (isUsingScreenStream) {
- Toolbar.changeDesktopSharingButtonState(isUsingScreenStream);
- };
-
- UI.inputDisplayNameHandler = function (value) {
- VideoLayout.inputDisplayNameHandler(value);
- };
-
- UI.onMucEntered = function (jid, id, displayName) {
- messageHandler.notify(displayName || 'Somebody',
- 'connected',
- 'connected');
-
- // Add Peer's container
- VideoLayout.ensurePeerContainerExists(jid,id);
- };
-
- UI.onMucPresenceStatus = function ( jid, info) {
- VideoLayout.setPresenceStatus(
- 'participant_' + Strophe.getResourceFromJid(jid), info.status);
- };
-
- UI.onMucRoleChanged = function (role, displayName) {
- VideoLayout.showModeratorIndicator();
-
- if (role === 'moderator') {
- var displayName = displayName;
- if (!displayName) {
- displayName = 'Somebody';
- }
- messageHandler.notify(
- displayName,
- 'connected',
- 'Moderator rights granted to ' + displayName + '!');
- }
- };
-
- UI.updateLocalConnectionStats = function(percent, stats)
- {
- VideoLayout.updateLocalConnectionStats(percent, stats);
- };
-
- UI.updateConnectionStats = function(jid, percent, stats)
- {
- VideoLayout.updateConnectionStats(jid, percent, stats);
- };
-
- UI.onStatsStop = function () {
- VideoLayout.onStatsStop();
- };
-
- UI.getLargeVideoState = function()
- {
- return VideoLayout.getLargeVideoState();
- };
-
- UI.showLocalAudioIndicator = function (mute) {
- VideoLayout.showLocalAudioIndicator(mute);
- };
-
- UI.changeLocalVideo = function (stream, flipx) {
- VideoLayout.changeLocalVideo(stream, flipx);
- };
-
- UI.generateRoomName = function() {
- var roomnode = null;
- var path = window.location.pathname;
-
- // determinde the room node from the url
- // TODO: just the roomnode or the whole bare jid?
- if (config.getroomnode && typeof config.getroomnode === 'function') {
- // custom function might be responsible for doing the pushstate
- roomnode = config.getroomnode(path);
- } else {
- /* fall back to default strategy
- * this is making assumptions about how the URL->room mapping happens.
- * It currently assumes deployment at root, with a rewrite like the
- * following one (for nginx):
- location ~ ^/([a-zA-Z0-9]+)$ {
- rewrite ^/(.*)$ / break;
- }
- */
- if (path.length > 1) {
- roomnode = path.substr(1).toLowerCase();
- } else {
- var word = RoomNameGenerator.generateRoomWithoutSeparator();
- roomnode = word.toLowerCase();
-
- window.history.pushState('VideoChat',
- 'Room: ' + word, window.location.pathname + word);
- }
- }
-
- roomName = roomnode + '@' + config.hosts.muc;
- };
-
-
- UI.connectionIndicatorShowMore = function(id)
- {
- return VideoLayout.connectionIndicators[id].showMore();
- };
-
- UI.showToolbar = function () {
- return ToolbarToggler.showToolbar();
- };
-
- UI.dockToolbar = function (isDock) {
- return ToolbarToggler.dockToolbar(isDock);
- };
-
-
- function dump(elem, filename) {
- elem = elem.parentNode;
- elem.download = filename || 'meetlog.json';
- elem.href = 'data:application/json;charset=utf-8,\n';
- var data = {};
- if (connection.jingle) {
- data = connection.jingle.populateData();
- }
- var metadata = {};
- metadata.time = new Date();
- metadata.url = window.location.href;
- metadata.ua = navigator.userAgent;
- if (connection.logger) {
- metadata.xmpp = connection.logger.log;
- }
- data.metadata = metadata;
- elem.href += encodeURIComponent(JSON.stringify(data, null, ' '));
- return false;
- }
-
- module.exports = UI;
|