From f8ad29f467d071cb02bfc3e42ba68a8124fab00b Mon Sep 17 00:00:00 2001 From: chsakell Date: Tue, 4 Oct 2016 15:41:46 +0300 Subject: [PATCH] more refactoring in feed service --- app/app.component.ts | 2 +- app/home/home.component.ts | 4 ++-- app/shared/interfaces.ts | 2 +- app/shared/services/feed.service.ts | 14 +++++++------- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/app.component.ts b/app/app.component.ts index 52efc7e..29644ac 100644 --- a/app/app.component.ts +++ b/app/app.component.ts @@ -1,7 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { FeedService } from './shared/services/feed.service'; -import { ConnectionState } from './shared/interfaces'; +import { SignalRConnectionStatus } from './shared/interfaces'; @Component({ selector: 'my-app', diff --git a/app/home/home.component.ts b/app/home/home.component.ts index 8edd94a..a1f0d5a 100644 --- a/app/home/home.component.ts +++ b/app/home/home.component.ts @@ -3,7 +3,7 @@ import { Component, OnInit } from '@angular/core'; import { FeedService } from '../shared/services/feed.service'; import { Match, Feed } from '../shared/interfaces'; import { DataService } from '../shared/services/data.service'; -import { ConnectionState } from '../shared/interfaces'; +import { SignalRConnectionStatus } from '../shared/interfaces'; @Component({ selector: 'home', @@ -23,7 +23,7 @@ export class HomeComponent implements OnInit { self.feedService.connectionState .subscribe( connectionState => { - if (connectionState == ConnectionState.Connected) { + if (connectionState == SignalRConnectionStatus.Connected) { console.log('Connected!'); self.loadMatches(); } else { diff --git a/app/shared/interfaces.ts b/app/shared/interfaces.ts index 056c3a4..f87d129 100644 --- a/app/shared/interfaces.ts +++ b/app/shared/interfaces.ts @@ -22,7 +22,7 @@ export interface FeedServer { unsubscribe(matchId: number): void; } -export enum ConnectionState { +export enum SignalRConnectionStatus { Connected = 1, Disconnected = 2, Error = 3 diff --git a/app/shared/services/feed.service.ts b/app/shared/services/feed.service.ts index 103d36e..ef94bd6 100644 --- a/app/shared/services/feed.service.ts +++ b/app/shared/services/feed.service.ts @@ -5,20 +5,20 @@ import 'rxjs/add/operator/toPromise'; import { Observable } from "rxjs/Observable"; import { Subject } from "rxjs/Subject"; -import { FeedSignalR, FeedProxy, FeedClient, FeedServer, ConnectionState, ChatMessage, Match, Feed } from '../interfaces'; +import { FeedSignalR, FeedProxy, FeedClient, FeedServer, SignalRConnectionStatus, ChatMessage, Match, Feed } from '../interfaces'; @Injectable() export class FeedService { - currentState = ConnectionState.Disconnected; - connectionState: Observable; + currentState = SignalRConnectionStatus.Disconnected; + connectionState: Observable; userConnected: Observable; updateMatch: Observable; addFeed: Observable; addChatMessage: Observable; - private connectionStateSubject = new Subject(); + private connectionStateSubject = new Subject(); private userConnectedSubject = new Subject(); private updateMatchSubject = new Subject(); @@ -36,7 +36,7 @@ export class FeedService { this.addChatMessage = this.addChatMessageSubject.asObservable(); } - start(debug: boolean): Observable { + start(debug: boolean): Observable { // only for debug $.connection.hub.logging = debug; // get the signalR hub named 'broadcaster' @@ -64,13 +64,13 @@ export class FeedService { // start the connection $.connection.hub.start() - .done(response => this.setConnectionState(ConnectionState.Connected)) + .done(response => this.setConnectionState(SignalRConnectionStatus.Connected)) .fail(error => this.connectionStateSubject.error(error)); return this.connectionState; } - private setConnectionState(connectionState: ConnectionState) { + private setConnectionState(connectionState: SignalRConnectionStatus) { console.log('connection state changed to: ' + connectionState); this.currentState = connectionState; this.connectionStateSubject.next(connectionState);