From 4dc031cf8b3f5c7f600ab66cef1e38f8cfad9a23 Mon Sep 17 00:00:00 2001 From: chsakell Date: Mon, 3 Oct 2016 15:03:46 +0300 Subject: [PATCH] hide show subscribe buttons --- app/shared/components/match.component.html | 9 ++++++--- app/shared/components/match.component.ts | 7 +++++++ app/shared/interfaces.ts | 5 +++-- app/shared/services/feed.service.ts | 4 ++++ 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/shared/components/match.component.html b/app/shared/components/match.component.html index 938b2a6..e1e7091 100644 --- a/app/shared/components/match.component.html +++ b/app/shared/components/match.component.html @@ -19,13 +19,16 @@ {{match.Type}} - + - - + + diff --git a/app/shared/components/match.component.ts b/app/shared/components/match.component.ts index 7d957db..62c614f 100644 --- a/app/shared/components/match.component.ts +++ b/app/shared/components/match.component.ts @@ -10,6 +10,7 @@ import { FeedService } from '../services/feed.service'; export class MatchComponent implements OnInit { @Input() match: Match; + subscribed: boolean; constructor(private feedService: FeedService) { } @@ -17,6 +18,12 @@ export class MatchComponent implements OnInit { subscribe() { console.log(this.match.Id); + this.subscribed = true; this.feedService.subscribeToFeed(this.match.Id); } + + unsubscribe() { + this.subscribed = false; + this.feedService.unsubscribeToFeed(this.match.Id); + } } \ No newline at end of file diff --git a/app/shared/interfaces.ts b/app/shared/interfaces.ts index d8d4ca7..3bdd849 100644 --- a/app/shared/interfaces.ts +++ b/app/shared/interfaces.ts @@ -11,14 +11,15 @@ export interface FeedProxy { export interface FeedClient { userConnected: (user: any) => void; userDisconnected: (id: string) => void; - + updateMatch: (match: Match) => void; addFeed: (feed: Feed) => void; messageReceived: (message: string) => void; } export interface FeedServer { - subscribe(matchId: number) : void; + subscribe(matchId: number): void; + unsubscribe(matchId: number): void; } export enum ConnectionState { diff --git a/app/shared/services/feed.service.ts b/app/shared/services/feed.service.ts index 00eeece..3580a08 100644 --- a/app/shared/services/feed.service.ts +++ b/app/shared/services/feed.service.ts @@ -121,4 +121,8 @@ export class FeedService { public subscribeToFeed(matchId: number) { this.server.subscribe(matchId); } + + public unsubscribeToFeed(matchId: number) { + this.server.unsubscribe(matchId); + } } \ No newline at end of file