diff --git a/Hubs/Broadcaster.cs b/Hubs/Broadcaster.cs
index 9f77b7d..9dd8849 100644
--- a/Hubs/Broadcaster.cs
+++ b/Hubs/Broadcaster.cs
@@ -13,5 +13,15 @@ namespace LiveGameFeed.Hubs
{
return Clients.All.messageReceived(Context.ConnectionId + "> " + message);
}
+
+ public Task Subscribe(int matchId)
+ {
+ return Groups.Add(Context.ConnectionId, matchId.ToString());
+ }
+
+ public Task Unsubscribe(int matchId)
+ {
+ return Groups.Remove(Context.ConnectionId, matchId.ToString());
+ }
}
}
\ No newline at end of file
diff --git a/app/shared/components/match.component.html b/app/shared/components/match.component.html
index a70583c..a2e79ed 100644
--- a/app/shared/components/match.component.html
+++ b/app/shared/components/match.component.html
@@ -19,7 +19,7 @@
{{match.Type}}
- |
diff --git a/app/shared/components/match.component.ts b/app/shared/components/match.component.ts
index 0ced8ec..94dfdec 100644
--- a/app/shared/components/match.component.ts
+++ b/app/shared/components/match.component.ts
@@ -1,6 +1,7 @@
import { Component, OnInit, Input } from '@angular/core';
import { Match } from '../interfaces';
+import { FeedService } from '../services/feed.service';
@Component({
selector: 'match',
@@ -10,7 +11,12 @@ export class MatchComponent implements OnInit {
@Input() match: Match;
- constructor() { }
+ constructor(private feedService: FeedService) { }
ngOnInit() { }
+
+ subscribe() {
+ console.log(this.match.Id);
+ this.feedService.subscribeToFeed(this.match.Id);
+ }
}
\ No newline at end of file
diff --git a/app/shared/interfaces.ts b/app/shared/interfaces.ts
index a11ed85..4cd9830 100644
--- a/app/shared/interfaces.ts
+++ b/app/shared/interfaces.ts
@@ -4,7 +4,8 @@ export interface FeedSignalR extends SignalR {
}
export interface FeedProxy {
- client: FeedClient
+ client: FeedClient;
+ server: FeedServer;
}
export interface FeedClient {
@@ -15,6 +16,10 @@ export interface FeedClient {
messageReceived: (message: string) => void;
}
+export interface FeedServer {
+ subscribe(matchId: number) : void;
+}
+
export enum ConnectionState {
Connected = 1,
Disconnected = 2,
diff --git a/app/shared/services/feed.service.ts b/app/shared/services/feed.service.ts
index c204f3d..379fc3c 100644
--- a/app/shared/services/feed.service.ts
+++ b/app/shared/services/feed.service.ts
@@ -5,7 +5,7 @@ import 'rxjs/add/operator/toPromise';
import { Observable } from "rxjs/Observable";
import { Subject } from "rxjs/Subject";
-import { FeedSignalR, FeedProxy, FeedClient, ConnectionState, Match } from '../interfaces';
+import { FeedSignalR, FeedProxy, FeedClient, FeedServer, ConnectionState, Match } from '../interfaces';
@Injectable()
export class FeedService {
@@ -23,6 +23,8 @@ export class FeedService {
private updateMatchSubject = new Subject();
private messageReceivedSubject = new Subject();
+ private server: FeedServer;
+
constructor(private http: Http) {
this.connectionState = this.connectionStateSubject.asObservable();
this.userConnected = this.userConnectedSubject.asObservable();
@@ -37,6 +39,7 @@ export class FeedService {
// get the signalR hub named 'broadcaster'
let connection = $.connection;
let feedHub = connection.broadcaster;
+ this.server = feedHub.server;
/**
* @desc callback when a new user connect to the chat
@@ -104,4 +107,8 @@ export class FeedService {
console.log(message);
this.messageReceivedSubject.next(message);
}
+
+ public subscribeToFeed(matchId: number) {
+ this.server.subscribe(matchId);
+ }
}
\ No newline at end of file