您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

actions.web.js 4.2KB

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