From 3ec64a62d331c5100c026313700119a4a97df64a Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Sun, 9 May 2021 23:16:00 +0200 Subject: [PATCH] fix(ui): allow to connect to a websocket-only server Related: - https://github.com/socketio/socket.io-admin-ui/pull/4 - https://github.com/socketio/engine.io-client/issues/575 --- ui/src/App.vue | 30 +++++++++++++++++++-------- ui/src/components/ConnectionModal.vue | 10 +++++++++ ui/src/locales/en.json | 3 ++- ui/src/locales/fr.json | 3 ++- ui/src/store/modules/connection.js | 6 +++++- 5 files changed, 40 insertions(+), 12 deletions(-) diff --git a/ui/src/App.vue b/ui/src/App.vue index d9a07b4..cd5cb87 100644 --- a/ui/src/App.vue +++ b/ui/src/App.vue @@ -15,6 +15,7 @@ state.connection.serverUrl, + wsOnly: (state) => state.connection.wsOnly, backgroundColor: (state) => state.config.darkTheme ? "" : "grey lighten-5", }), @@ -80,7 +82,7 @@ export default { }, methods: { - tryConnect(serverUrl, auth) { + tryConnect(serverUrl, auth, wsOnly) { this.isConnecting = true; if (SocketHolder.socket) { SocketHolder.socket.disconnect(); @@ -92,6 +94,7 @@ export default { forceNew: true, reconnection: false, withCredentials: true, // needed for cookie-based sticky-sessions + transports: wsOnly ? ["websocket"] : ["polling", "websocket"], auth, }); socket.once("connect", () => { @@ -100,7 +103,7 @@ export default { this.isConnecting = false; socket.io.reconnection(true); - this.$store.commit("connection/saveServerUrl", serverUrl); + this.$store.commit("connection/saveConfig", { serverUrl, wsOnly }); SocketHolder.socket = socket; this.registerEventListeners(socket); }); @@ -154,10 +157,14 @@ export default { }, onSubmit(form) { - this.tryConnect(form.serverUrl, { - username: form.username, - password: form.password, - }); + this.tryConnect( + form.serverUrl, + { + username: form.username, + password: form.password, + }, + form.wsOnly + ); }, }, @@ -166,9 +173,14 @@ export default { if (this.serverUrl) { const sessionId = this.$store.state.connection.sessionId; - this.tryConnect(this.serverUrl, { - sessionId, - }); + const wsOnly = this.$store.state.connection.wsOnly; + this.tryConnect( + this.serverUrl, + { + sessionId, + }, + wsOnly + ); } else { this.showConnectionModal = true; } diff --git a/ui/src/components/ConnectionModal.vue b/ui/src/components/ConnectionModal.vue index f166691..94725c9 100644 --- a/ui/src/components/ConnectionModal.vue +++ b/ui/src/components/ConnectionModal.vue @@ -25,6 +25,13 @@ type="password" > + +