import { Peer } from "../core" ; export class PubSub { constructor ( private parent ) { } private checkOnlineAndEnabled ( ) { if ( ! this . parent . isOnline ( ) ) { throw new Error ( "peer is not online" ) ; } if ( ! this . parent . host . pubsub ) { throw new Error ( "pubsub is not enabled" ) ; } } async publish ( topics , messages ) { this . checkOnlineAndEnabled ( ) ; if ( this . parent . host . pubsub ) { return this . parent . host . pubsub . publish ( topics , messages ) ; } } param topic param handler example async subscribe ( topics , handler ) { this . checkOnlineAndEnabled ( ) ; if ( this . parent . host . pubsub ) { return this . parent . host . pubsub . subscribe ( topics , handler , null ) ; } } param topic param handler example example async unsubscribe ( topic , handler ? ) { this . checkOnlineAndEnabled ( ) ; if ( this . parent . host . pubsub ) { return this . parent . host . pubsub . unsubscribe ( topic , handler ) ; } } async ls ( ) { this . checkOnlineAndEnabled ( ) ; if ( this . parent . host . pubsub ) { return this . parent . host . pubsub . ls ( ) ; } } async peers ( topic ) { this . checkOnlineAndEnabled ( ) ; if ( this . parent . host . pubsub ) { return this . parent . host . pubsub . peers ( topic ) ; } } setMaxListeners ( n ) { this . checkOnlineAndEnabled ( ) ; if ( this . parent . host . pubsub ) { return this . parent . host . pubsub . setMaxListeners ( n ) ; } } }