Skip to content

Commit

Permalink
fix(ui): allow to connect to a websocket-only server
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed May 9, 2021
1 parent 51fac0a commit 3ec64a6
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
30 changes: 21 additions & 9 deletions ui/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<ConnectionModal
:is-open="showConnectionModal"
:initial-server-url="serverUrl"
:initial-ws-only="wsOnly"
:is-connecting="isConnecting"
:error="connectionError"
@submit="onSubmit"
Expand Down Expand Up @@ -59,6 +60,7 @@ export default {
computed: {
...mapState({
serverUrl: (state) => state.connection.serverUrl,
wsOnly: (state) => state.connection.wsOnly,
backgroundColor: (state) =>
state.config.darkTheme ? "" : "grey lighten-5",
}),
Expand All @@ -80,7 +82,7 @@ export default {
},
methods: {
tryConnect(serverUrl, auth) {
tryConnect(serverUrl, auth, wsOnly) {
this.isConnecting = true;
if (SocketHolder.socket) {
SocketHolder.socket.disconnect();
Expand All @@ -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", () => {
Expand All @@ -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);
});
Expand Down Expand Up @@ -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
);
},
},
Expand All @@ -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;
}
Expand Down
10 changes: 10 additions & 0 deletions ui/src/components/ConnectionModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
type="password"
></v-text-field>

<v-switch
v-model="wsOnly"
:label="$t('connection.websocket-only')"
inset
dense
/>

<v-btn
:loading="isConnecting"
:disabled="isConnecting || !isValid"
Expand All @@ -49,12 +56,14 @@ export default {
isOpen: Boolean,
isConnecting: Boolean,
initialServerUrl: String,
initialWsOnly: Boolean,
error: String,
},
data() {
return {
serverUrl: this.initialServerUrl,
wsOnly: this.initialWsOnly,
username: "",
password: "",
};
Expand All @@ -75,6 +84,7 @@ export default {
onSubmit() {
this.$emit("submit", {
serverUrl: this.serverUrl,
wsOnly: this.wsOnly,
username: this.username,
password: this.password,
});
Expand Down
3 changes: 2 additions & 1 deletion ui/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"password": "Password",
"connect": "Connect",
"invalid-credentials": "Invalid credentials",
"error": "Error"
"error": "Error",
"websocket-only": "WebSocket only?"
},
"dashboard": {
"title": "Dashboard"
Expand Down
3 changes: 2 additions & 1 deletion ui/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"password": "Mot de passe",
"connect": "Se connecter",
"invalid-credentials": "Identifiants invalides",
"error": "Erreur"
"error": "Erreur",
"websocket-only": "WebSocket uniquement ?"
},
"dashboard": {
"title": "Accueil"
Expand Down
6 changes: 5 additions & 1 deletion ui/src/store/modules/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@ export default {
namespaced: true,
state: {
serverUrl: "",
wsOnly: false,
sessionId: "",
connected: false,
},
mutations: {
init(state) {
if (isLocalStorageAvailable) {
state.serverUrl = localStorage.getItem("server_url");
state.wsOnly = localStorage.getItem("ws_only") === "true";
state.sessionId = localStorage.getItem("session_id");
}
},
saveServerUrl(state, serverUrl) {
saveConfig(state, { serverUrl, wsOnly }) {
state.serverUrl = serverUrl;
state.wsOnly = wsOnly;
if (isLocalStorageAvailable) {
localStorage.setItem("server_url", serverUrl);
localStorage.setItem("ws_only", wsOnly);
}
},
saveSessionId(state, sessionId) {
Expand Down

0 comments on commit 3ec64a6

Please sign in to comment.