import { BasePostMessageStream , PostMessageEvent , StreamData , } from './BasePostMessageStream' ; import { DEDICATED_WORKER_NAME } from './enums' ; /**
 * Worker-side dedicated web worker `postMessage` stream.
 */ export class WorkerPostMessageStream extends BasePostMessageStream { private _name : string ; /**
     * Note: Designed for use in web workers only.
     *
     * Creates a stream for communicating with the window that created this web
     * worker.
     */ constructor ( ) { super ( ) ; this . _name = DEDICATED_WORKER_NAME ; self . onmessage = this . _onMessage . bind ( this ) as any ; this . _handshake ( ) ; } protected _postMessage ( data ) { ( self . postMessage as ( message : any ) => void ) ( { data } ) ; } private _onMessage ( event ) { const message = event . data ; if ( typeof message !== 'object' || message . target !== this . _name || ! message . data ) { return ; } this . _onData ( message . data as StreamData ) ; } _destroy ( ) { return undefined ; } }