Add optional trigger argument to WebSocketService

This commit is contained in:
Kristóf Tóth 2018-03-14 17:06:56 +01:00
parent 3b7b597b3c
commit 3b7c8daafe

View File

@ -43,14 +43,19 @@ export class WebSocketService {
return this.downlink.pipe(filter(message => message.key === key));
}
public send(key: string, data: any): void {
public send(key: string, data?: any, trigger?: any): void {
// If the WebSocket is not connected then the QueueingSubject will ensure
// that messages are queued and delivered when the WebSocket reconnects.
// A regular Subject can be used to discard messages sent when the WebSocket
// is disconnected.
this.uplink.next({
'key': key,
'data': data
});
// TODO: do this nicer?
const message = {'key': key};
if (data) {
message['data'] = data;
}
if (trigger) {
message['trigger'] = trigger;
}
this.uplink.next(message);
}
}