Compare commits
2 Commits
204616a2d8
...
55e3f5a3c4
| Author | SHA1 | Date | |
|---|---|---|---|
| 55e3f5a3c4 | |||
| 496bc61c7d |
@ -44,7 +44,6 @@
|
||||
<!-- seo + other things -->
|
||||
<title>{{ name }}'s Profile | Selenite</title>
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3415518411898563" crossorigin="anonymous"></script>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", ()=>{
|
||||
let music = {{ is_music }};
|
||||
|
||||
@ -44,7 +44,6 @@
|
||||
<!-- seo + other things -->
|
||||
<title>{{ name }}'s Profile | Selenite</title>
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3415518411898563" crossorigin="anonymous"></script>
|
||||
<!-- <script>
|
||||
let audioObject;
|
||||
document.addEventListener("DOMContentLoaded", ()=>{
|
||||
|
||||
@ -123,7 +123,7 @@
|
||||
});
|
||||
</script>
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3415518411898563" crossorigin="anonymous"></script>
|
||||
|
||||
</head>
|
||||
<alerts> </alerts>
|
||||
<body>
|
||||
|
||||
25
index.js
25
index.js
@ -45,10 +45,20 @@ import WebSocket, { WebSocketServer } from "ws";
|
||||
const wss = new WebSocketServer({ noServer: true });
|
||||
// let openSockets = 0;
|
||||
wss.on("connection", function connection(ws, req, res) {
|
||||
ws.send(`online=${wss.clients.size}`);
|
||||
setInterval(() => {
|
||||
ws.send(`online=${wss.clients.size}`);
|
||||
}, 10000);
|
||||
// ws.send(`online=${wss.clients.size}`);
|
||||
// setInterval(() => {
|
||||
// ws.send(`online=${wss.clients.size}`);
|
||||
// }, 10000);
|
||||
let server = new WebSocket("ws://localhost:7910");
|
||||
|
||||
server.on("message", async function message(data) {
|
||||
let message = Buffer.from(data).toString();
|
||||
if(message.startsWith("online")) {
|
||||
ws.send(message);
|
||||
} else if(message.startsWith("annc")) {
|
||||
ws.send(message);
|
||||
}
|
||||
})
|
||||
|
||||
ws.on("error", console.error);
|
||||
|
||||
@ -67,9 +77,10 @@ wss.on("connection", function connection(ws, req, res) {
|
||||
} else if (message.startsWith("annc")) {
|
||||
let splitMessage = message.split(";;");
|
||||
if(await isAdmin(splitMessage[1])) {
|
||||
wss.clients.forEach(client => {
|
||||
client.send(`annc;;${splitMessage[2]};;${splitMessage[3]}`);
|
||||
})
|
||||
// wss.clients.forEach(client => {
|
||||
// client.send(`annc;;${splitMessage[2]};;${splitMessage[3]}`);
|
||||
// })
|
||||
server.send(message);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
"description": "",
|
||||
"exports": "./index.js",
|
||||
"scripts": {
|
||||
"websocket_server": "bun --watch websocket.js",
|
||||
"start": "bun --watch index.js",
|
||||
"svg": "node svg-converter.js"
|
||||
},
|
||||
|
||||
33
websocket.js
Normal file
33
websocket.js
Normal file
@ -0,0 +1,33 @@
|
||||
import WebSocket, { WebSocketServer } from "ws";
|
||||
const wss = new WebSocketServer({ noServer: true });
|
||||
|
||||
wss.on("connection", function connection(ws, req, res) {
|
||||
ws.send(`online=${wss.clients.size}`);
|
||||
setInterval(() => {
|
||||
ws.send(`online=${wss.clients.size}`);
|
||||
}, 10000);
|
||||
|
||||
ws.on("message", async function message(data, isBinary) {
|
||||
let message = Buffer.from(data).toString();
|
||||
if (message.startsWith("annc")) {
|
||||
let splitMessage = message.split(";;");
|
||||
wss.clients.forEach(client => {
|
||||
client.send(`annc;;${splitMessage[2]};;${splitMessage[3]}`);
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
ws.on("close", () => {});
|
||||
});
|
||||
let port = 7910;
|
||||
import express from "express";
|
||||
const app = express();
|
||||
const server = app.listen(port, () => {
|
||||
console.log("Websocket server is online.");
|
||||
console.log("- http://localhost:" + port);
|
||||
});
|
||||
server.on("upgrade", (request, socket, head) => {
|
||||
wss.handleUpgrade(request, socket, head, (socket) => {
|
||||
wss.emit("connection", socket, request);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user