Skip to content

feat(connectivity): implement BrowserNetworkService using Web Connectivity APIs #41

Description

@rohansaini-02

Problem

Currently, poc-connectivity only implements MockNetworkService. While useful for local test suites, the application needs a production-ready browser implementation that monitors real browser network status.

Proposed Solution

Create a new BrowserNetworkService implementing INetworkService using web APIs:

  • Monitor status using navigator.onLine.

    [!NOTE]
    The initial implementation can rely on navigator.onLine, while keeping the abstraction flexible for future enhancements such as active reachability checks.

  • Listen to live state changes using the window online and offline event listeners.
  • Notify registered subscribers whenever browser connectivity state changes.
  • The implementation should ensure browser event listeners are cleaned up appropriately when the service is disposed or no longer needed.
export class BrowserNetworkService implements INetworkService {
  private listeners: Set<NetworkChangeListener> = new Set();

  constructor() {
    if (typeof window !== 'undefined') {
      window.addEventListener('online', () => this.handleStatusChange());
      window.addEventListener('offline', () => this.handleStatusChange());
    }
  }
  ...
}

Acceptance Criteria

  • BrowserNetworkService is exposed by the connectivity module.
  • The service reacts to browser online/offline events and exposes connectivity state through the existing subscription mechanism.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions