This commit is contained in:
leca 2023-08-05 13:03:33 +03:00
parent 4891f0c083
commit 8e041a0992
3 changed files with 15 additions and 5 deletions

View File

@ -30,7 +30,7 @@ function connect() {
serverAddress = document.getElementById("server-address").value;
serverPort = document.getElementById("server-port").value
console.log(`Connecting ${serverAddress}:${serverPort}`)
socket = new WebSocket(`ws://${serverAddress}:${serverPort}`)
socket = new WebSocket(`wss://${serverAddress}:${serverPort}`)
timer.textContent="Board is loading, please wait";
socket.addEventListener("open", (event) => {
socket.send(JSON.stringify({code:0}));
@ -69,6 +69,9 @@ function connect() {
drawPixel(contentJson.x * 4, contentJson.y * 4, color)
redraw();
break;
case undefined:
console.log("ping!");
break
}
});
});

View File

@ -1,5 +1,6 @@
{
"httpPort": 8080,
"listenPort": 8080,
"exposedPort": 443,
"boardWidth": 1920,
"boardHeight": 1080,
"serverAddress": "localhost",

View File

@ -11,7 +11,8 @@ app.use(express.static(path.join(__dirname, '../html')));
app.set('view engine', 'pug');
const config = require("../settings.json");
const httpPort = config.httpPort;
const httpPort = config.listenPort;
const exposedPort = config.exposedPort;
const serverAddress = config.serverAddress;
const saveFile = config.saveFile;
const boardWidth = config.boardWidth;
@ -122,11 +123,16 @@ server.on('connection', (client) => {
});
const pingClient = () => {
clients.forEach(client => {
client.send(JSON.stringify({}));
});
};
setInterval(pingClient, 15000)
app.get('/', (req, res) => {
res.render('index.pug', { root: __dirname, server: serverAddress, port: httpPort });
res.render('index.pug', { root: __dirname, server: serverAddress, port: exposedPort });
})
app.use(function (err, req, res, next) {
if (err) console.log(err);