Mid-Simulator/multiplayer.js

30 lines
472 B
JavaScript
Raw Normal View History

2022-04-18 01:14:39 +00:00
const ws = require("ws");
module.exports = (server) => {
const socket = new ws.Server({ server: server, path: "/multiplayer" });
socket.on("connection", (conn) => {
function broadcast(data) {
socket.clients.forEach((client) => {
if (client !== conn && client.readyState === ws.OPEN) {
client.send(data);
}
});
}
conn.on("message", (data) => {
// ...
});
conn.on("close", (data) => {
// ...
});
conn.send("oh hi");
});
};