snapshot of https://github.com/jitsi/jitsi-meet.git @ fd1749dd28f4138aa80234fc7f311b19aaffa0e7 (2026-09-15)
This commit is contained in:
70
react/features/base/net-info/NetworkInfoService.native.ts
Normal file
70
react/features/base/net-info/NetworkInfoService.native.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
import {
|
||||
default as NetInfo,
|
||||
type NetInfoState,
|
||||
type NetInfoSubscription
|
||||
} from '@react-native-community/netinfo';
|
||||
// eslint-disable-next-line lines-around-comment
|
||||
// @ts-ignore
|
||||
import EventEmitter from 'events';
|
||||
|
||||
import { ONLINE_STATE_CHANGED_EVENT } from './events';
|
||||
import type { NetworkInfo } from './types';
|
||||
|
||||
/**
|
||||
* The network info service implementation for iOS and Android. 'react-native-netinfo' seems to support windows as well,
|
||||
* but that has not been tested and is nto used by jitsi-meet.
|
||||
*/
|
||||
export default class NetworkInfoService extends EventEmitter {
|
||||
/**
|
||||
* Stores the native subscription for future cleanup.
|
||||
*/
|
||||
_subscription?: NetInfoSubscription;
|
||||
|
||||
/**
|
||||
* Converts library's structure to {@link NetworkInfo} used by jitsi-meet.
|
||||
*
|
||||
* @param {NetInfoState} netInfoState - The new state given by the native library.
|
||||
* @private
|
||||
* @returns {NetworkInfo}
|
||||
*/
|
||||
static _convertNetInfoState(netInfoState: NetInfoState): NetworkInfo {
|
||||
return {
|
||||
isOnline: Boolean(netInfoState.isInternetReachable),
|
||||
|
||||
details: netInfoState.details,
|
||||
networkType: netInfoState.type
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for support.
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
static isSupported() {
|
||||
return Boolean(NetInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the service.
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
start() {
|
||||
this._subscription = NetInfo.addEventListener(netInfoState => {
|
||||
super.emit(ONLINE_STATE_CHANGED_EVENT, NetworkInfoService._convertNetInfoState(netInfoState));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the service.
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
stop() {
|
||||
if (this._subscription) {
|
||||
this._subscription();
|
||||
this._subscription = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user