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.

actions.web.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* @flow */
  2. import type { Dispatch } from 'redux';
  3. import {
  4. JitsiConferenceEvents,
  5. libInitError,
  6. WEBRTC_NOT_READY,
  7. WEBRTC_NOT_SUPPORTED
  8. } from '../lib-jitsi-meet';
  9. import UIEvents from '../../../../service/UI/UIEvents';
  10. import { SET_DOMAIN } from './actionTypes';
  11. declare var APP: Object;
  12. declare var config: Object;
  13. const logger = require('jitsi-meet-logger').getLogger(__filename);
  14. export {
  15. connectionEstablished,
  16. connectionFailed
  17. } from './actions.native.js';
  18. /**
  19. * Opens new connection.
  20. *
  21. * @returns {Promise<JitsiConnection>}
  22. */
  23. export function connect() {
  24. return (dispatch: Dispatch<*>, getState: Function) => {
  25. const state = getState();
  26. // XXX Lib-jitsi-meet does not accept uppercase letters.
  27. const room = state['features/base/conference'].room.toLowerCase();
  28. // XXX For web based version we use conference initialization logic
  29. // from the old app (at the moment of writing).
  30. return APP.conference.init({ roomName: room }).then(() => {
  31. if (APP.logCollector) {
  32. // Start the LogCollector's periodic "store logs" task
  33. APP.logCollector.start();
  34. APP.logCollectorStarted = true;
  35. // Make an attempt to flush in case a lot of logs have been
  36. // cached, before the collector was started.
  37. APP.logCollector.flush();
  38. // This event listener will flush the logs, before
  39. // the statistics module (CallStats) is stopped.
  40. //
  41. // NOTE The LogCollector is not stopped, because this event can
  42. // be triggered multiple times during single conference
  43. // (whenever statistics module is stopped). That includes
  44. // the case when Jicofo terminates the single person left in the
  45. // room. It will then restart the media session when someone
  46. // eventually join the room which will start the stats again.
  47. APP.conference.addConferenceListener(
  48. JitsiConferenceEvents.BEFORE_STATISTICS_DISPOSED,
  49. () => {
  50. if (APP.logCollector) {
  51. APP.logCollector.flush();
  52. }
  53. }
  54. );
  55. }
  56. APP.UI.initConference();
  57. APP.UI.addListener(UIEvents.LANG_CHANGED, language => {
  58. APP.translation.setLanguage(language);
  59. APP.settings.setLanguage(language);
  60. });
  61. APP.keyboardshortcut.init();
  62. if (config.requireDisplayName && !APP.settings.getDisplayName()) {
  63. APP.UI.promptDisplayName();
  64. }
  65. })
  66. .catch(error => {
  67. APP.UI.hideRingOverLay();
  68. APP.API.notifyConferenceLeft(APP.conference.roomName);
  69. logger.error(error);
  70. // TODO The following are in fact Errors raised by
  71. // JitsiMeetJS.init() which should be taken care of in
  72. // features/base/lib-jitsi-meet but we are not there yet on the
  73. // Web at the time of this writing.
  74. switch (error.name) {
  75. case WEBRTC_NOT_READY:
  76. case WEBRTC_NOT_SUPPORTED:
  77. dispatch(libInitError(error));
  78. }
  79. });
  80. };
  81. }
  82. /**
  83. * Closes connection.
  84. *
  85. * @returns {Function}
  86. */
  87. export function disconnect() {
  88. // XXX For web based version we use conference hanging up logic from the old
  89. // app.
  90. return () => APP.conference.hangup();
  91. }
  92. /**
  93. * Sets connection domain.
  94. *
  95. * @param {string} domain - Domain name.
  96. * @returns {{
  97. * type: SET_DOMAIN,
  98. * domain: string
  99. * }}
  100. */
  101. export function setDomain(domain: string) {
  102. return {
  103. type: SET_DOMAIN,
  104. domain
  105. };
  106. }