I have a method which calls a another service to play a stream url within a player. playStream$()
returns some streaming data which should be returned from the play$()
method as well. As a side effect while playing a stream, i want to send a heartbeat, triggered by an interval.
play$(streamId: number, position?: number): Observable<Stream> {
return this.playerService.playStream$(streamId, position)
.pipe(
tap(() => this.heartbeat$(streamId).subscribe())
);
}
Since it's not a good practice to subscribe to another observable inside a tap()
operator, i'm looking for a solution with switchMap
, mergeMap
oder similar. BUT: I'm not interested in the heartbeat's emitted value. I just need the Stream
data, as soon playStream$()
emits. The heartbeat is just a side effect, which could even fail. heartbeat$()
has a takeUntil
Operator who makes sure to unsubscribe from it if nessecairy.
I allready tried mergeMap
and switchMap
but with the effect, that the subscriber from play$()
won't get the Stream
data immediately.
What's the RxJS way to solve this?