-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
52 lines (45 loc) · 1.43 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const http = require("http");
const express = require("express");
const app = express();
const server = http.createServer(app);
const io = require("socket.io")(server, {
cors: {
origin: "http://localhost:3000",
methods: ["GET", "POST"],
allowedHeaders: ["my-custom-header"],
credentials: true,
},
});
const { addUser, removeUser } = require("./user");
const PORT = 5000;
// io.on("connection", (socket) => {
// socket.on("join", ({ name, room }, callBack) => {
// const { user, error } = addUser({ id: socket.id, name, room });
// if (error) return callBack(error);
// socket.join(user.room);
// socket.emit("message", {
// user: "Admin",
// text: `Welocome to ${user.room}`,
// });
// socket.broadcast
// .to(user.room)
// .emit("message", { user: "Admin", text: `${user.name} has joined!` });
// callBack(null);
// socket.on("sendMessage", ({ message }) => {
// io.to(user.room).emit("message", {
// user: user.name,
// text: message,
// });
// });
// });
// socket.on("disconnect", () => {
// const user = removeUser(socket.id);
// console.log(user);
// io.to(user.room).emit("message", {
// user: "Admin",
// text: `${user.name} just left the room`,
// });
// console.log("A disconnection has been made");
// });
// });
// server.listen(PORT, () => console.log(`Server is Quannected to Port ${PORT}`));