diff options
Diffstat (limited to 'frontend/src/utils')
-rw-r--r-- | frontend/src/utils/createWebSocketConnection.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/frontend/src/utils/createWebSocketConnection.js b/frontend/src/utils/createWebSocketConnection.js new file mode 100644 index 00000000..b0924976 --- /dev/null +++ b/frontend/src/utils/createWebSocketConnection.js @@ -0,0 +1,14 @@ +import SockJS from 'sockjs-client' +import Stomp from 'webstomp-client' +const wsURL = 'http://localhost:8080/seven-wonders-websocket' + +const createConnection = (headers = {}) => new Promise((resolve, reject) => { + let socket = Stomp.over(new SockJS(wsURL), { + debug: process.env.NODE_ENV !== "production" + }) + socket.connect(headers, (frame) => { + return resolve({ frame, socket }) + }, reject) +}) + +export default createConnection |