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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* @flow */
  2. import type { Dispatch } from 'redux';
  3. import { JitsiConferenceEvents } from '../lib-jitsi-meet';
  4. import UIEvents from '../../../../service/UI/UIEvents';
  5. import { SET_DOMAIN } from './actionTypes';
  6. import { appNavigate } from '../../app';
  7. import { setUnsupportedBrowser } from '../../unsupported-browser';
  8. declare var APP: Object;
  9. const logger = require('jitsi-meet-logger').getLogger(__filename);
  10. export {
  11. connectionEstablished,
  12. connectionFailed
  13. } from './actions.native.js';
  14. /**
  15. * Opens new connection.
  16. *
  17. * @returns {Promise<JitsiConnection>}
  18. */
  19. export function connect() {
  20. return (dispatch: Dispatch<*>, getState: Function) => {
  21. const state = getState();
  22. // XXX Lib-jitsi-meet does not accept uppercase letters.
  23. const room = state['features/base/conference'].room.toLowerCase();
  24. // XXX For web based version we use conference initialization logic
  25. // from the old app (at the moment of writing).
  26. return APP.conference.init({ roomName: room }).then(() => {
  27. if (APP.logCollector) {
  28. // Start the LogCollector's periodic "store logs" task
  29. APP.logCollector.start();
  30. APP.logCollectorStarted = true;
  31. // Make an attempt to flush in case a lot of logs have been
  32. // cached, before the collector was started.
  33. APP.logCollector.flush();
  34. // This event listener will flush the logs, before
  35. // the statistics module (CallStats) is stopped.
  36. //
  37. // NOTE The LogCollector is not stopped, because this event can
  38. // be triggered multiple times during single conference
  39. // (whenever statistics module is stopped). That includes
  40. // the case when Jicofo terminates the single person left in the
  41. // room. It will then restart the media session when someone
  42. // eventually join the room which will start the stats again.
  43. APP.conference.addConferenceListener(
  44. JitsiConferenceEvents.BEFORE_STATISTICS_DISPOSED,
  45. () => {
  46. if (APP.logCollector) {
  47. APP.logCollector.flush();
  48. }
  49. }
  50. );
  51. }
  52. APP.UI.initConference();
  53. APP.UI.addListener(UIEvents.LANG_CHANGED, language => {
  54. APP.translation.setLanguage(language);
  55. APP.settings.setLanguage(language);
  56. });
  57. APP.keyboardshortcut.init();
  58. })
  59. .catch(err => {
  60. APP.UI.hideRingOverLay();
  61. APP.API.notifyConferenceLeft(APP.conference.roomName);
  62. logger.error(err);
  63. dispatch(setUnsupportedBrowser(err));
  64. // If during the conference initialization was defined that
  65. // browser doesn't support WebRTC then we should define
  66. // which route to render.
  67. dispatch(appNavigate(room));
  68. // Force reinitialization of the conference if WebRTC is ready.
  69. if (err.webRTCReadyPromise) {
  70. err.webRTCReadyPromise.then(() => {
  71. // Setting plugin required flag to false because
  72. // it's already been installed.
  73. dispatch(setUnsupportedBrowser({
  74. isPluginRequired: false
  75. }));
  76. dispatch(appNavigate(room));
  77. });
  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. }