Skip to content

Commit

Permalink
Enforce Websocket (louislam#181)
Browse files Browse the repository at this point in the history
* Always show Down button

* Force WebSocket

* Force WebSocket
  • Loading branch information
louislam authored Nov 25, 2023
1 parent 457f038 commit d23e2d8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions backend/dockge-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export class DockgeServer {
// Create Socket.io
this.io = new socketIO.Server(this.httpServer, {
cors,
transports: [ "websocket" ],
});

this.io.on("connection", async (socket: Socket) => {
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,10 @@
"Allowed commands:": "Allowed commands:",
"Internal Networks": "Internal Networks",
"External Networks": "External Networks",
"No External Networks": "No External Networks"
"No External Networks": "No External Networks",
"reverseProxyMsg1": "Using a Reverse Proxy?",
"reverseProxyMsg2": "Check how to config it for WebSocket",
"Cannot connect to the socket server.": "Cannot connect to the socket server.",
"reconnecting...": "Reconnecting...",
"connecting...": "Connecting to the socket server..."
}
7 changes: 7 additions & 0 deletions frontend/src/layouts/Layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<div v-if="! $root.socketIO.connected && ! $root.socketIO.firstConnect" class="lost-connection">
<div class="container-fluid">
{{ $root.socketIO.connectionErrorMsg }}
<div v-if="$root.socketIO.showReverseProxyGuide">
{{ $t("reverseProxyMsg1") }} <a href="https://github.com/louislam/uptime-kuma/wiki/Reverse-Proxy" target="_blank">{{ $t("reverseProxyMsg2") }}</a>
</div>
</div>
</div>

Expand Down Expand Up @@ -82,6 +85,10 @@
</header>

<main>
<div v-if="$root.socketIO.connecting" class="container mt-5">
<h4>{{ $t("connecting...") }}</h4>
</div>

<router-view v-if="$root.loggedIn" />
<Login v-if="! $root.loggedIn && $root.allowLoginDialog" />
</main>
Expand Down
13 changes: 11 additions & 2 deletions frontend/src/mixins/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default defineComponent({
initedSocketIO: false,
connectionErrorMsg: `${this.$t("Cannot connect to the socket server.")} ${this.$t("Reconnecting...")}`,
showReverseProxyGuide: true,
connecting: false,
},
info: {

Expand Down Expand Up @@ -103,13 +104,20 @@ export default defineComponent({
url = location.protocol + "//" + location.host;
}

let connectingMsgTimeout = setTimeout(() => {
this.socketIO.connecting = true;
}, 1500);

socket = io(url, {
transports: [ "websocket", "polling" ]
transports: [ "websocket" ]
});

socket.on("connect", () => {
console.log("Connected to the socket server");

clearTimeout(connectingMsgTimeout);
this.socketIO.connecting = false;

this.socketIO.connectCount++;
this.socketIO.connected = true;
this.socketIO.showReverseProxyGuide = false;
Expand Down Expand Up @@ -143,10 +151,11 @@ export default defineComponent({

socket.on("connect_error", (err) => {
console.error(`Failed to connect to the backend. Socket.io connect_error: ${err.message}`);
this.socketIO.connectionErrorMsg = `${this.$t("Cannot connect to the socket server.")} [${err}] ${this.$t("Reconnecting...")}`;
this.socketIO.connectionErrorMsg = `${this.$t("Cannot connect to the socket server.")} [${err}] ${this.$t("reconnecting...")}`;
this.socketIO.showReverseProxyGuide = true;
this.socketIO.connected = false;
this.socketIO.firstConnect = false;
this.socketIO.connecting = false;
});

// Custom Events
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Compose.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{{ $t("stopStack") }}
</button>

<BDropdown v-if="!isEditMode && active" right text="" variant="normal">
<BDropdown right text="" variant="normal">
<BDropdownItem @click="downStack">
<font-awesome-icon icon="stop" class="me-1" />
{{ $t("downStack") }}
Expand Down

0 comments on commit d23e2d8

Please sign in to comment.