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
This commit is contained in:
parent
51fac0aeb8
commit
3ec64a62d3
|
|
@ -15,6 +15,7 @@
|
||||||
<ConnectionModal
|
<ConnectionModal
|
||||||
:is-open="showConnectionModal"
|
:is-open="showConnectionModal"
|
||||||
:initial-server-url="serverUrl"
|
:initial-server-url="serverUrl"
|
||||||
|
:initial-ws-only="wsOnly"
|
||||||
:is-connecting="isConnecting"
|
:is-connecting="isConnecting"
|
||||||
:error="connectionError"
|
:error="connectionError"
|
||||||
@submit="onSubmit"
|
@submit="onSubmit"
|
||||||
|
|
@ -59,6 +60,7 @@ export default {
|
||||||
computed: {
|
computed: {
|
||||||
...mapState({
|
...mapState({
|
||||||
serverUrl: (state) => state.connection.serverUrl,
|
serverUrl: (state) => state.connection.serverUrl,
|
||||||
|
wsOnly: (state) => state.connection.wsOnly,
|
||||||
backgroundColor: (state) =>
|
backgroundColor: (state) =>
|
||||||
state.config.darkTheme ? "" : "grey lighten-5",
|
state.config.darkTheme ? "" : "grey lighten-5",
|
||||||
}),
|
}),
|
||||||
|
|
@ -80,7 +82,7 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
tryConnect(serverUrl, auth) {
|
tryConnect(serverUrl, auth, wsOnly) {
|
||||||
this.isConnecting = true;
|
this.isConnecting = true;
|
||||||
if (SocketHolder.socket) {
|
if (SocketHolder.socket) {
|
||||||
SocketHolder.socket.disconnect();
|
SocketHolder.socket.disconnect();
|
||||||
|
|
@ -92,6 +94,7 @@ export default {
|
||||||
forceNew: true,
|
forceNew: true,
|
||||||
reconnection: false,
|
reconnection: false,
|
||||||
withCredentials: true, // needed for cookie-based sticky-sessions
|
withCredentials: true, // needed for cookie-based sticky-sessions
|
||||||
|
transports: wsOnly ? ["websocket"] : ["polling", "websocket"],
|
||||||
auth,
|
auth,
|
||||||
});
|
});
|
||||||
socket.once("connect", () => {
|
socket.once("connect", () => {
|
||||||
|
|
@ -100,7 +103,7 @@ export default {
|
||||||
this.isConnecting = false;
|
this.isConnecting = false;
|
||||||
|
|
||||||
socket.io.reconnection(true);
|
socket.io.reconnection(true);
|
||||||
this.$store.commit("connection/saveServerUrl", serverUrl);
|
this.$store.commit("connection/saveConfig", { serverUrl, wsOnly });
|
||||||
SocketHolder.socket = socket;
|
SocketHolder.socket = socket;
|
||||||
this.registerEventListeners(socket);
|
this.registerEventListeners(socket);
|
||||||
});
|
});
|
||||||
|
|
@ -154,10 +157,14 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
onSubmit(form) {
|
onSubmit(form) {
|
||||||
this.tryConnect(form.serverUrl, {
|
this.tryConnect(
|
||||||
|
form.serverUrl,
|
||||||
|
{
|
||||||
username: form.username,
|
username: form.username,
|
||||||
password: form.password,
|
password: form.password,
|
||||||
});
|
},
|
||||||
|
form.wsOnly
|
||||||
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -166,9 +173,14 @@ export default {
|
||||||
|
|
||||||
if (this.serverUrl) {
|
if (this.serverUrl) {
|
||||||
const sessionId = this.$store.state.connection.sessionId;
|
const sessionId = this.$store.state.connection.sessionId;
|
||||||
this.tryConnect(this.serverUrl, {
|
const wsOnly = this.$store.state.connection.wsOnly;
|
||||||
|
this.tryConnect(
|
||||||
|
this.serverUrl,
|
||||||
|
{
|
||||||
sessionId,
|
sessionId,
|
||||||
});
|
},
|
||||||
|
wsOnly
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
this.showConnectionModal = true;
|
this.showConnectionModal = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,13 @@
|
||||||
type="password"
|
type="password"
|
||||||
></v-text-field>
|
></v-text-field>
|
||||||
|
|
||||||
|
<v-switch
|
||||||
|
v-model="wsOnly"
|
||||||
|
:label="$t('connection.websocket-only')"
|
||||||
|
inset
|
||||||
|
dense
|
||||||
|
/>
|
||||||
|
|
||||||
<v-btn
|
<v-btn
|
||||||
:loading="isConnecting"
|
:loading="isConnecting"
|
||||||
:disabled="isConnecting || !isValid"
|
:disabled="isConnecting || !isValid"
|
||||||
|
|
@ -49,12 +56,14 @@ export default {
|
||||||
isOpen: Boolean,
|
isOpen: Boolean,
|
||||||
isConnecting: Boolean,
|
isConnecting: Boolean,
|
||||||
initialServerUrl: String,
|
initialServerUrl: String,
|
||||||
|
initialWsOnly: Boolean,
|
||||||
error: String,
|
error: String,
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
serverUrl: this.initialServerUrl,
|
serverUrl: this.initialServerUrl,
|
||||||
|
wsOnly: this.initialWsOnly,
|
||||||
username: "",
|
username: "",
|
||||||
password: "",
|
password: "",
|
||||||
};
|
};
|
||||||
|
|
@ -75,6 +84,7 @@ export default {
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
this.$emit("submit", {
|
this.$emit("submit", {
|
||||||
serverUrl: this.serverUrl,
|
serverUrl: this.serverUrl,
|
||||||
|
wsOnly: this.wsOnly,
|
||||||
username: this.username,
|
username: this.username,
|
||||||
password: this.password,
|
password: this.password,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,8 @@
|
||||||
"password": "Password",
|
"password": "Password",
|
||||||
"connect": "Connect",
|
"connect": "Connect",
|
||||||
"invalid-credentials": "Invalid credentials",
|
"invalid-credentials": "Invalid credentials",
|
||||||
"error": "Error"
|
"error": "Error",
|
||||||
|
"websocket-only": "WebSocket only?"
|
||||||
},
|
},
|
||||||
"dashboard": {
|
"dashboard": {
|
||||||
"title": "Dashboard"
|
"title": "Dashboard"
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,8 @@
|
||||||
"password": "Mot de passe",
|
"password": "Mot de passe",
|
||||||
"connect": "Se connecter",
|
"connect": "Se connecter",
|
||||||
"invalid-credentials": "Identifiants invalides",
|
"invalid-credentials": "Identifiants invalides",
|
||||||
"error": "Erreur"
|
"error": "Erreur",
|
||||||
|
"websocket-only": "WebSocket uniquement ?"
|
||||||
},
|
},
|
||||||
"dashboard": {
|
"dashboard": {
|
||||||
"title": "Accueil"
|
"title": "Accueil"
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ export default {
|
||||||
namespaced: true,
|
namespaced: true,
|
||||||
state: {
|
state: {
|
||||||
serverUrl: "",
|
serverUrl: "",
|
||||||
|
wsOnly: false,
|
||||||
sessionId: "",
|
sessionId: "",
|
||||||
connected: false,
|
connected: false,
|
||||||
},
|
},
|
||||||
|
|
@ -11,13 +12,16 @@ export default {
|
||||||
init(state) {
|
init(state) {
|
||||||
if (isLocalStorageAvailable) {
|
if (isLocalStorageAvailable) {
|
||||||
state.serverUrl = localStorage.getItem("server_url");
|
state.serverUrl = localStorage.getItem("server_url");
|
||||||
|
state.wsOnly = localStorage.getItem("ws_only") === "true";
|
||||||
state.sessionId = localStorage.getItem("session_id");
|
state.sessionId = localStorage.getItem("session_id");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
saveServerUrl(state, serverUrl) {
|
saveConfig(state, { serverUrl, wsOnly }) {
|
||||||
state.serverUrl = serverUrl;
|
state.serverUrl = serverUrl;
|
||||||
|
state.wsOnly = wsOnly;
|
||||||
if (isLocalStorageAvailable) {
|
if (isLocalStorageAvailable) {
|
||||||
localStorage.setItem("server_url", serverUrl);
|
localStorage.setItem("server_url", serverUrl);
|
||||||
|
localStorage.setItem("ws_only", wsOnly);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
saveSessionId(state, sessionId) {
|
saveSessionId(state, sessionId) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue