Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. setNickname: function (nickname) {
  29. // FIXME check if room is available etc.
  30. room.setDisplayName(nickname);
  31. }
  32. };
  33. }
  34. var APP = {
  35. JitsiMeetJS: JitsiMeetJS,
  36. init: function () {
  37. this.JitsiMeetJS.init();
  38. this.conference = null;
  39. this.UI = require("./modules/UI/UI");
  40. this.API = require("./modules/API/API");
  41. this.connectionquality =
  42. require("./modules/connectionquality/connectionquality");
  43. this.statistics = require("./modules/statistics/statistics");
  44. this.desktopsharing =
  45. require("./modules/desktopsharing/desktopsharing");
  46. this.keyboardshortcut =
  47. require("./modules/keyboardshortcut/keyboardshortcut");
  48. this.translation = require("./modules/translation/translation");
  49. this.settings = require("./modules/settings/Settings");
  50. //this.DTMF = require("./modules/DTMF/DTMF");
  51. this.members = require("./modules/members/MemberList");
  52. this.configFetch = require("./modules/config/HttpConfigFetch");
  53. }
  54. };
  55. function connect() {
  56. var connection = new APP.JitsiMeetJS.JitsiConnection(null, null, {
  57. hosts: config.hosts,
  58. bosh: config.bosh,
  59. clientNode: config.clientNode
  60. });
  61. var events = APP.JitsiMeetJS.events.connection;
  62. return new Promise(function (resolve, reject) {
  63. var onConnectionSuccess = function () {
  64. console.log('CONNECTED');
  65. resolve(connection);
  66. };
  67. var onConnectionFailed = function () {
  68. console.error('CONNECTION FAILED');
  69. reject();
  70. };
  71. var onDisconnect = function () {
  72. console.log('DISCONNECT');
  73. connection.removeEventListener(
  74. events.CONNECTION_ESTABLISHED, onConnectionSuccess
  75. );
  76. connection.removeEventListener(
  77. events.CONNECTION_FAILED, onConnectionFailed
  78. );
  79. connection.removeEventListener(
  80. events.CONNECTION_DISCONNECTED, onDisconnect
  81. );
  82. };
  83. connection.addEventListener(
  84. events.CONNECTION_ESTABLISHED, onConnectionSuccess
  85. );
  86. connection.addEventListener(
  87. events.CONNECTION_FAILED, onConnectionFailed
  88. );
  89. connection.addEventListener(
  90. events.CONNECTION_DISCONNECTED, onDisconnect
  91. );
  92. connection.connect();
  93. }).catch(function (errType, msg) {
  94. // TODO handle OTHER_ERROR only
  95. UI.notifyConnectionFailed(msg);
  96. // rethrow
  97. throw new Error(errType);
  98. });
  99. }
  100. var ConferenceEvents = APP.JitsiMeetJS.events.conference;
  101. var ConferenceErrors = APP.JitsiMeetJS.errors.conference;
  102. function initConference(connection, roomName) {
  103. var room = connection.initJitsiConference(roomName, {
  104. openSctp: config.openSctp,
  105. disableAudioLevels: config.disableAudioLevels
  106. });
  107. var conf = createConference(connection, room);
  108. room.on(ConferenceEvents.IN_LAST_N_CHANGED, function (inLastN) {
  109. if (config.muteLocalVideoIfNotInLastN) {
  110. // TODO mute or unmute if required
  111. // mark video on UI
  112. // UI.markVideoMuted(true/false);
  113. }
  114. });
  115. room.on(
  116. ConferenceEvents.ACTIVE_SPEAKER_CHANGED,
  117. function (id) {
  118. APP.UI.markDominantSpiker(id);
  119. }
  120. );
  121. room.on(
  122. ConferenceEvents.LAST_N_ENDPOINTS_CHANGED,
  123. function (ids) {
  124. APP.UI.handleLastNEndpoints(ids);
  125. }
  126. );
  127. room.on(
  128. ConferenceEvents.DISPLAY_NAME_CHANGED,
  129. function (id, displayName) {
  130. UI.changeDisplayName(id, displayName);
  131. }
  132. );
  133. room.on(
  134. ConferenceEvents.USER_JOINED,
  135. function (id) {
  136. // FIXME ????
  137. UI.addUser();
  138. }
  139. );
  140. room.on(
  141. ConferenceEvents.USER_LEFT,
  142. function (id) {
  143. UI.removeUser(id);
  144. }
  145. );
  146. room.on(
  147. ConferenceEvents.TRACK_MUTE_CHANGED,
  148. function (track) {
  149. // FIXME handle mute
  150. }
  151. );
  152. room.on(
  153. ConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED,
  154. function (id, lvl) {
  155. UI.setAudioLevel(id, lvl);
  156. }
  157. );
  158. return new Promise(function (resolve, reject) {
  159. room.on(
  160. ConferenceEvents.CONFERENCE_JOINED,
  161. function () {
  162. resolve(conf);
  163. }
  164. );
  165. room.on(
  166. ConferenceErrors.PASSWORD_REQUIRED,
  167. function () {
  168. // FIXME handle
  169. reject();
  170. }
  171. );
  172. APP.UI.closeAuthenticationDialog();
  173. if (config.useNicks) {
  174. // FIXME check this
  175. var nick = APP.UI.askForNickname();
  176. }
  177. room.join();
  178. });
  179. }
  180. function init() {
  181. connect().then(function (connection) {
  182. return initConference(connection, UI.generateRoomName());
  183. }).then(function (conference) {
  184. APP.conference = conference;
  185. APP.UI.initConference();
  186. //NicknameHandler emits this event
  187. APP.UI.addListener(UIEvents.NICKNAME_CHANGED, function (nickname) {
  188. APP.conference.setNickname(nickname);
  189. });
  190. APP.desktopsharing.init();
  191. APP.statistics.start();
  192. APP.connectionquality.init();
  193. APP.keyboardshortcut.init();
  194. APP.members.start();
  195. });
  196. }
  197. /**
  198. * If we have an HTTP endpoint for getting config.json configured we're going to
  199. * read it and override properties from config.js and interfaceConfig.js.
  200. * If there is no endpoint we'll just continue with initialization.
  201. * Keep in mind that if the endpoint has been configured and we fail to obtain
  202. * the config for any reason then the conference won't start and error message
  203. * will be displayed to the user.
  204. */
  205. function obtainConfigAndInit() {
  206. var roomName = APP.UI.getRoomNode();
  207. if (config.configLocation) {
  208. APP.configFetch.obtainConfig(
  209. config.configLocation, roomName,
  210. // Get config result callback
  211. function(success, error) {
  212. if (success) {
  213. console.log("(TIME) configuration fetched:\t",
  214. window.performance.now());
  215. init();
  216. } else {
  217. // Show obtain config error,
  218. // pass the error object for report
  219. APP.UI.messageHandler.openReportDialog(
  220. null, "dialog.connectError", error);
  221. }
  222. });
  223. } else {
  224. require("./modules/config/BoshAddressChoice").chooseAddress(
  225. config, roomName);
  226. init();
  227. }
  228. }
  229. $(document).ready(function () {
  230. console.log("(TIME) document ready:\t", window.performance.now());
  231. var URLProcessor = require("./modules/config/URLProcessor");
  232. URLProcessor.setConfigParametersFromUrl();
  233. APP.init();
  234. APP.translation.init();
  235. if(APP.API.isEnabled()) {
  236. APP.API.init();
  237. }
  238. APP.UI.start();
  239. obtainConfigAndInit();
  240. });
  241. $(window).bind('beforeunload', function () {
  242. if(APP.API.isEnabled())
  243. APP.API.dispose();
  244. });
  245. module.exports = APP;