Fix WebSocket protocol handling based on page protocol

This commit is contained in:
2024-09-09 21:50:34 +07:00
parent 77895fe51c
commit ac484ca3da

View File

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