Last active
May 9, 2020 17:04
-
-
Save tranphuquy19/f3d2aab52749d1394eee9be5d3a42854 to your computer and use it in GitHub Desktop.
Hướng dẫn sử dụng Socket.io với Express-generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var createError = require('http-errors'); | |
var express = require('express'); | |
var path = require('path'); | |
var cookieParser = require('cookie-parser'); | |
var logger = require('morgan'); | |
var indexRouter = require('./routes/index'); | |
var usersRouter = require('./routes/users'); | |
var apiRouter = require('./routes/api'); | |
var app = express(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var router = express.Router(); | |
module.exports = (io) => { | |
io.on('connection', socket => { | |
let { id } = socket; | |
console.log('new connection id:', id); | |
socket.on('disconnect', socket => { | |
console.log('disconnection id:', id); | |
}); | |
}); | |
return router; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment