summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorVictor Chabbert <chabbertvi@eisti.eu>2016-12-19 01:16:26 +0100
committerVictor Chabbert <chabbertvi@eisti.eu>2016-12-19 01:16:26 +0100
commit1b7f038c53568cb1c2753f89497000fff37e0f28 (patch)
treef4c38364fe30375b7cfb281c1fa1a0df28544817 /src/main
parentAdd redux-saga to handle effects (diff)
downloadseven-wonders-1b7f038c53568cb1c2753f89497000fff37e0f28.tar.gz
seven-wonders-1b7f038c53568cb1c2753f89497000fff37e0f28.tar.bz2
seven-wonders-1b7f038c53568cb1c2753f89497000fff37e0f28.zip
Initial work on websocket sagas
Diffstat (limited to 'src/main')
-rw-r--r--src/main/js/package.json4
-rw-r--r--src/main/js/src/wsSagas.js42
-rw-r--r--src/main/js/yarn.lock21
3 files changed, 64 insertions, 3 deletions
diff --git a/src/main/js/package.json b/src/main/js/package.json
index 30ecc9e2..eff6dc38 100644
--- a/src/main/js/package.json
+++ b/src/main/js/package.json
@@ -12,7 +12,9 @@
"react-redux": "^5.0.1",
"react-router": "4.0.0-alpha.6",
"redux": "^3.6.0",
- "redux-saga": "^0.13.0"
+ "redux-saga": "^0.13.0",
+ "sockjs-client": "latest",
+ "webstomp-client": "^1.0.3"
},
"scripts": {
"start": "react-scripts start",
diff --git a/src/main/js/src/wsSagas.js b/src/main/js/src/wsSagas.js
new file mode 100644
index 00000000..b6dcce95
--- /dev/null
+++ b/src/main/js/src/wsSagas.js
@@ -0,0 +1,42 @@
+import { call, put, take } from 'redux-saga/effects'
+import SockJS from 'sockjs-client'
+import Stomp from 'webstomp-client'
+const wsURL = '/seven-wonders-websocket'
+let socket = null;
+
+const openSocket = () => {
+ socket = Stomp.over(new SockJS(wsURL))
+ socket.connect({}, (frame) => {
+ console.log('Connected')
+
+ socket.subscribe('/user/queue/errors', (msg) =>
+ console.error('/user/queue/errors', msg)
+ )
+
+ socket.subscribe('/topic/games', (msg) => {
+ const game = JSON.parse(msg)
+ console.error('/topic/games', game)
+ })
+
+ socket.subscribe('/user/queue/join-game', (msg) => {
+ const game = JSON.parse(msg)
+ console.error('/user/queue/join-game', game)
+ })
+ })
+}
+
+const disconnect = () => {
+ if (!socket) {
+ socket.disconnect()
+ console.log('Disconnected')
+ }
+}
+
+export default function* wsSagas() {
+ const channel = yield call(openSocket)
+
+ while (true) {
+ const action = yield take(channel)
+ yield put(action)
+ }
+}
diff --git a/src/main/js/yarn.lock b/src/main/js/yarn.lock
index 983f930a..bd375f1c 100644
--- a/src/main/js/yarn.lock
+++ b/src/main/js/yarn.lock
@@ -1940,7 +1940,7 @@ events@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/events/-/events-1.1.1.tgz#9ebdb7635ad099c70dcc4c2a1f5004288e8bd924"
-eventsource@^0.1.3:
+eventsource@^0.1.3, eventsource@~0.1.6:
version "0.1.6"
resolved "https://registry.yarnpkg.com/eventsource/-/eventsource-0.1.6.tgz#0acede849ed7dd1ccc32c811bb11b944d4f29232"
dependencies:
@@ -2035,6 +2035,12 @@ faye-websocket@^0.10.0:
dependencies:
websocket-driver ">=0.5.1"
+faye-websocket@~0.11.0:
+ version "0.11.0"
+ resolved "https://registry.yarnpkg.com/faye-websocket/-/faye-websocket-0.11.0.tgz#d9ccf0e789e7db725d74bc4877d23aa42972ac50"
+ dependencies:
+ websocket-driver ">=0.5.1"
+
faye-websocket@~0.7.3:
version "0.7.3"
resolved "https://registry.yarnpkg.com/faye-websocket/-/faye-websocket-0.7.3.tgz#cc4074c7f4a4dfd03af54dd65c354b135132ce11"
@@ -4678,6 +4684,17 @@ sockjs-client@^1.0.3, sockjs-client@1.0.3:
json3 "^3.3.2"
url-parse "^1.0.1"
+sockjs-client@latest:
+ version "1.1.1"
+ resolved "https://registry.yarnpkg.com/sockjs-client/-/sockjs-client-1.1.1.tgz#284843e9a9784d7c474b1571b3240fca9dda4bb0"
+ dependencies:
+ debug "^2.2.0"
+ eventsource "~0.1.6"
+ faye-websocket "~0.11.0"
+ inherits "^2.0.1"
+ json3 "^3.3.2"
+ url-parse "^1.1.1"
+
sockjs@^0.3.15:
version "0.3.18"
resolved "https://registry.yarnpkg.com/sockjs/-/sockjs-0.3.18.tgz#d9b289316ca7df77595ef299e075f0f937eb4207"
@@ -5039,7 +5056,7 @@ url-loader@0.5.7:
loader-utils "0.2.x"
mime "1.2.x"
-url-parse@^1.0.1:
+url-parse@^1.0.1, url-parse@^1.1.1:
version "1.1.7"
resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.1.7.tgz#025cff999653a459ab34232147d89514cc87d74a"
dependencies:
bgstack15