-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
56 lines (41 loc) · 1.14 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
53
54
55
const express = require("express")
const app = express()
const http = require('http').createServer(app);
const { Server } = require("socket.io");
const io = new Server(http);
const mongoose = require("mongoose");
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
const connect = require("./schemas");
connect();
let user = []
io.on('connection', function (socket) {
socket.on('potato', function (data) {
console.log(data)
io.emit('tomato', data)
})
});
var chat1 = io.of('/lobby');
chat1.on('connection', function (socket) {
socket.on('user', function (data) {
console.log(data, "fuck here")
})
var roomNo = '';
socket.on('requestJoin', function (data) {
socket.join(data);
roomNo = data;
});
socket.on('who', function (data) {
chat1.to(roomNo).emit('a', data);
});
socket.on('chat', function (data) {
console.log(data);
chat1.to(roomNo).emit('e', data);
});
});
app.get('/chat', function (요청, 응답) {
응답.render('chat.ejs')
});
http.listen(8080, function () {
console.log('listening on 8080')
});