Use lettable RxJS operators

This commit is contained in:
Bálint Bokros 2018-01-11 16:04:29 +01:00
parent 8187f11068
commit d66705f2f2

View File

@ -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');
}