aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/ducks/connection.js
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2017-04-26 17:51:33 +0200
committerMaximilian Hils <git@maximilianhils.com>2017-04-29 19:34:51 +0200
commit8f1b763082d0d00bee0b1e97f9c8bfb740083c63 (patch)
tree7fb2d09499ce7bc602342394b023af1b168b41ad /web/src/js/ducks/connection.js
parentbd88733a0a8c05146b570ba400f2820edd6ad8cc (diff)
downloadmitmproxy-8f1b763082d0d00bee0b1e97f9c8bfb740083c63.tar.gz
mitmproxy-8f1b763082d0d00bee0b1e97f9c8bfb740083c63.tar.bz2
mitmproxy-8f1b763082d0d00bee0b1e97f9c8bfb740083c63.zip
[web] add connection indicator
Diffstat (limited to 'web/src/js/ducks/connection.js')
-rw-r--r--web/src/js/ducks/connection.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/web/src/js/ducks/connection.js b/web/src/js/ducks/connection.js
new file mode 100644
index 00000000..ffa2c309
--- /dev/null
+++ b/web/src/js/ducks/connection.js
@@ -0,0 +1,44 @@
+export const ConnectionState = {
+ INIT: Symbol("init"),
+ FETCHING: Symbol("fetching"), // WebSocket is established, but still startFetching resources.
+ ESTABLISHED: Symbol("established"),
+ ERROR: Symbol("error"),
+ OFFLINE: Symbol("offline"), // indicates that there is no live (websocket) backend.
+}
+
+const defaultState = {
+ state: ConnectionState.INIT,
+ message: null,
+}
+
+export default function reducer(state = defaultState, action) {
+ switch (action.type) {
+
+ case ConnectionState.ESTABLISHED:
+ case ConnectionState.FETCHING:
+ case ConnectionState.ERROR:
+ case ConnectionState.OFFLINE:
+ return {
+ state: action.type,
+ message: action.message
+ }
+
+ default:
+ return state
+ }
+}
+
+export function startFetching() {
+ return { type: ConnectionState.FETCHING }
+}
+
+export function connectionEstablished() {
+ return { type: ConnectionState.ESTABLISHED }
+}
+
+export function connectionError(message) {
+ return { type: ConnectionState.ERROR, message }
+}
+export function setOffline() {
+ return { type: ConnectionState.OFFLINE }
+}