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 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /* jshint -W117 */
  2. /* global JitsiMeetJS */
  3. /* application specific logic */
  4. require("jquery");
  5. require("jquery-ui");
  6. require("strophe");
  7. require("strophe-disco");
  8. require("strophe-caps");
  9. require("tooltip");
  10. require("popover");
  11. window.toastr = require("toastr");
  12. require("jQuery-Impromptu");
  13. require("autosize");
  14. function createConference(connection, room) {
  15. var localTracks = [];
  16. var remoteTracks = {};
  17. return {
  18. muteAudio: function (mute) {
  19. },
  20. muteVideo: function (mute) {
  21. },
  22. toggleAudioMuted: function () {
  23. APP.UI.setAudioMuted(muted);
  24. },
  25. toggleVideoMuted: function () {
  26. APP.UI.setVideoMuted(muted);
  27. }
  28. };
  29. }
  30. var APP = {
  31. init: function () {
  32. this.JitsiMeetJS = JitsiMeetJS;
  33. this.JitsiMeetJS.init();
  34. this.conference = null;
  35. this.UI = require("./modules/UI/UI");
  36. this.API = require("./modules/API/API");
  37. this.connectionquality =
  38. require("./modules/connectionquality/connectionquality");
  39. this.statistics = require("./modules/statistics/statistics");
  40. this.desktopsharing =
  41. require("./modules/desktopsharing/desktopsharing");
  42. this.keyboardshortcut =
  43. require("./modules/keyboardshortcut/keyboardshortcut");
  44. this.translation = require("./modules/translation/translation");
  45. this.settings = require("./modules/settings/Settings");
  46. //this.DTMF = require("./modules/DTMF/DTMF");
  47. this.members = require("./modules/members/MemberList");
  48. this.configFetch = require("./modules/config/HttpConfigFetch");
  49. }
  50. };
  51. function connect() {
  52. var connection = new APP.JitsiMeetJS.JitsiConnection(null, null, {
  53. hosts: config.hosts,
  54. bosh: config.bosh,
  55. clientNode: config.clientNode
  56. });
  57. var events = APP.JitsiMeetJS.events.connection;
  58. return new Promise(function (resolve, reject) {
  59. var onConnectionSuccess = function () {
  60. console.log('CONNECTED');
  61. resolve(connection);
  62. };
  63. var onConnectionFailed = function () {
  64. console.error('CONNECTION FAILED');
  65. reject();
  66. };
  67. var onDisconnect = function () {
  68. console.log('DISCONNECT');
  69. connection.removeEventListener(
  70. events.CONNECTION_ESTABLISHED, onConnectionSuccess
  71. );
  72. connection.removeEventListener(
  73. events.CONNECTION_FAILED, onConnectionFailed
  74. );
  75. connection.removeEventListener(
  76. events.CONNECTION_DISCONNECTED, onDisconnect
  77. );
  78. };
  79. connection.addEventListener(
  80. events.CONNECTION_ESTABLISHED, onConnectionSuccess
  81. );
  82. connection.addEventListener(
  83. events.CONNECTION_FAILED, onConnectionFailed
  84. );
  85. connection.addEventListener(
  86. events.CONNECTION_DISCONNECTED, onDisconnect
  87. );
  88. connection.connect();
  89. }).catch(function (errType, msg) {
  90. // TODO handle OTHER_ERROR only
  91. UI.notifyConnectionFailed(msg);
  92. // rethrow
  93. throw new Error(errType);
  94. });
  95. }
  96. var ConferenceEvents = APP.JitsiMeetJS.events.conference;
  97. function initConference(connection, roomName) {
  98. var room = connection.initJitsiConference(roomName, {
  99. openSctp: config.openSctp,
  100. disableAudioLevels: config.disableAudioLevels
  101. });
  102. room.on(ConferenceEvents.IN_LAST_N_CHANGED, function (inLastN) {
  103. if (config.muteLocalVideoIfNotInLastN) {
  104. // TODO mute or unmute if required
  105. // mark video on UI
  106. // UI.markVideoMuted(true/false);
  107. }
  108. });
  109. room.on(
  110. ConferenceEvents.ACTIVE_SPEAKER_CHANGED,
  111. function (id) {
  112. APP.UI.markDominantSpiker(id);
  113. }
  114. );
  115. room.on(
  116. ConferenceEvents.LAST_N_ENDPOINTS_CHANGED,
  117. function (ids) {
  118. APP.UI.handleLastNEndpoints(ids);
  119. }
  120. );
  121. return initConference(connection, room);
  122. }
  123. function init() {
  124. connect().then(function (connection) {
  125. return initConference(connection, UI.generateRoomName());
  126. }).then(function (conference) {
  127. APP.conference = conference;
  128. APP.desktopsharing.init();
  129. APP.statistics.start();
  130. APP.connectionquality.init();
  131. APP.keyboardshortcut.init();
  132. APP.members.start();
  133. });
  134. }
  135. /**
  136. * If we have an HTTP endpoint for getting config.json configured we're going to
  137. * read it and override properties from config.js and interfaceConfig.js.
  138. * If there is no endpoint we'll just continue with initialization.
  139. * Keep in mind that if the endpoint has been configured and we fail to obtain
  140. * the config for any reason then the conference won't start and error message
  141. * will be displayed to the user.
  142. */
  143. function obtainConfigAndInit() {
  144. var roomName = APP.UI.getRoomNode();
  145. if (config.configLocation) {
  146. APP.configFetch.obtainConfig(
  147. config.configLocation, roomName,
  148. // Get config result callback
  149. function(success, error) {
  150. if (success) {
  151. console.log("(TIME) configuration fetched:\t",
  152. window.performance.now());
  153. init();
  154. } else {
  155. // Show obtain config error,
  156. // pass the error object for report
  157. APP.UI.messageHandler.openReportDialog(
  158. null, "dialog.connectError", error);
  159. }
  160. });
  161. } else {
  162. require("./modules/config/BoshAddressChoice").chooseAddress(
  163. config, roomName);
  164. init();
  165. }
  166. }
  167. $(document).ready(function () {
  168. console.log("(TIME) document ready:\t", window.performance.now());
  169. var URLProcessor = require("./modules/config/URLProcessor");
  170. URLProcessor.setConfigParametersFromUrl();
  171. APP.init();
  172. APP.translation.init();
  173. if(APP.API.isEnabled()) {
  174. APP.API.init();
  175. }
  176. APP.UI.start();
  177. obtainConfigAndInit();
  178. });
  179. $(window).bind('beforeunload', function () {
  180. if(APP.API.isEnabled())
  181. APP.API.dispose();
  182. });
  183. module.exports = APP;