diff --git a/packages/core/useNetwork/index.md b/packages/core/useNetwork/index.md index c66e745042fb..7f2782908781 100644 --- a/packages/core/useNetwork/index.md +++ b/packages/core/useNetwork/index.md @@ -78,6 +78,10 @@ export interface NetworkState { * The detected effective speed type. */ effectiveType: Ref + /** + * The estimated effective round-trip time of the current connection. + */ + rtt: Ref /** * If the user activated data saver mode. */ @@ -93,7 +97,7 @@ export interface NetworkState { * @see https://vueuse.org/useNetwork * @param options */ -export declare function useNetwork(options?: ConfigurableWindow): NetworkState +export declare function useNetwork(options?: ConfigurableWindow): Readonly ``` ## Source diff --git a/packages/core/useNetwork/index.ts b/packages/core/useNetwork/index.ts index 7bfeeb93d645..cf540b41797f 100644 --- a/packages/core/useNetwork/index.ts +++ b/packages/core/useNetwork/index.ts @@ -27,9 +27,13 @@ export interface NetworkState { */ downlinkMax: Ref /** - * The detected effective speed type. - */ + * The detected effective speed type. + */ effectiveType: Ref + /** + * The estimated effective round-trip time of the current connection. + */ + rtt: Ref /** * If the user activated data saver mode. */ @@ -46,7 +50,7 @@ export interface NetworkState { * @see https://vueuse.org/useNetwork * @param options */ -export function useNetwork(options: ConfigurableWindow = {}): NetworkState { +export function useNetwork(options: ConfigurableWindow = {}): Readonly { const { window = defaultWindow } = options const navigator = window?.navigator const isSupported = Boolean(navigator && 'connection' in navigator) @@ -56,6 +60,7 @@ export function useNetwork(options: ConfigurableWindow = {}): NetworkState { const offlineAt: Ref = ref(undefined) const downlink: Ref = ref(undefined) const downlinkMax: Ref = ref(undefined) + const rtt: Ref = ref(undefined) const effectiveType: Ref = ref(undefined) const type: Ref = ref('unknown') @@ -72,6 +77,7 @@ export function useNetwork(options: ConfigurableWindow = {}): NetworkState { downlink.value = connection.downlink downlinkMax.value = connection.downlinkMax effectiveType.value = connection.effectiveType + rtt.value = connection.rtt saveData.value = connection.saveData type.value = connection.type } @@ -101,6 +107,7 @@ export function useNetwork(options: ConfigurableWindow = {}): NetworkState { downlink, downlinkMax, effectiveType, + rtt, type, } }