From 28e1cca60c571e769a4c7137afc0fa78126c8983 Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Tue, 14 May 2024 05:02:05 +0200 Subject: [PATCH] update socket --- painter-js/src/main.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/painter-js/src/main.js b/painter-js/src/main.js index a303ce5..8d5131c 100644 --- a/painter-js/src/main.js +++ b/painter-js/src/main.js @@ -1,5 +1,9 @@ import io from 'socket.io-client'; +// Determine the WebSocket protocol based on the page protocol +const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; +// Use the same host as the page +const wsHost = window.location.host; const canvas = document.getElementById('canvas'); const ctx = canvas.getContext('2d'); const colorPicker = document.getElementById('color-picker'); @@ -9,7 +13,9 @@ const pixelCooldown = 60 * 1000; // 1 minute let lastPixelTime = parseInt(localStorage.getItem('lastPixelTime') || '0'); -const socket = io('ws://localhost:3000'); +const socket = io(`${wsProtocol}//${wsHost}`, { + transports: ['websocket'], +}); socket.on('connect', () => { console.log('connect');