Skip to content
Snippets Groups Projects
Commit faedd266 authored by jojohoch's avatar jojohoch
Browse files

[player] Avoid sending change notification twice in PlayerStateDirective

- Refactor subscriptions for verona commands
parent 5014b9f5
No related branches found
No related tags found
No related merge requests found
import { Directive, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core'; import {
Directive, Input, OnChanges, OnInit, SimpleChanges
} from '@angular/core';
import { import {
PlayerState, RunningState PlayerState, RunningState
} from 'player/modules/verona/models/verona'; } from 'player/modules/verona/models/verona';
import { BehaviorSubject, Subject } from 'rxjs'; import {
BehaviorSubject, map, merge, Subject
} from 'rxjs';
import { VeronaSubscriptionService } from 'player/modules/verona/services/verona-subscription.service'; import { VeronaSubscriptionService } from 'player/modules/verona/services/verona-subscription.service';
import { VeronaPostService } from 'player/modules/verona/services/verona-post.service'; import { VeronaPostService } from 'player/modules/verona/services/verona-post.service';
import { takeUntil } from 'rxjs/operators'; import { takeUntil } from 'rxjs/operators';
...@@ -25,7 +29,6 @@ export class PlayerStateDirective implements OnInit, OnChanges { ...@@ -25,7 +29,6 @@ export class PlayerStateDirective implements OnInit, OnChanges {
ngOnInit(): void { ngOnInit(): void {
this.initSubscriptions(); this.initSubscriptions();
this.sendVopStateChangedNotification();
} }
ngOnChanges(changes: SimpleChanges): void { ngOnChanges(changes: SimpleChanges): void {
...@@ -35,15 +38,15 @@ export class PlayerStateDirective implements OnInit, OnChanges { ...@@ -35,15 +38,15 @@ export class PlayerStateDirective implements OnInit, OnChanges {
} }
private initSubscriptions(): void { private initSubscriptions(): void {
this.veronaSubscriptionService.vopContinueCommand merge(
.pipe(takeUntil(this.ngUnsubscribe)) this.veronaSubscriptionService.vopContinueCommand
.subscribe(() => this.setAndSendRunningState(true)); .pipe(map(() => true)),
this.veronaSubscriptionService.vopStopCommand this.veronaSubscriptionService.vopStopCommand
.pipe(takeUntil(this.ngUnsubscribe)) .pipe(map(() => false)),
.subscribe(() => this.setAndSendRunningState(false)); this.veronaSubscriptionService.vopGetStateRequest
this.veronaSubscriptionService.vopGetStateRequest .pipe(map(message => (!message.stop && this.state === 'running')))
.pipe(takeUntil(this.ngUnsubscribe)) ).pipe(takeUntil(this.ngUnsubscribe))
.subscribe(message => this.setAndSendRunningState((!message.stop && this.state === 'running'))); .subscribe(isRunning => this.setAndSendRunningState(isRunning));
} }
private get state(): RunningState { private get state(): RunningState {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment