Network

Reactive wrapper around the Network Information API. Track network connection information with Angular signals.

Loading demo...

Usage

angular-ts
import { Component } from '@angular/core';
import { network } from '@signality/core';

@Component({
  template: `
    <p [class.offline]="!net.isOnline()">
      {{ net.isOnline() ? '🟢 Online' : '🔴 Offline' }}
    </p>
  `,
})
export class NetworkStatus {
  readonly net = network(); 
}

Use InjectionToken for Singleton

For global state tracking like network, consider using the provided NETWORK token instead of calling the function directly. This ensures a singleton instance shared across your entire application, reducing memory usage and event listener overhead:

typescript
import { inject } from '@angular/core';
import { NETWORK } from '@signality/core';

const net = network(); 
const net = inject(NETWORK); 

Learn more about Token-based utilities.

Parameters

ParameterTypeDescription
optionsNetworkOptionsOptional configuration

Options

OptionTypeDescription
injectorInjectorOptional injector for DI context

Return Value

The network() function returns a NetworkRef object:

PropertyTypeDescription
isOnlineSignal<boolean>Whether the browser is online (provided by ONLINE token)
isSupportedSignal<boolean>Whether Network Information API is supported
effectiveTypeSignal<'slow-2g' | '2g' | '3g' | '4g' | undefined>Effective connection type
downlinkSignal<number | undefined>Downlink speed in Mbps
rttSignal<number | undefined>Round-trip time in ms
saveDataSignal<boolean>Whether user has data saver enabled
typeSignal<ConnectionType | undefined>Connection type (wifi, cellular, etc.)

Examples

Offline banner

angular-ts
import { Component } from '@angular/core';
import { network } from '@signality/core';

@Component({
  template: `
    @if (!net.isOnline()) {
      <div class="offline-banner">
        You are offline. Some features may be unavailable.
      </div>
    }
    <ng-content />
  `,
})
export class OfflineBanner {
  readonly net = network();
}

Adaptive media quality

angular-ts
import { Component, computed } from '@angular/core';
import { network } from '@signality/core';

@Component({
  template: `<img [src]="imageSrc()" alt="Adaptive image" />`,
})
export class AdaptiveImage {
  readonly net = network();
  
  readonly imageSrc = computed(() => {
    const type = this.net.effectiveType();
    
    switch (type) {
      case 'slow-2g':
      case '2g':
        return '/images/photo-low.jpg';
      case '3g':
        return '/images/photo-medium.jpg';
      case '4g':
      default:
        return '/images/photo-high.jpg';
    }
  });
}

Browser Compatibility

The Network Information API has limited browser support. Always check isSupported() before relying on network information (see Browser API support detection):

angular-html
@if (network.isSupported()) {
  <p>Connection: {{ network.effectiveType() }}</p>
} @else {
  <p>Network information is not available in this browser</p>
}

For detailed browser support information, see Can I use: Network Information API.

SSR Compatibility

On the server, signals initialize with safe defaults:

  • isOnlinetrue
  • isSupportedfalse
  • effectiveType, downlink, rtt, typeundefined
  • saveDatafalse

Type Definitions

typescript
type EffectiveConnectionType = 'slow-2g' | '2g' | '3g' | '4g';
type ConnectionType = 'bluetooth' | 'cellular' | 'ethernet' | 'wifi' | 'wimax' | 'none' | 'other' | 'unknown';

type NetworkOptions = WithInjector;

interface NetworkRef {
  readonly isOnline: Signal<boolean>;
  readonly isSupported: Signal<boolean>;
  readonly effectiveType: Signal<EffectiveConnectionType | undefined>;
  readonly downlink: Signal<number | undefined>;
  readonly rtt: Signal<number | undefined>;
  readonly saveData: Signal<boolean>;
  readonly type: Signal<ConnectionType | undefined>;
}

function network(options?: NetworkOptions): NetworkRef;
Edit this page on GitHub Last updated: Mar 19, 2026, 23:28:23