-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
68 lines (58 loc) · 1.71 KB
/
app.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const express = require('express')
const app = express()
const http = require('http')
const server = http.createServer(app)
const socketIO = require("socket.io")
const io = socketIO(server)
app.set('view engine', 'ejs')
app.get("/", (req, res) => {
res.render("index")
})
// point no 1
// io.on("connection", (socket) => {
// console.log(`${socket.id} connected`)
// socket.on("disconnect", () => { // jab connected socket disconnect ho to ye callback chalega
// console.log(`${socket.id} disconnected`)
// })
// })
// point no 2
// io.on("connection", (socket) => {
// socket.on("abcd", () => {
// console.log(`event received`)
// })
// })
// point no 3
// io.on("connection", (socket) => {
// socket.on("abcd", (data) => {
// console.log(data)
// })
// })
// point no 4
// io.on("connection", (socket) => {
// socket.on("abcd", () => {
// io.emit("defg", "data from backend") // saare users ko data bej rahe hai
// socket.emit("defg", "ye sirf mere liye")
// })
// })
// point no 5
// io.on("connection", (socket) => {
// console.log(`${socket.id} connected`)
// socket.on("typing", () => {
// socket.broadcast.emit("typing", `${socket.id} is typing`) // ye message mje cgodkr baki sb logu ko jayega
// })
// })
// point no 6
// io.on("connection", (socket) => {
// console.log(`${socket.id} connected`)
// socket.on("disconnect", () => {
// console.log(`${socket.id} disconnected`)
// })
// })
// point no 7
io.on("connection", (socket) => {
console.log(`${socket.id} is connected`)
socket.on("typing", (data) => {
socket.broadcast.emit("typing", data)
})
})
server.listen(3000)