Fix WebSocket protocol handling based on page protocol

This commit is contained in:
2024-09-09 21:46:56 +07:00
parent b23bf8898b
commit 77895fe51c

View File

@ -1,5 +1,6 @@
if (!window.mySocket) { if (!window.mySocket) {
window.mySocket = new WebSocket(`ws://${window.location.host}/user`); const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
window.mySocket = new WebSocket(`${wsProtocol}://${window.location.host}/user`);
window.mySocket.onopen = function(event) { window.mySocket.onopen = function(event) {
console.log('WebSocket is open now.'); console.log('WebSocket is open now.');