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
Problem
Currently,
poc-connectivityonly implementsMockNetworkService. 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
BrowserNetworkServiceimplementingINetworkServiceusing web APIs:navigator.onLine.onlineandofflineevent listeners.Acceptance Criteria
BrowserNetworkServiceis exposed by the connectivity module.