mirror of
				https://github.com/avatao-content/frontend-tutorial-framework
				synced 2025-11-04 11:52:54 +00:00 
			
		
		
		
	Update WebSocketService according to the new API
This commit is contained in:
		@@ -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;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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 {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user