added chat table

This commit is contained in:
chsakell
2016-10-03 16:30:49 +03:00
parent df79d53626
commit 2b7a82666b
9 changed files with 119 additions and 17 deletions

View File

@@ -5,7 +5,7 @@ import 'rxjs/add/operator/toPromise';
import { Observable } from "rxjs/Observable";
import { Subject } from "rxjs/Subject";
import { FeedSignalR, FeedProxy, FeedClient, FeedServer, ConnectionState, Match, Feed } from '../interfaces';
import { FeedSignalR, FeedProxy, FeedClient, FeedServer, ConnectionState, ChatMessage, Match, Feed } from '../interfaces';
@Injectable()
export class FeedService {
@@ -17,6 +17,7 @@ export class FeedService {
updateMatch: Observable<Match>;
addFeed: Observable<Feed>;
messageReceived: Observable<string>;
addChatMessage: Observable<ChatMessage>;
private connectionStateSubject = new Subject<ConnectionState>();
private userConnectedSubject = new Subject<any>();
@@ -24,6 +25,7 @@ export class FeedService {
private updateMatchSubject = new Subject<Match>();
private addFeedSubject = new Subject<Feed>();
private messageReceivedSubject = new Subject<string>();
private addChatMessageSubject = new Subject<ChatMessage>();
private server: FeedServer;
@@ -34,6 +36,7 @@ export class FeedService {
this.updateMatch = this.updateMatchSubject.asObservable();
this.addFeed = this.addFeedSubject.asObservable();
this.messageReceived = this.messageReceivedSubject.asObservable();
this.addChatMessage = this.addChatMessageSubject.asObservable();
}
start(debug: boolean): Observable<ConnectionState> {
@@ -67,6 +70,8 @@ export class FeedService {
*/
feedHub.client.messageReceived = message => this.onMessageReceived(message);
feedHub.client.addChatMessage = chatMessage => this.onAddChatMessage(chatMessage);
if (debug) {
// for debug only, callback on connection state change
$.connection.hub.stateChanged(change => {
@@ -101,7 +106,6 @@ export class FeedService {
}
private onUserConnected(user: any) {
console.log("Chat Hub new user connected: " + user);
this.userConnectedSubject.next(user);
}
@@ -110,14 +114,19 @@ export class FeedService {
}
private onAddFeed(feed: Feed) {
console.log(feed);
this.addFeedSubject.next(feed);
}
private onMessageReceived(message: string) {
console.log(message);
this.messageReceivedSubject.next(message);
}
private onAddChatMessage(chatMessage: ChatMessage) {
console.log(chatMessage);
this.addChatMessageSubject.next(chatMessage);
}
public subscribeToFeed(matchId: number) {
this.server.subscribe(matchId);
}