Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
2c70388
commit 6ae9bbe
Showing
20 changed files
with
377 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import EventEmitter from 'events'; | ||
|
||
import { ONLINE_STATE_CHANGED_EVENT } from './events'; | ||
|
||
/** | ||
* The network info service implementation for web (Chrome, Firefox and Safari). | ||
*/ | ||
export default class NetworkInfoService extends EventEmitter { | ||
|
||
/** | ||
* Creates new instance... | ||
*/ | ||
constructor() { | ||
super(); | ||
this._onlineStateListener = this._handleOnlineStatusChange.bind(this, /* online */ true); | ||
this._offlineStateListener = this._handleOnlineStatusChange.bind(this, /* offline */ false); | ||
} | ||
|
||
/** | ||
* Callback function to track the online state. | ||
* | ||
* @param {boolean} isOnline - Is the browser online or not. | ||
* @private | ||
* @returns {void} | ||
*/ | ||
_handleOnlineStatusChange(isOnline) { | ||
this.emit(ONLINE_STATE_CHANGED_EVENT, { isOnline }); | ||
} | ||
|
||
/** | ||
* Checks for support. | ||
* | ||
* @returns {boolean} | ||
*/ | ||
static isSupported() { | ||
return window.addEventListener && typeof navigator.onLine !== 'undefined'; | ||
} | ||
|
||
/** | ||
* Starts the service. | ||
* | ||
* @returns {void} | ||
*/ | ||
start() { | ||
window.addEventListener('online', this._onlineStateListener); | ||
window.addEventListener('offline', this._offlineStateListener); | ||
} | ||
|
||
/** | ||
* Stops the service. | ||
* | ||
* @returns {void} | ||
*/ | ||
stop() { | ||
window.removeEventListener('online', this._onlineStateListener); | ||
window.removeEventListener('offline', this._offlineStateListener); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* The action dispatched when the {@link NetworkInfo} structure is being updated. | ||
* | ||
* @type {string} | ||
*/ | ||
export const SET_NETWORK_INFO = 'SET_NETWORK_INFO'; | ||
|
||
/** | ||
* Tha action dispatched by 'base/net-info' middleware in order to store the cleanup function for later use. | ||
* @type {string} | ||
* @private | ||
*/ | ||
export const _STORE_NETWORK_INFO_CLEANUP = 'STORE_NETWORK_INFO_CLEANUP'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// @flow | ||
|
||
import { SET_NETWORK_INFO, _STORE_NETWORK_INFO_CLEANUP } from './actionTypes'; | ||
|
||
import type { NetworkInfo } from './types'; | ||
|
||
/** | ||
* Up[dates the network info state. | ||
* | ||
* @param {NetworkInfo} networkInfo - The new network state to be set. | ||
* @returns {{ | ||
* type: SET_NETWORK_INFO, | ||
* isOnline: boolean, | ||
* networkType: string, | ||
* details: Object | ||
* }} | ||
*/ | ||
export function setNetworkInfo({ isOnline, networkType, details }: NetworkInfo): Object { | ||
return { | ||
type: SET_NETWORK_INFO, | ||
isOnline, | ||
networkType, | ||
details | ||
}; | ||
} | ||
|
||
/** | ||
* Stored the cleanup function used to shutdown the {@code NetworkInfoService}. | ||
* | ||
* @param {Function} cleanup - The cleanup function to be called on {@code APP_WILL_UNMOUNT}. | ||
* @returns {{ | ||
* type: _STORE_NETWORK_INFO_CLEANUP, | ||
* cleanup: Function | ||
* }} | ||
* @private | ||
*/ | ||
export function _storeNetworkInfoCleanup(cleanup: Function): Object { | ||
return { | ||
type: _STORE_NETWORK_INFO_CLEANUP, | ||
cleanup | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* The name for Redux store key used by the 'base/net-info' feature. | ||
* | ||
* @type {string} | ||
*/ | ||
export const STORE_NAME = 'features/base/net-info'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const ONLINE_STATE_CHANGED_EVENT = 'network-info-online-status-change'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './actionTypes'; | ||
|
||
import './middleware'; | ||
import './reducer'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// @flow | ||
|
||
import { getLogger } from '../logging/functions'; | ||
|
||
export default getLogger('features/base/net-info'); |
Oops, something went wrong.