diff options
author | Joffrey Bion <joffrey.bion@amadeus.com> | 2017-07-21 10:00:07 +0200 |
---|---|---|
committer | Joffrey Bion <joffrey.bion@amadeus.com> | 2017-07-21 16:29:16 +0200 |
commit | 859bafb1e4223216d8d818fb5566fd42aaf80705 (patch) | |
tree | 25994f3165019e5703c9647b3c435f86eb056cbb /frontend/src/utils/websocket.js | |
parent | Rename actions in games.js (GAME -> GAMES) (diff) | |
download | seven-wonders-859bafb1e4223216d8d818fb5566fd42aaf80705.tar.gz seven-wonders-859bafb1e4223216d8d818fb5566fd42aaf80705.tar.bz2 seven-wonders-859bafb1e4223216d8d818fb5566fd42aaf80705.zip |
Isolate Seven Wonders API from sagas
Diffstat (limited to 'frontend/src/utils/websocket.js')
-rw-r--r-- | frontend/src/utils/websocket.js | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/frontend/src/utils/websocket.js b/frontend/src/utils/websocket.js deleted file mode 100644 index 6acd0806..00000000 --- a/frontend/src/utils/websocket.js +++ /dev/null @@ -1,50 +0,0 @@ -// @flow -import SockJS from 'sockjs-client'; -import Stomp from 'webstomp-client'; -import { eventChannel } from 'redux-saga'; - -const wsURL = '/seven-wonders-websocket'; - -export type FrameType = { - body: string, - command: string, - header: { - 'heart-beat': number, - 'user-name': string, - version: string - } -}; -export type SocketType = { - connect: (headers: Object, onSucces: (frame: FrameType) => void, onReject: (error: any) => void) => void, - subscribe: (path: string, callback: (event: any) => void) => Object -}; -export type SocketSubscriptionType = { - id: string, - unsubscribe: () => void -}; -export type SocketEventType = { - body: string -}; -export type SocketObjectType = { - frame: FrameType, - socket: SocketType -}; - -export const createWsConnection = (headers: Object = {}): Promise<SocketObjectType> => - new Promise((resolve, reject) => { - let socket: SocketType = Stomp.over(new SockJS(wsURL), { - debug: process.env.NODE_ENV !== 'production', - }); - socket.connect(headers, (frame: FrameType) => resolve({ frame, socket }), reject); - }); - -export const createSubscriptionChannel = (socket: SocketType, path: string) => { - return eventChannel((emitter: (data: any) => void) => { - const socketSubscription: SocketSubscriptionType = socket.subscribe(path, (event: SocketEventType) => { - // not all events have a body - const value = event.body && JSON.parse(event.body); - emitter(value); - }); - return () => socketSubscription.unsubscribe(); - }); -}; |