mirror of
				https://github.com/avatao-content/frontend-tutorial-framework
				synced 2025-11-04 12:22:54 +00:00 
			
		
		
		
	Use lettable RxJS operators
This commit is contained in:
		@@ -2,16 +2,14 @@ import { Injectable } from '@angular/core';
 | 
			
		||||
import { QueueingSubject } from 'queueing-subject';
 | 
			
		||||
import { Observable } from 'rxjs/Observable';
 | 
			
		||||
import websocketConnect from 'rxjs-websockets';
 | 
			
		||||
import { filter, map, share } from 'rxjs/operators';
 | 
			
		||||
import { WSMessage } from './wsmessage';
 | 
			
		||||
import 'rxjs/add/operator/map';
 | 
			
		||||
import 'rxjs/add/operator/filter';
 | 
			
		||||
import 'rxjs/add/operator/share';
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function jsonWebsocketConnect(url: string, input: Observable<object>, protocols?: string | string[]) {
 | 
			
		||||
  const jsonInput = input.map(message => JSON.stringify(message));
 | 
			
		||||
  const jsonInput = input.pipe(map(message => JSON.stringify(message)));
 | 
			
		||||
  const { connectionStatus, messages } = websocketConnect(url, jsonInput, protocols);
 | 
			
		||||
  const jsonMessages = messages.map(message => JSON.parse(message));
 | 
			
		||||
  const jsonMessages = messages.pipe(map(message => JSON.parse(message)));
 | 
			
		||||
  return { connectionStatus, messages: jsonMessages };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -35,7 +33,10 @@ export class WebSocketService {
 | 
			
		||||
    this.downlink = jsonWebsocketConnect(
 | 
			
		||||
      'ws://localhost:4242/ws',
 | 
			
		||||
      this.uplink = new QueueingSubject<object>()
 | 
			
		||||
    ).messages.map(message => <WSMessage> message).share();
 | 
			
		||||
    ).messages.pipe(
 | 
			
		||||
        map(message => <WSMessage<undefined>> message),
 | 
			
		||||
        share()
 | 
			
		||||
      );
 | 
			
		||||
    console.log('ws connected');
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user