選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

app.js 23KB

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