summaryrefslogtreecommitdiff
path: root/frontend/src/api/websocket.js
diff options
context:
space:
mode:
authorJoffrey BION <joffrey.bion@gmail.com>2017-07-25 00:33:03 +0200
committerJoffrey BION <joffrey.bion@gmail.com>2017-07-25 00:33:03 +0200
commit9a761a95851b618c39d161680752fe64fa27107d (patch)
tree6b22e49acf5aa26a96f26336d142644dead7e213 /frontend/src/api/websocket.js
parentUpdate README (diff)
downloadseven-wonders-9a761a95851b618c39d161680752fe64fa27107d.tar.gz
seven-wonders-9a761a95851b618c39d161680752fe64fa27107d.tar.bz2
seven-wonders-9a761a95851b618c39d161680752fe64fa27107d.zip
Fix types in websocket.js
Diffstat (limited to 'frontend/src/api/websocket.js')
-rw-r--r--frontend/src/api/websocket.js12
1 files changed, 6 insertions, 6 deletions
diff --git a/frontend/src/api/websocket.js b/frontend/src/api/websocket.js
index 0cf0689a..d145076b 100644
--- a/frontend/src/api/websocket.js
+++ b/frontend/src/api/websocket.js
@@ -1,6 +1,6 @@
// @flow
import SockJS from 'sockjs-client';
-import type { Client, Frame, Options, Subscription } from 'webstomp-client';
+import type { Client, Frame, Message, Options, Subscription } from 'webstomp-client';
import Stomp from 'webstomp-client';
const DEFAULT_DEBUG_OPTIONS = {
@@ -18,24 +18,24 @@ export class JsonStompClient {
this.client = client;
}
- connect(headers: Object = {}): Promise<Frame> {
+ connect(headers: Object = {}): Promise<Frame | void> {
return new Promise((resolve, reject) => {
this.client.connect(headers, resolve, reject);
});
}
subscribe<T>(path: string, callback: Callback<T>): UnsubscribeFn {
- const socketSubscription: Subscription = this.client.subscribe(path, (frame: Frame) => {
+ const socketSubscription: Subscription = this.client.subscribe(path, (message: Message) => {
// not all frames have a JSON body
- const value: T = frame && JsonStompClient.parseBody(frame);
+ const value: T | void = message && JsonStompClient.parseBody(message);
callback(value);
});
return () => socketSubscription.unsubscribe();
}
- static parseBody<T>(frame: Frame): T | void {
+ static parseBody<T>(message: Message): T | void {
try {
- return frame.body && JSON.parse(frame.body);
+ return message.body && JSON.parse(message.body);
} catch (jsonParseError) {
throw new Error('Cannot parse websocket message as JSON: ' + jsonParseError.message);
}
bgstack15