mirror of
https://gitcode.com/GitHub_Trending/ji/jitsi-meet.git
synced 2026-05-14 11:57:48 +00:00
feat: report analytics for the network connection
Will emit new 'network.info' action with the online/offline status and extra details for native like the network type and 'isConnectionExpensive' flag.
This commit is contained in:
66
react/features/base/net-info/NetworkInfoService.native.js
Normal file
66
react/features/base/net-info/NetworkInfoService.native.js
Normal file
@@ -0,0 +1,66 @@
|
||||
// @flow
|
||||
import EventEmitter from 'events';
|
||||
import NetInfo from '@react-native-community/netinfo';
|
||||
import type { NetInfoState, NetInfoSubscription } from '@react-native-community/netinfo';
|
||||
|
||||
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: 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 => {
|
||||
this.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