Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

app.js 22KB

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