You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

app.js 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. /* global $, JitsiMeetJS, config, interfaceConfig */
  2. /* application specific logic */
  3. import "babel-polyfill";
  4. import "jquery";
  5. import "jquery-ui";
  6. import "strophe";
  7. import "strophe-disco";
  8. import "strophe-caps";
  9. import "tooltip";
  10. import "popover";
  11. import "jQuery-Impromptu";
  12. import "autosize";
  13. window.toastr = require("toastr");
  14. import URLProcessor from "./modules/config/URLProcessor";
  15. import RoomnameGenerator from './modules/util/RoomnameGenerator';
  16. import CQEvents from './service/connectionquality/CQEvents';
  17. import UIEvents from './service/UI/UIEvents';
  18. import DSEvents from './service/desktopsharing/DesktopSharingEventTypes';
  19. import UI from "./modules/UI/UI";
  20. import statistics from "./modules/statistics/statistics";
  21. import settings from "./modules/settings/Settings";
  22. import {openConnection} from './modules/connection';
  23. import AuthHandler from './modules/AuthHandler';
  24. import createRoomLocker from './modules/RoomLocker';
  25. const ConnectionEvents = JitsiMeetJS.events.connection;
  26. const ConnectionErrors = JitsiMeetJS.errors.connection;
  27. const ConferenceEvents = JitsiMeetJS.events.conference;
  28. const ConferenceErrors = JitsiMeetJS.errors.conference;
  29. let localVideo, localAudio;
  30. const Commands = {
  31. CONNECTION_QUALITY: "connectionQuality",
  32. EMAIL: "email",
  33. VIDEO_TYPE: "videoType",
  34. ETHERPAD: "etherpad",
  35. PREZI: "prezi",
  36. STOP_PREZI: "stop-prezi"
  37. };
  38. function buildRoomName () {
  39. let path = window.location.pathname;
  40. let roomName;
  41. // determinde the room node from the url
  42. // TODO: just the roomnode or the whole bare jid?
  43. if (config.getroomnode && typeof config.getroomnode === 'function') {
  44. // custom function might be responsible for doing the pushstate
  45. roomName = config.getroomnode(path);
  46. } else {
  47. /* fall back to default strategy
  48. * this is making assumptions about how the URL->room mapping happens.
  49. * It currently assumes deployment at root, with a rewrite like the
  50. * following one (for nginx):
  51. location ~ ^/([a-zA-Z0-9]+)$ {
  52. rewrite ^/(.*)$ / break;
  53. }
  54. */
  55. if (path.length > 1) {
  56. roomName = path.substr(1).toLowerCase();
  57. } else {
  58. let word = RoomnameGenerator.generateRoomWithoutSeparator();
  59. roomName = word.toLowerCase();
  60. window.history.pushState(
  61. 'VideoChat', `Room: ${word}`, window.location.pathname + word
  62. );
  63. }
  64. }
  65. return roomName;
  66. }
  67. const APP = {
  68. UI,
  69. statistics,
  70. settings,
  71. createLocalTracks (...devices) {
  72. return JitsiMeetJS.createLocalTracks({
  73. // copy array to avoid mutations inside library
  74. devices: devices.slice(0),
  75. resolution: config.resolution
  76. }).catch(function (err) {
  77. console.error('failed to create local tracks', ...devices, err);
  78. APP.statistics.onGetUserMediaFailed(err);
  79. return [];
  80. });
  81. },
  82. init () {
  83. let roomName = buildRoomName();
  84. this.conference = {
  85. roomName,
  86. localId: undefined,
  87. isModerator: false,
  88. membersCount: 0,
  89. audioMuted: false,
  90. videoMuted: false,
  91. isLocalId (id) {
  92. return this.localId === id;
  93. },
  94. muteAudio (mute) {
  95. APP.UI.eventEmitter.emit(UIEvents.AUDIO_MUTED, mute);
  96. APP.statistics.onAudioMute(mute);
  97. },
  98. toggleAudioMuted () {
  99. this.muteAudio(!this.audioMuted);
  100. },
  101. muteVideo (mute) {
  102. APP.UI.eventEmitter.emit(UIEvents.VIDEO_MUTED, mute);
  103. APP.statistics.onVideoMute(mute);
  104. },
  105. toggleVideoMuted () {
  106. this.muteVideo(!this.videoMuted);
  107. }
  108. };
  109. this.API = require("./modules/API/API");
  110. this.connectionquality =
  111. require("./modules/connectionquality/connectionquality");
  112. this.desktopsharing =
  113. require("./modules/desktopsharing/desktopsharing");
  114. this.keyboardshortcut =
  115. require("./modules/keyboardshortcut/keyboardshortcut");
  116. this.translation = require("./modules/translation/translation");
  117. this.configFetch = require("./modules/config/HttpConfigFetch");
  118. }
  119. };
  120. function initConference(localTracks, connection) {
  121. let options = {
  122. openSctp: config.openSctp,
  123. disableAudioLevels: config.disableAudioLevels
  124. };
  125. if(config.enableRecording) {
  126. options.recordingType = (config.hosts &&
  127. (typeof config.hosts.jirecon != "undefined"))?
  128. "jirecon" : "colibri";
  129. }
  130. let room = connection.initJitsiConference(APP.conference.roomName, options);
  131. APP.conference._room = room; // FIXME do not use this
  132. const addTrack = (track) => {
  133. room.addTrack(track);
  134. if (track.isAudioTrack()) {
  135. return;
  136. }
  137. room.removeCommand(Commands.VIDEO_TYPE);
  138. room.sendCommand(Commands.VIDEO_TYPE, {
  139. value: track.videoType,
  140. attributes: {
  141. xmlns: 'http://jitsi.org/jitmeet/video'
  142. }
  143. });
  144. };
  145. APP.conference.localId = room.myUserId();
  146. Object.defineProperty(APP.conference, "membersCount", {
  147. get: function () {
  148. return room.getParticipants().length; // FIXME maybe +1?
  149. }
  150. });
  151. APP.conference.listMembers = function () {
  152. return room.getParticipants();
  153. };
  154. APP.conference.listMembersIds = function () {
  155. return room.getParticipants().map(p => p.getId());
  156. };
  157. APP.conference.sipGatewayEnabled = () => {
  158. return room.isSIPCallingSupported();
  159. };
  160. function getDisplayName(id) {
  161. if (APP.conference.isLocalId(id)) {
  162. return APP.settings.getDisplayName();
  163. }
  164. let participant = room.getParticipantById(id);
  165. if (participant && participant.getDisplayName()) {
  166. return participant.getDisplayName();
  167. }
  168. }
  169. // add local streams when joined to the conference
  170. room.on(ConferenceEvents.CONFERENCE_JOINED, function () {
  171. localTracks.forEach(function (track) {
  172. if(track.isAudioTrack()) {
  173. localAudio = track;
  174. }
  175. else if (track.isVideoTrack()) {
  176. localVideo = track;
  177. }
  178. addTrack(track);
  179. APP.UI.addLocalStream(track);
  180. });
  181. APP.UI.updateAuthInfo(room.isAuthEnabled(), room.getAuthLogin());
  182. });
  183. room.on(ConferenceEvents.USER_JOINED, function (id, user) {
  184. console.error('USER %s connnected', id, user);
  185. // FIXME email???
  186. APP.UI.addUser(id, user.getDisplayName());
  187. });
  188. room.on(ConferenceEvents.USER_LEFT, function (id, user) {
  189. console.error('USER %s LEFT', id, user);
  190. APP.UI.removeUser(id, user.getDisplayName());
  191. APP.UI.stopPrezi(id);
  192. });
  193. room.on(ConferenceEvents.USER_ROLE_CHANGED, function (id, role) {
  194. if (APP.conference.isLocalId(id)) {
  195. console.info(`My role changed, new role: ${role}`);
  196. APP.conference.isModerator = room.isModerator();
  197. APP.UI.updateLocalRole(room.isModerator());
  198. } else {
  199. let user = room.getParticipantById(id);
  200. if (user) {
  201. APP.UI.updateUserRole(user);
  202. }
  203. }
  204. });
  205. let roomLocker = createRoomLocker(room);
  206. APP.UI.addListener(UIEvents.ROOM_LOCK_CLICKED, function () {
  207. if (room.isModerator()) {
  208. let promise = roomLocker.isLocked
  209. ? roomLocker.askToUnlock()
  210. : roomLocker.askToLock();
  211. promise.then(function () {
  212. APP.UI.markRoomLocked(roomLocker.isLocked);
  213. });
  214. } else {
  215. roomLocker.notifyModeratorRequired();
  216. }
  217. });
  218. room.on(ConferenceEvents.TRACK_ADDED, function (track) {
  219. if (track.isLocal()) { // skip local tracks
  220. return;
  221. }
  222. console.error(
  223. 'REMOTE %s TRACK', track.getType(), track.getParticipantId()
  224. );
  225. APP.UI.addRemoteStream(track);
  226. });
  227. room.on(ConferenceEvents.TRACK_REMOVED, function (track) {
  228. if (track.isLocal()) { // skip local tracks
  229. return;
  230. }
  231. console.error(
  232. 'REMOTE %s TRACK REMOVED', track.getType(), track.getParticipantId()
  233. );
  234. // FIXME handle
  235. });
  236. room.on(ConferenceEvents.TRACK_MUTE_CHANGED, function (track) {
  237. // FIXME handle mute
  238. });
  239. room.on(ConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED, function (id, lvl) {
  240. APP.UI.setAudioLevel(id, lvl);
  241. });
  242. APP.UI.addListener(UIEvents.AUDIO_MUTED, function (muted) {
  243. // FIXME mute or unmute
  244. APP.UI.setAudioMuted(muted);
  245. APP.conference.audioMuted = muted;
  246. });
  247. APP.UI.addListener(UIEvents.VIDEO_MUTED, function (muted) {
  248. // FIXME mute or unmute
  249. APP.UI.setVideoMuted(muted);
  250. APP.conference.videoMuted = muted;
  251. });
  252. room.on(ConferenceEvents.IN_LAST_N_CHANGED, function (inLastN) {
  253. if (config.muteLocalVideoIfNotInLastN) {
  254. // TODO mute or unmute if required
  255. // mark video on UI
  256. // APP.UI.markVideoMuted(true/false);
  257. }
  258. });
  259. room.on(ConferenceEvents.LAST_N_ENDPOINTS_CHANGED, function (ids) {
  260. APP.UI.handleLastNEndpoints(ids);
  261. });
  262. room.on(ConferenceEvents.ACTIVE_SPEAKER_CHANGED, function (id) {
  263. APP.UI.markDominantSpiker(id);
  264. });
  265. if (!interfaceConfig.filmStripOnly) {
  266. room.on(ConferenceEvents.CONNECTION_INTERRUPTED, function () {
  267. APP.UI.markVideoInterrupted(true);
  268. });
  269. room.on(ConferenceEvents.CONNECTION_RESTORED, function () {
  270. APP.UI.markVideoInterrupted(false);
  271. });
  272. APP.UI.addListener(UIEvents.MESSAGE_CREATED, function (message) {
  273. room.sendTextMessage(message);
  274. });
  275. room.on(ConferenceEvents.MESSAGE_RECEIVED, function (id, text, ts) {
  276. APP.UI.addMessage(id, getDisplayName(id), text, ts);
  277. });
  278. }
  279. APP.connectionquality.addListener(
  280. CQEvents.LOCALSTATS_UPDATED,
  281. function (percent, stats) {
  282. APP.UI.updateLocalStats(percent, stats);
  283. // send local stats to other users
  284. room.sendCommand(Commands.CONNECTION_QUALITY, {
  285. value: APP.connectionquality.convertToMUCStats(stats),
  286. attributes: {
  287. id: room.myUserId()
  288. }
  289. });
  290. }
  291. );
  292. APP.connectionquality.addListener(CQEvents.STOP, function () {
  293. APP.UI.hideStats();
  294. room.removeCommand(Commands.CONNECTION_QUALITY);
  295. });
  296. // listen to remote stats
  297. room.addCommandListener(
  298. Commands.CONNECTION_QUALITY,
  299. function ({value, attributes}) {
  300. APP.connectionquality.updateRemoteStats(attributes.id, value);
  301. }
  302. );
  303. APP.connectionquality.addListener(
  304. CQEvents.REMOTESTATS_UPDATED,
  305. function (id, percent, stats) {
  306. APP.UI.updateRemoteStats(id, percent, stats);
  307. }
  308. );
  309. room.addCommandListener(Commands.ETHERPAD, function ({value}) {
  310. APP.UI.initEtherpad(value);
  311. });
  312. room.addCommandListener(Commands.PREZI, function ({value, attributes}) {
  313. APP.UI.showPrezi(attributes.id, value, attributes.slide);
  314. });
  315. room.addCommandListener(Commands.STOP_PREZI, function ({attributes}) {
  316. APP.UI.stopPrezi(attributes.id);
  317. });
  318. APP.UI.addListener(UIEvents.SHARE_PREZI, function (url, slide) {
  319. console.log('Sharing Prezi %s slide %s', url, slide);
  320. room.removeCommand(Commands.PREZI);
  321. room.sendCommand(Commands.PREZI, {
  322. value: url,
  323. attributes: {
  324. id: room.myUserId(),
  325. slide
  326. }
  327. });
  328. });
  329. APP.UI.addListener(UIEvents.STOP_SHARING_PREZI, function () {
  330. room.removeCommand(Commands.PREZI);
  331. room.sendCommandOnce(Commands.STOP_PREZI, {
  332. attributes: {
  333. id: room.myUserId()
  334. }
  335. });
  336. });
  337. room.addCommandListener(Commands.VIDEO_TYPE, ({value}, from) => {
  338. APP.UI.onPeerVideoTypeChanged(from, value);
  339. });
  340. // share email with other users
  341. function sendEmail(email) {
  342. room.sendCommand(Commands.EMAIL, {
  343. value: email,
  344. attributes: {
  345. id: room.myUserId()
  346. }
  347. });
  348. }
  349. let email = APP.settings.getEmail();
  350. email && sendEmail(email);
  351. APP.UI.addListener(UIEvents.EMAIL_CHANGED, function (email) {
  352. APP.settings.setEmail(email);
  353. APP.UI.setUserAvatar(room.myUserId(), email);
  354. sendEmail(email);
  355. });
  356. room.addCommandListener(Commands.EMAIL, function (data) {
  357. APP.UI.setUserAvatar(data.attributes.id, data.value);
  358. });
  359. let nick = APP.settings.getDisplayName();
  360. if (config.useNicks && !nick) {
  361. nick = APP.UI.askForNickname();
  362. APP.settings.setDisplayName(nick);
  363. }
  364. if (nick) {
  365. room.setDisplayName(nick);
  366. }
  367. room.on(ConferenceEvents.DISPLAY_NAME_CHANGED, function (id, displayName) {
  368. APP.UI.changeDisplayName(id, displayName);
  369. });
  370. room.on(ConferenceEvents.RECORDING_STATE_CHANGED, (status, error) => {
  371. if(status == "error") {
  372. console.error(error);
  373. return;
  374. }
  375. APP.UI.updateRecordingState(status);
  376. });
  377. APP.UI.addListener(UIEvents.NICKNAME_CHANGED, function (nickname) {
  378. APP.settings.setDisplayName(nickname);
  379. room.setDisplayName(nickname);
  380. APP.UI.changeDisplayName(APP.conference.localId, nickname);
  381. });
  382. APP.UI.addListener(
  383. UIEvents.START_MUTED_CHANGED,
  384. function (startAudioMuted, startVideoMuted) {
  385. // FIXME start muted
  386. }
  387. );
  388. APP.UI.addListener(UIEvents.USER_INVITED, function (roomUrl) {
  389. APP.UI.inviteParticipants(
  390. roomUrl,
  391. APP.conference.roomName,
  392. roomLocker.password,
  393. APP.settings.getDisplayName()
  394. );
  395. });
  396. // call hangup
  397. APP.UI.addListener(UIEvents.HANGUP, function () {
  398. APP.UI.requestFeedback().then(function () {
  399. connection.disconnect();
  400. if (config.enableWelcomePage) {
  401. setTimeout(function() {
  402. window.localStorage.welcomePageDisabled = false;
  403. window.location.pathname = "/";
  404. }, 3000);
  405. }
  406. }, function (err) {
  407. console.error(err);
  408. });
  409. });
  410. // logout
  411. APP.UI.addListener(UIEvents.LOGOUT, function () {
  412. // FIXME handle logout
  413. // APP.xmpp.logout(function (url) {
  414. // if (url) {
  415. // window.location.href = url;
  416. // } else {
  417. // hangup();
  418. // }
  419. // });
  420. });
  421. APP.UI.addListener(UIEvents.SIP_DIAL, function (sipNumber) {
  422. room.dial(sipNumber);
  423. });
  424. // Starts or stops the recording for the conference.
  425. APP.UI.addListener(UIEvents.RECORDING_TOGGLE, function (predefinedToken) {
  426. if (predefinedToken) {
  427. room.toggleRecording({token: predefinedToken});
  428. return;
  429. }
  430. APP.UI.requestRecordingToken().then((token) => {
  431. room.toggleRecording({token: token});
  432. });
  433. });
  434. APP.UI.addListener(UIEvents.TOPIC_CHANGED, function (topic) {
  435. // FIXME handle topic change
  436. // APP.xmpp.setSubject(topic);
  437. // on SUBJECT_CHANGED UI.setSubject(topic);
  438. });
  439. APP.UI.addListener(UIEvents.USER_KICKED, function (id) {
  440. room.kickParticipant(id);
  441. });
  442. APP.UI.addListener(UIEvents.REMOTE_AUDIO_MUTED, function (id) {
  443. room.muteParticipant(id);
  444. });
  445. room.on(ConferenceEvents.KICKED, function () {
  446. APP.UI.notifyKicked();
  447. // FIXME close
  448. });
  449. APP.UI.addListener(UIEvents.AUTH_CLICKED, function () {
  450. AuthHandler.authenticate(room);
  451. });
  452. APP.UI.addListener(UIEvents.SELECTED_ENDPOINT, function (id) {
  453. room.selectParticipant(id);
  454. });
  455. room.on(ConferenceEvents.DTMF_SUPPORT_CHANGED, function (isDTMFSupported) {
  456. APP.UI.updateDTMFSupport(isDTMFSupported);
  457. });
  458. APP.UI.addListener(UIEvents.TOGGLE_SCREENSHARING, function () {
  459. APP.desktopsharing.toggleScreenSharing();
  460. });
  461. APP.UI.addListener(DSEvents.SWITCHING_DONE, function (isSharingScreen) {
  462. APP.UI.updateDesktopSharingButtons(isSharingScreen);
  463. });
  464. APP.desktopsharing.addListener(
  465. DSEvents.NEW_STREAM_CREATED,
  466. (track, callback) => {
  467. const localCallback = (newTrack) => {
  468. if (newTrack.isLocal() && newTrack === localVideo) {
  469. if(localVideo.isMuted() &&
  470. localVideo.videoType !== track.videoType) {
  471. localVideo.mute();
  472. }
  473. callback();
  474. room.off(ConferenceEvents.TRACK_ADDED, localCallback);
  475. }
  476. };
  477. room.on(ConferenceEvents.TRACK_ADDED, localCallback);
  478. localVideo.stop();
  479. localVideo = track;
  480. addTrack(track);
  481. APP.UI.addLocalStream(track);
  482. }
  483. );
  484. $(window).bind('beforeunload', function () {
  485. room.leave();
  486. });
  487. return new Promise(function (resolve, reject) {
  488. room.on(ConferenceEvents.CONFERENCE_JOINED, handleConferenceJoined);
  489. room.on(ConferenceEvents.CONFERENCE_FAILED, onConferenceFailed);
  490. let password;
  491. let reconnectTimeout;
  492. function unsubscribe() {
  493. room.off(
  494. ConferenceEvents.CONFERENCE_JOINED, handleConferenceJoined
  495. );
  496. room.off(
  497. ConferenceEvents.CONFERENCE_FAILED, onConferenceFailed
  498. );
  499. if (reconnectTimeout) {
  500. clearTimeout(reconnectTimeout);
  501. }
  502. AuthHandler.closeAuth();
  503. }
  504. function handleConferenceJoined() {
  505. unsubscribe();
  506. resolve();
  507. }
  508. function handleConferenceFailed(err) {
  509. unsubscribe();
  510. reject(err);
  511. }
  512. function onConferenceFailed(err, msg = '') {
  513. console.error('CONFERENCE FAILED:', err, msg);
  514. switch (err) {
  515. // room is locked by the password
  516. case ConferenceErrors.PASSWORD_REQUIRED:
  517. APP.UI.markRoomLocked(true);
  518. roomLocker.requirePassword().then(function () {
  519. room.join(roomLocker.password);
  520. });
  521. break;
  522. case ConferenceErrors.CONNECTION_ERROR:
  523. APP.UI.notifyConnectionFailed(msg);
  524. break;
  525. // not enough rights to create conference
  526. case ConferenceErrors.AUTHENTICATION_REQUIRED:
  527. // schedule reconnect to check if someone else created the room
  528. reconnectTimeout = setTimeout(function () {
  529. room.join(password);
  530. }, 5000);
  531. // notify user that auth is required
  532. AuthHandler.requireAuth(APP.conference.roomName);
  533. break;
  534. default:
  535. handleConferenceFailed(err);
  536. }
  537. }
  538. room.join(password);
  539. });
  540. }
  541. function connect() {
  542. return openConnection({retry: true}).catch(function (err) {
  543. if (err === ConnectionErrors.PASSWORD_REQUIRED) {
  544. APP.UI.notifyTokenAuthFailed();
  545. } else {
  546. APP.UI.notifyConnectionFailed(err);
  547. }
  548. throw err;
  549. });
  550. }
  551. function init() {
  552. APP.UI.start();
  553. JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.TRACE);
  554. JitsiMeetJS.init(config).then(function () {
  555. return Promise.all([
  556. APP.createLocalTracks('audio', 'video'),
  557. connect()
  558. ]);
  559. }).then(function ([tracks, connection]) {
  560. console.log('initialized with %s local tracks', tracks.length);
  561. return initConference(tracks, connection);
  562. }).then(function () {
  563. APP.UI.initConference();
  564. APP.UI.addListener(UIEvents.LANG_CHANGED, function (language) {
  565. APP.translation.setLanguage(language);
  566. APP.settings.setLanguage(language);
  567. });
  568. APP.desktopsharing.init(JitsiMeetJS.isDesktopSharingEnabled());
  569. APP.statistics.start();
  570. APP.connectionquality.init();
  571. APP.keyboardshortcut.init();
  572. }).catch(function (err) {
  573. console.error(err);
  574. });
  575. }
  576. /**
  577. * If we have an HTTP endpoint for getting config.json configured we're going to
  578. * read it and override properties from config.js and interfaceConfig.js.
  579. * If there is no endpoint we'll just continue with initialization.
  580. * Keep in mind that if the endpoint has been configured and we fail to obtain
  581. * the config for any reason then the conference won't start and error message
  582. * will be displayed to the user.
  583. */
  584. function obtainConfigAndInit() {
  585. let roomName = APP.conference.roomName;
  586. if (config.configLocation) {
  587. APP.configFetch.obtainConfig(
  588. config.configLocation, roomName,
  589. // Get config result callback
  590. function(success, error) {
  591. if (success) {
  592. console.log("(TIME) configuration fetched:\t",
  593. window.performance.now());
  594. init();
  595. } else {
  596. // Show obtain config error,
  597. // pass the error object for report
  598. APP.UI.messageHandler.openReportDialog(
  599. null, "dialog.connectError", error);
  600. }
  601. });
  602. } else {
  603. require("./modules/config/BoshAddressChoice").chooseAddress(
  604. config, roomName);
  605. init();
  606. }
  607. }
  608. $(document).ready(function () {
  609. console.log("(TIME) document ready:\t", window.performance.now());
  610. URLProcessor.setConfigParametersFromUrl();
  611. APP.init();
  612. APP.translation.init(settings.getLanguage());
  613. if (APP.API.isEnabled()) {
  614. APP.API.init();
  615. }
  616. obtainConfigAndInit();
  617. });
  618. $(window).bind('beforeunload', function () {
  619. if (APP.API.isEnabled()) {
  620. APP.API.dispose();
  621. }
  622. });
  623. module.exports = APP;