src/subscriptions.js
/**
 * Creates shared Observable that is served as a connection to Subscriptions host
 *
 * @param {string} host
 * @param {{}} options
 */
Creates shared Observable that is served as a connection to Subscriptions host
@param {string} host
@param {{}} options
Creates shared Observable that is served as a connection to Subscriptions host @param { string } host @param {{ }} options
function createConnection(host, options){
    const streamId = +new Date();
    return of(host).pipe(
        tap(host => console.debug(`${streamId} Opening EventStream on ${host}`)),
        switchMap(host =>
            from(new TangoRestApiRequest(`${host}/tango/subscriptions`, {...options,mode:'cors'}, fetch)
                .post("", this.subscription.events.map(event => event.target)))),
        map(resp => this.subscription = new Subscription({...resp,url: `${host}/tango/subscriptions/${resp.id}`, source: new EventStream(`${host}/tango/subscriptions/${resp.id}/event-stream`)})),
        switchMap(subscription => subscription.source.open()),
        retryWhen(err => err.pipe(
            tap(err=> console.error(`${streamId} EventStream error!`,err)),
            delay(kEventSourceOpenTimeout)
        )),
        tap(() => console.debug(`${streamId} EventStream is open`)),
        tap(() => this.subscription.events
            .forEach(event => this.subscribe(event))),
        share()
    )
}
function createConnection ( host , options ) { const streamId = + new Date ( ) ; return of ( host ) . pipe ( tap ( host => console . debug ( ` ${ streamId } ${ host } ` ) ) , switchMap ( host => from ( new TangoRestApiRequest ( ` ${ host } ` , { ... options , mode : 'cors' } , fetch ) . post ( "" , this . subscription . events . map ( event => event . target ) ) ) ) , map ( resp => this . subscription = new Subscription ( { ... resp , url : ` ${ host } ${ resp . id } ` , source : new EventStream ( ` ${ host } ${ resp . id } ` ) } ) ) , switchMap ( subscription => subscription . source . open ( ) ) , retryWhen ( err => err . pipe ( tap ( err => console . error ( ` ${ streamId } ` , err ) ) , delay ( kEventSourceOpenTimeout ) ) ) , tap ( ( ) => console . debug ( ` ${ streamId } ` ) ) , tap ( ( ) => this . subscription . events . forEach ( event => this . subscribe ( event ) ) ) , share ( ) ) }
Creates shared Observable that is served as a connection to Subscriptions host
 @param {string} host
 @param {{}} options
Creates shared Observable that is served as a connection to Subscriptions host @param { string } host @param {{ }} options