DenisSlider2000/index.js
2022-04-09 00:32:32 +02:00

39 lines
864 B
JavaScript

const fs = require("fs");
const https = require("https");
const express = require("express");
const socketio = require("socket.io");
const app = express();
const https_options = {
key: fs.readFileSync("./privkey.pem"),
cert: fs.readFileSync("./fullchain.pem"),
requestCert: false,
rejectUnauthorized: false
}
const server = https.createServer(https_options, app);
const io = socketio(server, {
cors: {
origin: "https://danby.aniere.fr",
},
secure: true
});
usersConnected = 0
io.on("connection", (client) => {
usersConnected++;
client.on("disconnect", () => {
usersConnected--;
io.sockets.emit("update-count", {value: usersConnected});
});
io.sockets.emit("update-count", {value: usersConnected});
});
server.listen(3000, () => {
console.log("Server started on port 3000");
});