websockets.js 443 B

1234567891011121314151617181920
  1. import randomUUID from "node:crypto";
  2. const games = [];
  3. let p = "12345";
  4. let create = (data)=>{
  5. if(data.p !== p) return "nope";
  6. return "yep";
  7. }
  8. export default (wss)=>{
  9. wss.on("connection", (ws, req)=>{
  10. ws.on("message", (body)=>{
  11. const data = JSON.parse(body.toString("utf8"));
  12. switch(data.message){
  13. case "create": ws.send(create(data)); break;
  14. }
  15. });
  16. });
  17. }