import { NetworkEvent , INetworkEventEmitter , INetworkMonitor } from "@walletconnect/legacy-types" ; class NetworkMonitor implements INetworkMonitor { private _eventEmitters : INetworkEventEmitter [ ] ; constructor ( ) { this . _eventEmitters = [ ] ; if ( typeof window !== "undefined" && typeof ( window as any ) . addEventListener !== "undefined" ) { window . addEventListener ( "online" , ( ) => this . trigger ( "online" ) ) ; window . addEventListener ( "offline" , ( ) => this . trigger ( "offline" ) ) ; } } public on ( event , callback ) { this . _eventEmitters . push ( { event , callback , } ) ; } public trigger ( event ) { let eventEmitters = [ ] ; if ( event ) { eventEmitters = this . _eventEmitters . filter ( ( eventEmitter ) => eventEmitter . event === event ) ; } eventEmitters . forEach ( ( eventEmitter ) => { eventEmitter . callback ( ) ; } ) ; } } export default NetworkMonitor ;