mirror of
https://github.com/chsakell/aspnet-core-signalr-angular.git
synced 2025-12-22 17:27:48 +00:00
add hub server methods
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
<span class="label label-success">{{match.Type}}</span>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" class="btn btn-default btn-xs">
|
||||
<button type="button" class="btn btn-default btn-xs" (click)="subscribe()">
|
||||
Subscribe to feed
|
||||
</button>
|
||||
</td>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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<Match>();
|
||||
private messageReceivedSubject = new Subject<string>();
|
||||
|
||||
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 = <FeedSignalR>$.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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user