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

NetworkInfo.js 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { getLogger } from '@jitsi/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. */
  25. updateNetworkInfo({ isOnline }) {
  26. logger.debug('updateNetworkInfo', { isOnline });
  27. this._current = {
  28. isOnline: isOnline === true
  29. };
  30. this.eventEmitter.emit(NETWORK_INFO_EVENT, this._current);
  31. }
  32. /**
  33. * Returns the online/offline internet status. By default the value is {@code true} and changes only if
  34. * the lib's user wires the state through {@link JitsiMeetJS.setNetworkInfo} like the jitsi-meet does. Because of
  35. * that any logic should still assume that the internet may be offline and should handle the failure gracefully.
  36. * It's only a good hint in the other way around: to pause internet operations until it comes back online.
  37. * @returns {boolean}
  38. */
  39. isOnline() {
  40. return this._current.isOnline === true;
  41. }
  42. }
  43. const networkInfo = new NetworkInfo();
  44. export default networkInfo;