Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

actions.any.ts 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import _ from 'lodash';
  2. import { IReduxState } from '../../app/types';
  3. import {
  4. appendURLParam,
  5. getBackendSafeRoomName
  6. } from '../util/uri';
  7. import {
  8. CONNECTION_DISCONNECTED,
  9. CONNECTION_ESTABLISHED,
  10. CONNECTION_FAILED,
  11. SET_LOCATION_URL
  12. } from './actionTypes';
  13. import logger from './logger';
  14. /**
  15. * The error structure passed to the {@link connectionFailed} action.
  16. *
  17. * Note there was an intention to make the error resemble an Error instance (to
  18. * the extent that jitsi-meet needs it).
  19. */
  20. export type ConnectionFailedError = {
  21. /**
  22. * The invalid credentials that were used to authenticate and the
  23. * authentication failed.
  24. */
  25. credentials?: {
  26. /**
  27. * The XMPP user's ID.
  28. */
  29. jid: string;
  30. /**
  31. * The XMPP user's password.
  32. */
  33. password: string;
  34. };
  35. /**
  36. * The details about the connection failed event.
  37. */
  38. details?: Object;
  39. /**
  40. * Error message.
  41. */
  42. message?: string;
  43. /**
  44. * One of {@link JitsiConnectionError} constants (defined in
  45. * lib-jitsi-meet).
  46. */
  47. name: string;
  48. /**
  49. * Indicates whether this event is recoverable or not.
  50. */
  51. recoverable?: boolean;
  52. };
  53. /**
  54. * Create an action for when the signaling connection has been lost.
  55. *
  56. * @param {JitsiConnection} connection - The {@code JitsiConnection} which
  57. * disconnected.
  58. * @private
  59. * @returns {{
  60. * type: CONNECTION_DISCONNECTED,
  61. * connection: JitsiConnection
  62. * }}
  63. */
  64. export function connectionDisconnected(connection?: Object) {
  65. return {
  66. type: CONNECTION_DISCONNECTED,
  67. connection
  68. };
  69. }
  70. /**
  71. * Create an action for when the signaling connection has been established.
  72. *
  73. * @param {JitsiConnection} connection - The {@code JitsiConnection} which was
  74. * established.
  75. * @param {number} timeEstablished - The time at which the
  76. * {@code JitsiConnection} which was established.
  77. * @public
  78. * @returns {{
  79. * type: CONNECTION_ESTABLISHED,
  80. * connection: JitsiConnection,
  81. * timeEstablished: number
  82. * }}
  83. */
  84. export function connectionEstablished(
  85. connection: Object, timeEstablished: number) {
  86. return {
  87. type: CONNECTION_ESTABLISHED,
  88. connection,
  89. timeEstablished
  90. };
  91. }
  92. /**
  93. * Create an action for when the signaling connection could not be created.
  94. *
  95. * @param {JitsiConnection} connection - The {@code JitsiConnection} which
  96. * failed.
  97. * @param {ConnectionFailedError} error - Error.
  98. * @public
  99. * @returns {{
  100. * type: CONNECTION_FAILED,
  101. * connection: JitsiConnection,
  102. * error: ConnectionFailedError
  103. * }}
  104. */
  105. export function connectionFailed(
  106. connection: Object,
  107. error: ConnectionFailedError) {
  108. const { credentials } = error;
  109. if (credentials && !Object.keys(credentials).length) {
  110. error.credentials = undefined;
  111. }
  112. return {
  113. type: CONNECTION_FAILED,
  114. connection,
  115. error
  116. };
  117. }
  118. /**
  119. * Constructs options to be passed to the constructor of {@code JitsiConnection}
  120. * based on the redux state.
  121. *
  122. * @param {Object} state - The redux state.
  123. * @returns {Object} The options to be passed to the constructor of
  124. * {@code JitsiConnection}.
  125. */
  126. export function constructOptions(state: IReduxState) {
  127. // Deep clone the options to make sure we don't modify the object in the
  128. // redux store.
  129. const options = _.cloneDeep(state['features/base/config']);
  130. const { bosh } = options;
  131. let { websocket } = options;
  132. // TESTING: Only enable WebSocket for some percentage of users.
  133. if (websocket && navigator.product === 'ReactNative') {
  134. if ((Math.random() * 100) >= (options?.testing?.mobileXmppWsThreshold ?? 0)) {
  135. websocket = undefined;
  136. }
  137. }
  138. // WebSocket is preferred over BOSH.
  139. const serviceUrl = websocket || bosh;
  140. logger.log(`Using service URL ${serviceUrl}`);
  141. // Append room to the URL's search.
  142. const { room } = state['features/base/conference'];
  143. if (serviceUrl && room) {
  144. const roomName = getBackendSafeRoomName(room);
  145. options.serviceUrl = appendURLParam(serviceUrl, 'room', roomName ?? '');
  146. if (options.websocketKeepAliveUrl) {
  147. options.websocketKeepAliveUrl = appendURLParam(options.websocketKeepAliveUrl, 'room', roomName ?? '');
  148. }
  149. if (options.conferenceRequestUrl) {
  150. options.conferenceRequestUrl = appendURLParam(options.conferenceRequestUrl, 'room', roomName ?? '');
  151. }
  152. }
  153. return options;
  154. }
  155. /**
  156. * Sets the location URL of the application, connection, conference, etc.
  157. *
  158. * @param {URL} [locationURL] - The location URL of the application,
  159. * connection, conference, etc.
  160. * @returns {{
  161. * type: SET_LOCATION_URL,
  162. * locationURL: URL
  163. * }}
  164. */
  165. export function setLocationURL(locationURL?: URL) {
  166. return {
  167. type: SET_LOCATION_URL,
  168. locationURL
  169. };
  170. }