Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

app.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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. var Commands = {
  15. CONNECTION_QUALITY: "connectionQuality",
  16. EMAIL: "email"
  17. };
  18. function createConference(connection, room) {
  19. var localTracks = [];
  20. var remoteTracks = {};
  21. return {
  22. muteAudio: function (mute) {
  23. },
  24. muteVideo: function (mute) {
  25. },
  26. toggleAudioMuted: function () {
  27. APP.UI.setAudioMuted(muted);
  28. },
  29. toggleVideoMuted: function () {
  30. APP.UI.setVideoMuted(muted);
  31. },
  32. setNickname: function (nickname) {
  33. APP.settings.setDisplayName(nickname);
  34. room.setDisplayName(nickname);
  35. },
  36. setStartMuted: function (audio, video) {
  37. // FIXME room.setStartMuted
  38. },
  39. sendMessage: function (message) {
  40. room.sendTextMessage(message);
  41. },
  42. isModerator: function () {
  43. return false;
  44. },
  45. localId: function () {
  46. return room.myUserId();
  47. },
  48. isLocalId: function (id) {
  49. return id === this.localId();
  50. }
  51. };
  52. }
  53. var APP = {
  54. JitsiMeetJS: JitsiMeetJS,
  55. init: function () {
  56. this.JitsiMeetJS.init();
  57. this.JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.TRACE);
  58. this.conference = null;
  59. this.UI = require("./modules/UI/UI");
  60. this.API = require("./modules/API/API");
  61. this.connectionquality =
  62. require("./modules/connectionquality/connectionquality");
  63. this.statistics = require("./modules/statistics/statistics");
  64. this.desktopsharing =
  65. require("./modules/desktopsharing/desktopsharing");
  66. this.keyboardshortcut =
  67. require("./modules/keyboardshortcut/keyboardshortcut");
  68. this.translation = require("./modules/translation/translation");
  69. this.settings = require("./modules/settings/Settings");
  70. //this.DTMF = require("./modules/DTMF/DTMF");
  71. this.members = require("./modules/members/MemberList");
  72. this.configFetch = require("./modules/config/HttpConfigFetch");
  73. }
  74. };
  75. function connect() {
  76. var connection = new APP.JitsiMeetJS.JitsiConnection(null, null, {
  77. hosts: config.hosts,
  78. bosh: config.bosh,
  79. clientNode: config.clientNode
  80. });
  81. var events = APP.JitsiMeetJS.events.connection;
  82. return new Promise(function (resolve, reject) {
  83. var onConnectionSuccess = function () {
  84. console.log('CONNECTED');
  85. resolve(connection);
  86. };
  87. var onConnectionFailed = function () {
  88. console.error('CONNECTION FAILED');
  89. reject();
  90. };
  91. var onDisconnect = function () {
  92. console.log('DISCONNECT');
  93. connection.removeEventListener(
  94. events.CONNECTION_ESTABLISHED, onConnectionSuccess
  95. );
  96. connection.removeEventListener(
  97. events.CONNECTION_FAILED, onConnectionFailed
  98. );
  99. connection.removeEventListener(
  100. events.CONNECTION_DISCONNECTED, onDisconnect
  101. );
  102. };
  103. connection.addEventListener(
  104. events.CONNECTION_ESTABLISHED, onConnectionSuccess
  105. );
  106. connection.addEventListener(
  107. events.CONNECTION_FAILED, onConnectionFailed
  108. );
  109. connection.addEventListener(
  110. events.CONNECTION_DISCONNECTED, onDisconnect
  111. );
  112. connection.connect();
  113. }).catch(function (errType, msg) {
  114. // TODO handle OTHER_ERROR only
  115. APP.UI.notifyConnectionFailed(msg);
  116. // rethrow
  117. throw new Error(errType);
  118. });
  119. }
  120. var ConferenceEvents = APP.JitsiMeetJS.events.conference;
  121. var ConferenceErrors = APP.JitsiMeetJS.errors.conference;
  122. function initConference(connection, roomName) {
  123. var room = connection.initJitsiConference(roomName, {
  124. openSctp: config.openSctp,
  125. disableAudioLevels: config.disableAudioLevels
  126. });
  127. var conf = createConference(connection, room);
  128. room.on(ConferenceEvents.IN_LAST_N_CHANGED, function (inLastN) {
  129. if (config.muteLocalVideoIfNotInLastN) {
  130. // TODO mute or unmute if required
  131. // mark video on UI
  132. // APP.UI.markVideoMuted(true/false);
  133. }
  134. });
  135. room.on(
  136. ConferenceEvents.ACTIVE_SPEAKER_CHANGED,
  137. function (id) {
  138. APP.UI.markDominantSpiker(id);
  139. }
  140. );
  141. room.on(
  142. ConferenceEvents.LAST_N_ENDPOINTS_CHANGED,
  143. function (ids) {
  144. APP.UI.handleLastNEndpoints(ids);
  145. }
  146. );
  147. room.on(
  148. ConferenceEvents.DISPLAY_NAME_CHANGED,
  149. function (id, displayName) {
  150. APP.UI.changeDisplayName(id, displayName);
  151. }
  152. );
  153. room.on(
  154. ConferenceEvents.USER_JOINED,
  155. function (id) {
  156. // FIXME email???
  157. APP.UI.addUser(id);
  158. }
  159. );
  160. room.on(
  161. ConferenceEvents.USER_LEFT,
  162. function (id) {
  163. APP.UI.removeUser(id);
  164. }
  165. );
  166. room.on(
  167. ConferenceEvents.TRACK_MUTE_CHANGED,
  168. function (track) {
  169. // FIXME handle mute
  170. }
  171. );
  172. room.on(
  173. ConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED,
  174. function (id, lvl) {
  175. APP.UI.setAudioLevel(id, lvl);
  176. }
  177. );
  178. room.on(
  179. ConferenceEvents.CONNECTION_INTERRUPTED,
  180. function () {
  181. APP.UI.markVideoInterrupted(true);
  182. }
  183. );
  184. room.on(
  185. ConferenceEvents.CONNECTION_RESTORED,
  186. function () {
  187. APP.UI.markVideoInterrupted(false);
  188. }
  189. );
  190. APP.connectionquality.addListener(
  191. CQEvents.LOCALSTATS_UPDATED,
  192. function (percent, stats) {
  193. APP.UI.updateLocalStats(percent, stats);
  194. // send local stats to other users
  195. room.sendCommand(Commands.CONNECTION_QUALITY, {
  196. value: APP.connectionquality.convertToMUCStats(stats),
  197. attributes: {
  198. id: room.myUserId()
  199. }
  200. });
  201. }
  202. );
  203. APP.connectionquality.addListener(
  204. CQEvents.STOP,
  205. function () {
  206. APP.UI.hideStats();
  207. room.removeCommand(Commands.CONNECTION_QUALITY);
  208. }
  209. );
  210. // listen to remote stats
  211. room.addCommandListener(Commands.CONNECTION_QUALITY, function (data) {
  212. APP.connectionquality.updateRemoteStats(data.attributes.id, data.value);
  213. });
  214. APP.connectionquality.addListener(
  215. CQEvents.REMOTESTATS_UPDATED,
  216. function (id, percent, stats) {
  217. APP.UI.updateRemoteStats(id, percent, stats);
  218. }
  219. );
  220. // share email with other users
  221. function sendEmail(email) {
  222. room.sendCommand(Commands.EMAIL, {
  223. value: email,
  224. attributes: {
  225. id: room.myUserId()
  226. }
  227. });
  228. }
  229. APP.UI.addListener(UIEvents.EMAIL_CHANGED, function (email) {
  230. APP.settings.setEmail(email);
  231. APP.UI.setUserAvatar(room.myUserId(), data.value);
  232. sendEmail(email);
  233. });
  234. var email = APP.settings.getEmail();
  235. if (email) {
  236. sendEmail(APP.settings.getEmail());
  237. }
  238. room.addCommandListener(Commands.EMAIL, function (data) {
  239. APP.UI.setUserAvatar(data.attributes.id, data.value);
  240. });
  241. return new Promise(function (resolve, reject) {
  242. room.on(
  243. ConferenceEvents.CONFERENCE_JOINED,
  244. function () {
  245. resolve(conf);
  246. }
  247. );
  248. room.on(
  249. ConferenceErrors.PASSWORD_REQUIRED,
  250. function () {
  251. // FIXME handle
  252. reject();
  253. }
  254. );
  255. room.on(
  256. ConferenceErrors.CONNECTION_ERROR,
  257. function () {
  258. // FIXME handle
  259. reject();
  260. }
  261. );
  262. APP.UI.closeAuthenticationDialog();
  263. if (config.useNicks) {
  264. // FIXME check this
  265. var nick = APP.UI.askForNickname();
  266. }
  267. room.join();
  268. });
  269. }
  270. function init() {
  271. connect().then(function (connection) {
  272. return initConference(connection, APP.UI.generateRoomName());
  273. }).then(function (conference) {
  274. APP.conference = conference;
  275. APP.UI.start();
  276. // FIXME find own jid
  277. APP.UI.initConference("asdfasdf");
  278. APP.UI.addListener(UIEvents.NICKNAME_CHANGED, function (nickname) {
  279. APP.conference.setNickname(nickname);
  280. });
  281. APP.UI.addListener(UIEvents.MESSAGE_CREATED, function (message) {
  282. APP.conference.sendMessage(message);
  283. });
  284. APP.UI.addListener(UIEvents.LANG_CHANGED, function (language) {
  285. APP.translation.setLanguage(language);
  286. APP.settings.setLanguage(language);
  287. });
  288. APP.UI.addListener(
  289. UIEvents.START_MUTED_CHANGED,
  290. function (startAudioMuted, startVideoMuted) {
  291. APP.conference.setStartMuted(startAudioMuted, startVideoMuted);
  292. }
  293. );
  294. APP.desktopsharing.init();
  295. APP.statistics.start();
  296. APP.connectionquality.init();
  297. APP.keyboardshortcut.init();
  298. APP.members.start();
  299. });
  300. }
  301. /**
  302. * If we have an HTTP endpoint for getting config.json configured we're going to
  303. * read it and override properties from config.js and interfaceConfig.js.
  304. * If there is no endpoint we'll just continue with initialization.
  305. * Keep in mind that if the endpoint has been configured and we fail to obtain
  306. * the config for any reason then the conference won't start and error message
  307. * will be displayed to the user.
  308. */
  309. function obtainConfigAndInit() {
  310. var roomName = APP.UI.getRoomNode();
  311. if (config.configLocation) {
  312. APP.configFetch.obtainConfig(
  313. config.configLocation, roomName,
  314. // Get config result callback
  315. function(success, error) {
  316. if (success) {
  317. console.log("(TIME) configuration fetched:\t",
  318. window.performance.now());
  319. init();
  320. } else {
  321. // Show obtain config error,
  322. // pass the error object for report
  323. APP.UI.messageHandler.openReportDialog(
  324. null, "dialog.connectError", error);
  325. }
  326. });
  327. } else {
  328. require("./modules/config/BoshAddressChoice").chooseAddress(
  329. config, roomName);
  330. init();
  331. }
  332. }
  333. $(document).ready(function () {
  334. console.log("(TIME) document ready:\t", window.performance.now());
  335. var URLProcessor = require("./modules/config/URLProcessor");
  336. URLProcessor.setConfigParametersFromUrl();
  337. APP.init();
  338. APP.translation.init();
  339. if(APP.API.isEnabled()) {
  340. APP.API.init();
  341. }
  342. obtainConfigAndInit();
  343. });
  344. $(window).bind('beforeunload', function () {
  345. if(APP.API.isEnabled())
  346. APP.API.dispose();
  347. });
  348. module.exports = APP;