mirror of
https://github.com/avatao-content/frontend-tutorial-framework
synced 2025-07-03 21:46:22 +00:00
Move all message types to a standardised location
This commit is contained in:
@ -6,7 +6,7 @@ import { QueueingSubject } from './queueing-subject';
|
||||
import { Observable } from 'rxjs';
|
||||
import websocketConnect from 'rxjs-websockets';
|
||||
import { filter, map, share } from 'rxjs/operators';
|
||||
import { WSMessage } from './wsmessage';
|
||||
import { WebSocketMessage } from '../message.types/websocket.message';
|
||||
|
||||
|
||||
function jsonWebsocketConnect(url: string, input: Observable<object>, protocols?: string | string[]) {
|
||||
@ -19,7 +19,7 @@ function jsonWebsocketConnect(url: string, input: Observable<object>, protocols?
|
||||
@Injectable()
|
||||
export class WebSocketService {
|
||||
private uplink: QueueingSubject<object>;
|
||||
public downlink: Observable<WSMessage<undefined>>;
|
||||
public downlink: Observable<WebSocketMessage<undefined>>;
|
||||
|
||||
constructor() {}
|
||||
|
||||
@ -33,13 +33,13 @@ export class WebSocketService {
|
||||
wsproto + window.location.host + '/ws',
|
||||
this.uplink = new QueueingSubject<object>()
|
||||
).messages.pipe(
|
||||
map(message => <WSMessage<undefined>> message),
|
||||
map(message => <WebSocketMessage<undefined>> message),
|
||||
share()
|
||||
);
|
||||
console.log('ws connected');
|
||||
}
|
||||
|
||||
public observeKey<T>(key: string): Observable<WSMessage<T>> {
|
||||
public observeKey<T>(key: string): Observable<WebSocketMessage<T>> {
|
||||
return this.downlink.pipe(filter(message => message.key === key));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user