Update WebSocketService according to the new API

This commit is contained in:
R. Richard 2019-08-07 10:25:09 +02:00
parent 116401fe80
commit 053b4816d1
2 changed files with 5 additions and 7 deletions

View File

@ -1,8 +1,6 @@
// Copyright (C) 2018 Avatao.com Innovative Learning Kft.
// All Rights Reserved. See LICENSE file for details.
export class WebSocketMessage<T> {
export interface WebSocketMessage {
key: string;
trigger?: string;
data: T;
}

View File

@ -19,7 +19,7 @@ function jsonWebsocketConnect(url: string, input: Observable<object>, protocols?
@Injectable()
export class WebSocketService {
private uplink: QueueingSubject<object>;
public downlink: Observable<WebSocketMessage<undefined>>;
public downlink: Observable<WebSocketMessage>;
constructor() {}
@ -33,14 +33,14 @@ export class WebSocketService {
wsproto + window.location.host + '/ws',
this.uplink = new QueueingSubject<object>()
).messages.pipe(
map(message => <WebSocketMessage<undefined>> message),
map(message => <WebSocketMessage> message),
share()
);
console.log('ws connected');
}
public observeKey<T>(key: string): Observable<WebSocketMessage<T>> {
return this.downlink.pipe(filter(message => message.key === key));
public observeKey<T extends WebSocketMessage>(key: string): Observable<T> {
return this.downlink.pipe(filter(message => message.key.startsWith(key)), map(message => <T> message));
}
public send(key: string, data?: any, trigger?: any): void {