import { DocMetaRef } from '../DocMetaRef' ; import { DocInfoAdvertisement } from './DocInfoAdvertisement' ; import { DocInfoAdvertiser } from './DocInfoAdvertiser' ; import { DocInfoAdvertisementListenerService } from './DocInfoAdvertisementListenerService' ; import { PersistenceLayerEvent } from '../PersistenceLayerEvent' ; import { PersistenceLayer } from '../PersistenceLayer' ; import { ListenablePersistenceLayer } from '../ListenablePersistenceLayer' ; import { AbstractAdvertisingPersistenceLayer } from './AbstractAdvertisingPersistenceLayer' ; import { ErrorListener } from '../Datastore' ; import { DatastoreInitOpts } from '../Datastore' ; ElectronRendererContext export class AdvertisingPersistenceLayer extends AbstractAdvertisingPersistenceLayer implements ListenablePersistenceLayer { private readonly docInfoAdvertisementListenerService = new DocInfoAdvertisementListenerService ( ) ; public readonly id : string ; constructor ( delegate ) { super ( delegate ) ; this . id = 'advertising:' + delegate . id ; } public async init ( errorListener ? , opts ? ) { this . docInfoAdvertisementListenerService . addEventListener ( ( adv ) => this . onDocInfoAdvertisement ( adv ) ) ; this . docInfoAdvertisementListenerService . start ( ) ; await this . delegate . init ( errorListener , opts ) ; } public async stop ( ) { this . docInfoAdvertisementListenerService . stop ( ) ; return this . delegate . stop ( ) ; } protected broadcastEvent ( event ) { DocInfoAdvertiser . send ( { docMeta : event . docMeta , docInfo : event . docInfo , advertisementType : event . eventType } ) ; } private onDocInfoAdvertisement ( docInfoAdvertisement ) { this . dispatchEvent ( { docMetaRef : < DocMetaRef > { fingerprint : docInfoAdvertisement . docInfo . fingerprint , filename : docInfoAdvertisement . docInfo . filename , docInfo : docInfoAdvertisement . docInfo } , docMeta : docInfoAdvertisement . docMeta , docInfo : docInfoAdvertisement . docInfo , eventType : docInfoAdvertisement . advertisementType } ) ; } }