set connection id on start

This commit is contained in:
chsakell
2016-10-05 12:54:45 +03:00
parent 8a8055d0ba
commit 69afcd0108
9 changed files with 35 additions and 15 deletions

View File

@@ -3,6 +3,6 @@
<match [match]="match" (updateSubscription)="updateSubscription($event)"></match>
</div>
<div class="col-md-4">
<chat [matches]="matches"></chat>
<chat [matches]="matches" [connection]="connectionId"></chat>
</div>
</div>

View File

@@ -12,6 +12,7 @@ import { SignalRConnectionStatus } from '../shared/interfaces';
export class HomeComponent implements OnInit {
matches: Match[];
connectionId: string;
error: any;
constructor(private dataService: DataService,
@@ -20,6 +21,8 @@ export class HomeComponent implements OnInit {
ngOnInit() {
let self = this;
self.listenForConnection();
self.feedService.connectionState
.subscribe(
connectionState => {
@@ -60,7 +63,6 @@ export class HomeComponent implements OnInit {
for (var i = 0; i < self.matches.length; i++) {
if (self.matches[i].Id === feed.MatchId) {
if (!self.matches[i].Feeds) {
console.log('initializing for match ' + self.matches[i].Id);
self.matches[i].Feeds = new Array<Feed>();
}
self.matches[i].Feeds.unshift(feed);
@@ -74,8 +76,19 @@ export class HomeComponent implements OnInit {
});
}
listenForConnection() {
let self = this;
// Listen for connected / disconnected events
self.feedService.setConnectionId.subscribe(
id => {
console.log(id);
self.connectionId = id;
}
);
}
updateSubscription(subscription: any) {
if(<boolean>subscription.subscribe === true)
if (<boolean>subscription.subscribe === true)
this.feedService.subscribeToFeed(<number>subscription.matchId);
else
this.feedService.unsubscribeFromFeed(<number>subscription.matchId);