Fix WebSocket, add auto refresh on frontend update
This commit is contained in:
20
ejs/footer.ejs
Normal file
20
ejs/footer.ejs
Normal file
@@ -0,0 +1,20 @@
|
||||
<script>
|
||||
let ws;
|
||||
|
||||
function connectWebSocket() {
|
||||
const ws = new WebSocket((window.location.protocol === 'https:' ? 'wss://' : 'ws://') + window.location.host + window.location.pathname);
|
||||
|
||||
|
||||
ws.onmessage = async (event) => {
|
||||
if (event.data === 'update') {
|
||||
location.reload();
|
||||
}
|
||||
};
|
||||
|
||||
ws.onclose = () => {
|
||||
setTimeout(connectWebSocket, 5000);
|
||||
};
|
||||
}
|
||||
|
||||
connectWebSocket();
|
||||
</script>
|
||||
@@ -53,4 +53,5 @@
|
||||
<a href="/lobbies">Search Lobbies</a>
|
||||
</div>
|
||||
</body>
|
||||
<%- include('footer') %>
|
||||
</html>
|
||||
Reference in New Issue
Block a user