mirror of
https://github.com/avatao-content/frontend-tutorial-framework
synced 2024-12-05 02:01:32 +00:00
Use lettable RxJS operators
This commit is contained in:
parent
8187f11068
commit
d66705f2f2
@ -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');
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user