| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446 | 
							- /* global $, JitsiMeetJS, config, interfaceConfig */
 - /* application specific logic */
 - 
 - import "babel-polyfill";
 - import "jquery";
 - import "jquery-ui";
 - import "strophe";
 - import "strophe-disco";
 - import "strophe-caps";
 - import "tooltip";
 - import "popover";
 - import "jQuery-Impromptu";
 - import "autosize";
 - window.toastr = require("toastr");
 - 
 - import RoomnameGenerator from './modules/util/RoomnameGenerator';
 - import CQEvents from './service/connectionquality/CQEvents';
 - import UIEvents from './service/UI/UIEvents';
 - 
 - const Commands = {
 -     CONNECTION_QUALITY: "connectionQuality",
 -     EMAIL: "email"
 - };
 - 
 - function buildRoomName () {
 -     let path = window.location.pathname;
 -     let roomName;
 - 
 -     // 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
 -         roomName = 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) {
 -             roomName = path.substr(1).toLowerCase();
 -         } else {
 -             let word = RoomnameGenerator.generateRoomWithoutSeparator();
 -             roomName = word.toLowerCase();
 -             window.history.pushState(
 -                 'VideoChat', `Room: ${word}`, window.location.pathname + word
 -             );
 -         }
 -     }
 - 
 -     return roomName;
 - }
 - 
 - const APP = {
 -     init () {
 -         let roomName = buildRoomName();
 -         this.conference = {
 -             roomName,
 -             localId: undefined,
 -             isModerator: false,
 -             membersCount: 0,
 -             audioMuted: false,
 -             videoMuted: false,
 -             isLocalId (id) {
 -                 return this.localId === id;
 -             },
 -             muteAudio (mute) {
 -                 APP.UI.eventEmitter.emit(UIEvents.AUDIO_MUTED, mute);
 -             },
 -             toggleAudioMuted () {
 -                 this.muteAudio(!this.audioMuted);
 -             },
 -             muteVideo (mute) {
 -                 APP.UI.eventEmitter.emit(UIEvents.VIDEO_MUTED, mute);
 -             },
 -             toggleVideoMuted () {
 -                 this.muteVideo(!this.videoMuted);
 -             }
 -         };
 - 
 -         this.UI = require("./modules/UI/UI");
 -         this.API = require("./modules/API/API");
 -         this.connectionquality =
 -             require("./modules/connectionquality/connectionquality");
 -         this.statistics = require("./modules/statistics/statistics");
 -         this.desktopsharing =
 -             require("./modules/desktopsharing/desktopsharing");
 -         this.keyboardshortcut =
 -             require("./modules/keyboardshortcut/keyboardshortcut");
 -         this.translation = require("./modules/translation/translation");
 -         this.settings = require("./modules/settings/Settings");
 -         this.configFetch = require("./modules/config/HttpConfigFetch");
 -     }
 - };
 - 
 - 
 - var ConnectionEvents = JitsiMeetJS.events.connection;
 - var ConnectionErrors = JitsiMeetJS.errors.connection;
 - function connect() {
 -     var connection = new JitsiMeetJS.JitsiConnection(null, null, {
 -         hosts: config.hosts,
 -         bosh: config.bosh,
 -         clientNode: config.clientNode
 -     });
 - 
 -     return new Promise(function (resolve, reject) {
 -         var handlers = {};
 - 
 -         var unsubscribe = function () {
 -             Object.keys(handlers).forEach(function (event) {
 -                 connection.removeEventListener(event, handlers[event]);
 -             });
 -         };
 - 
 -         handlers[ConnectionEvents.CONNECTION_ESTABLISHED] = function () {
 -             console.log('CONNECTED');
 -             unsubscribe();
 -             resolve(connection);
 -         };
 - 
 -         var listenForFailure = function (event) {
 -             handlers[event] = function (...args) {
 -                 console.error(`CONNECTION FAILED: ${event}`, ...args);
 - 
 -                 unsubscribe();
 -                 reject([event, ...args]);
 -             };
 -         };
 - 
 -         listenForFailure(ConnectionEvents.CONNECTION_FAILED);
 -         listenForFailure(ConnectionErrors.PASSWORD_REQUIRED);
 -         listenForFailure(ConnectionErrors.CONNECTION_ERROR);
 -         listenForFailure(ConnectionErrors.OTHER_ERRORS);
 - 
 -         // install event listeners
 -         Object.keys(handlers).forEach(function (event) {
 -             connection.addEventListener(event, handlers[event]);
 -         });
 - 
 -         connection.connect();
 -     }).catch(function (err) {
 -         if (err[0] === ConnectionErrors.PASSWORD_REQUIRED) {
 -             // FIXME ask for password and try again
 -             return connect();
 -         }
 -         console.error('FAILED TO CONNECT', err);
 -         APP.UI.notifyConnectionFailed(err[1]);
 - 
 -         throw new Error(err[0]);
 -     });
 - }
 - 
 - var ConferenceEvents = JitsiMeetJS.events.conference;
 - var ConferenceErrors = JitsiMeetJS.errors.conference;
 - function initConference(localTracks, connection) {
 -     var room = connection.initJitsiConference(APP.conference.roomName, {
 -         openSctp: config.openSctp,
 -         disableAudioLevels: config.disableAudioLevels
 -     });
 - 
 -     var users = {};
 - 
 -     APP.conference.localId = room.myUserId();
 -     Object.defineProperty(APP.conference, "membersCount", {
 -         get: function () {
 -             return Object.keys(users).length; // FIXME maybe +1?
 -         }
 -     });
 - 
 -     function getDisplayName(id) {
 -         if (APP.conference.isLocalId(id)) {
 -             return APP.settings.getDisplayName();
 -         }
 - 
 -         var user = users[id];
 -         if (user && user.displayName) {
 -             return user.displayName;
 -         }
 -     }
 - 
 -     // add local streams when joined to the conference
 -     room.on(ConferenceEvents.CONFERENCE_JOINED, function () {
 -         localTracks.forEach(function (track) {
 -             room.addTrack(track);
 -             APP.UI.addLocalStream(track);
 -         });
 -     });
 - 
 - 
 -     room.on(ConferenceEvents.USER_JOINED, function (id) {
 -         users[id] = {
 -             displayName: undefined,
 -             tracks: []
 -         };
 -         // FIXME email???
 -         APP.UI.addUser(id);
 -     });
 -     room.on(ConferenceEvents.USER_LEFT, function (id) {
 -         delete users[id];
 -         APP.UI.removeUser(id);
 -     });
 - 
 - 
 -     room.on(ConferenceEvents.TRACK_MUTE_CHANGED, function (track) {
 -         // FIXME handle mute
 -     });
 -     room.on(ConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED, function (id, lvl) {
 -         APP.UI.setAudioLevel(id, lvl);
 -     });
 -     APP.UI.addListener(UIEvents.AUDIO_MUTED, function (muted) {
 -         // FIXME mute or unmute
 -         APP.UI.setAudioMuted(muted);
 -         APP.conference.audioMuted = muted;
 -     });
 -     APP.UI.addListener(UIEvents.VIDEO_MUTED, function (muted) {
 -         // FIXME mute or unmute
 -         APP.UI.setVideoMuted(muted);
 -         APP.conference.videoMuted = muted;
 -     });
 - 
 - 
 -     room.on(ConferenceEvents.IN_LAST_N_CHANGED, function (inLastN) {
 -         if (config.muteLocalVideoIfNotInLastN) {
 -             // TODO mute or unmute if required
 -             // mark video on UI
 -             // APP.UI.markVideoMuted(true/false);
 -         }
 -     });
 -     room.on(ConferenceEvents.LAST_N_ENDPOINTS_CHANGED, function (ids) {
 -         APP.UI.handleLastNEndpoints(ids);
 -     });
 -     room.on(ConferenceEvents.ACTIVE_SPEAKER_CHANGED, function (id) {
 -         APP.UI.markDominantSpiker(id);
 -     });
 - 
 - 
 -     if (!interfaceConfig.filmStripOnly) {
 -         room.on(ConferenceEvents.CONNECTION_INTERRUPTED, function () {
 -             APP.UI.markVideoInterrupted(true);
 -         });
 -         room.on(ConferenceEvents.CONNECTION_RESTORED, function () {
 -             APP.UI.markVideoInterrupted(false);
 -         });
 - 
 -         APP.UI.addListener(UIEvents.MESSAGE_CREATED, function (message) {
 -             room.sendTextMessage(message);
 -         });
 -         room.on(ConferenceEvents.MESSAGE_RECEIVED, function (userId, text) {
 -             APP.UI.addMessage(userId, getDisplayName(userId), text, Date.now());
 -         });
 -     }
 - 
 -     APP.connectionquality.addListener(
 -         CQEvents.LOCALSTATS_UPDATED,
 -         function (percent, stats) {
 -             APP.UI.updateLocalStats(percent, stats);
 - 
 -             // send local stats to other users
 -             room.sendCommand(Commands.CONNECTION_QUALITY, {
 -                 value: APP.connectionquality.convertToMUCStats(stats),
 -                 attributes: {
 -                     id: room.myUserId()
 -                 }
 -             });
 -         }
 -     );
 -     APP.connectionquality.addListener(CQEvents.STOP, function () {
 -         APP.UI.hideStats();
 -         room.removeCommand(Commands.CONNECTION_QUALITY);
 -     });
 -     // listen to remote stats
 -     room.addCommandListener(Commands.CONNECTION_QUALITY, function (data) {
 -         APP.connectionquality.updateRemoteStats(data.attributes.id, data.value);
 -     });
 -     APP.connectionquality.addListener(
 -         CQEvents.REMOTESTATS_UPDATED,
 -         function (id, percent, stats) {
 -             APP.UI.updateRemoteStats(id, percent, stats);
 -         }
 -     );
 - 
 - 
 -     // share email with other users
 -     function sendEmail(email) {
 -         room.sendCommand(Commands.EMAIL, {
 -             value: email,
 -             attributes: {
 -                 id: room.myUserId()
 -             }
 -         });
 -     }
 - 
 -     var email = APP.settings.getEmail();
 -     email && sendEmail(email);
 -     APP.UI.addListener(UIEvents.EMAIL_CHANGED, function (email) {
 -         APP.settings.setEmail(email);
 -         APP.UI.setUserAvatar(room.myUserId(), email);
 -         sendEmail(email);
 -     });
 -     room.addCommandListener(Commands.EMAIL, function (data) {
 -         APP.UI.setUserAvatar(data.attributes.id, data.value);
 -     });
 - 
 - 
 -     room.on(ConferenceEvents.DISPLAY_NAME_CHANGED, function (id, displayName) {
 -         APP.UI.changeDisplayName(id, displayName);
 -     });
 -     APP.UI.addListener(UIEvents.NICKNAME_CHANGED, function (nickname) {
 -         APP.settings.setDisplayName(nickname);
 -         room.setDisplayName(nickname);
 -     });
 - 
 -     room.on(ConferenceErrors.PASSWORD_REQUIRED, function () {
 -         // FIXME handle
 -     });
 -     room.on(ConferenceErrors.CONNECTION_ERROR, function () {
 -         // FIXME handle
 -     });
 - 
 -     APP.UI.addListener(
 -         UIEvents.START_MUTED_CHANGED,
 -         function (startAudioMuted, startVideoMuted) {
 -             // FIXME start muted
 -         }
 -     );
 - 
 -     return new Promise(function (resolve, reject) {
 -         room.on(
 -             ConferenceEvents.CONFERENCE_JOINED,
 -             function () {
 -                 resolve();
 -             }
 -         );
 -         APP.UI.closeAuthenticationDialog();
 -         if (config.useNicks) {
 -             // FIXME check this
 -             var nick = APP.UI.askForNickname();
 -         }
 -         room.join();
 -     }).catch(function (err) {
 -         if (err[0] === ConferenceErrors.PASSWORD_REQUIRED) {
 -             // FIXME ask for password and try again
 -             return initConference(localTracks, connection);
 -         }
 - 
 -         // FIXME else notify that we cannot conenct to the room
 - 
 -         throw new Error(err[0]);
 -     });
 - }
 - 
 - function createLocalTracks () {
 -     return JitsiMeetJS.createLocalTracks({
 -         devices: ['audio', 'video']
 -     }).catch(function (err) {
 -         console.error('failed to create local tracks', err);
 -         return [];
 -     });
 - }
 - 
 - function init() {
 -     JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.TRACE);
 -     JitsiMeetJS.init().then(function () {
 -         return Promise.all([createLocalTracks(), connect()]);
 -     }).then(function ([tracks, connection]) {
 -         console.log('initialized with %s local tracks', tracks.length);
 -         return initConference(tracks, connection);
 -     }).then(function () {
 -         APP.UI.start();
 - 
 -         APP.UI.initConference();
 - 
 -         APP.UI.addListener(UIEvents.LANG_CHANGED, function (language) {
 -             APP.translation.setLanguage(language);
 -             APP.settings.setLanguage(language);
 -         });
 - 
 -         APP.desktopsharing.init();
 -         APP.statistics.start();
 -         APP.connectionquality.init();
 -         APP.keyboardshortcut.init();
 -     });
 - }
 - 
 - /**
 -  * If we have an HTTP endpoint for getting config.json configured we're going to
 -  * read it and override properties from config.js and interfaceConfig.js.
 -  * If there is no endpoint we'll just continue with initialization.
 -  * Keep in mind that if the endpoint has been configured and we fail to obtain
 -  * the config for any reason then the conference won't start and error message
 -  * will be displayed to the user.
 -  */
 - function obtainConfigAndInit() {
 -     let roomName = APP.conference.roomName;
 - 
 -     if (config.configLocation) {
 -         APP.configFetch.obtainConfig(
 -             config.configLocation, roomName,
 -             // Get config result callback
 -             function(success, error) {
 -                 if (success) {
 -                     console.log("(TIME) configuration fetched:\t",
 -                                 window.performance.now());
 -                     init();
 -                 } else {
 -                     // Show obtain config error,
 -                     // pass the error object for report
 -                     APP.UI.messageHandler.openReportDialog(
 -                         null, "dialog.connectError", error);
 -                 }
 -             });
 -     } else {
 -         require("./modules/config/BoshAddressChoice").chooseAddress(
 -             config, roomName);
 - 
 -         init();
 -     }
 - }
 - 
 - 
 - $(document).ready(function () {
 -     console.log("(TIME) document ready:\t", window.performance.now());
 - 
 -     var URLProcessor = require("./modules/config/URLProcessor");
 -     URLProcessor.setConfigParametersFromUrl();
 -     APP.init();
 - 
 -     APP.translation.init();
 - 
 -     if (APP.API.isEnabled()) {
 -         APP.API.init();
 -     }
 - 
 -     obtainConfigAndInit();
 - });
 - 
 - $(window).bind('beforeunload', function () {
 -     if (APP.API.isEnabled()) {
 -         APP.API.dispose();
 -     }
 - });
 - 
 - module.exports = APP;
 
 
  |