Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

NetworkInfo.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { getLogger } from 'jitsi-meet-logger';
  2. import Listenable from '../util/Listenable';
  3. export const NETWORK_INFO_EVENT = 'NETWORK_INFO_CHANGED';
  4. const logger = getLogger(__filename);
  5. /**
  6. * Module provides information about the current status of the internet
  7. * connection. Lib-jitsi-meet doesn't have any logic for detecting internet
  8. * online/offline, but rather it relies on the information supplied by the app
  9. * that uses it. By default the online state is assumed and the lib acts as if
  10. * it was connected. See {@link JitsiMeetJS.setNetworkInfo}.
  11. */
  12. export class NetworkInfo extends Listenable {
  13. /**
  14. * Creates new {@link NetworkInfo} instance.
  15. */
  16. constructor() {
  17. super();
  18. this._current = {
  19. isOnline: true
  20. };
  21. }
  22. /**
  23. * Updates the network info state.
  24. * @param {boolean} isOnline - {@code true} if internet is online or {@code false} otherwise.
  25. */
  26. updateNetworkInfo({ isOnline }) {
  27. logger.debug('updateNetworkInfo', { isOnline });
  28. this._current = {
  29. isOnline: isOnline === true
  30. };
  31. this.eventEmitter.emit(NETWORK_INFO_EVENT, this._current);
  32. }
  33. /**
  34. * Returns the online/offline internet status. By default the value is {@code true} and changes only if
  35. * the lib's user wires the state through {@link JitsiMeetJS.setNetworkInfo} like the jitsi-meet does. Because of
  36. * that any logic should still assume that the internet may be offline and should handle the failure gracefully.
  37. * It's only a good hint in the other way around: to pause internet operations until it comes back online.
  38. * @returns {boolean}
  39. */
  40. isOnline() {
  41. return this._current.isOnline === true;
  42. }
  43. }
  44. const networkInfo = new NetworkInfo();
  45. export default networkInfo;