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

actions.web.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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(
  58. UIEvents.LANG_CHANGED,
  59. language => APP.translation.setLanguage(language));
  60. APP.keyboardshortcut.init();
  61. if (config.requireDisplayName && !APP.settings.getDisplayName()) {
  62. APP.UI.promptDisplayName();
  63. }
  64. })
  65. .catch(error => {
  66. APP.UI.hideRingOverLay();
  67. APP.API.notifyConferenceLeft(APP.conference.roomName);
  68. logger.error(error);
  69. // TODO The following are in fact Errors raised by
  70. // JitsiMeetJS.init() which should be taken care of in
  71. // features/base/lib-jitsi-meet but we are not there yet on the
  72. // Web at the time of this writing.
  73. switch (error.name) {
  74. case WEBRTC_NOT_READY:
  75. case WEBRTC_NOT_SUPPORTED:
  76. dispatch(libInitError(error));
  77. }
  78. });
  79. };
  80. }
  81. /**
  82. * Closes connection.
  83. *
  84. * @returns {Function}
  85. */
  86. export function disconnect() {
  87. // XXX For web based version we use conference hanging up logic from the old
  88. // app.
  89. return () => APP.conference.hangup();
  90. }
  91. /**
  92. * Sets connection domain.
  93. *
  94. * @param {string} domain - Domain name.
  95. * @returns {{
  96. * type: SET_DOMAIN,
  97. * domain: string
  98. * }}
  99. */
  100. export function setDomain(domain: string) {
  101. return {
  102. type: SET_DOMAIN,
  103. domain
  104. };
  105. }