Created
June 28, 2018 10:55
-
-
Save shrekuu/be702ddbf491e42852c21616171ce4a3 to your computer and use it in GitHub Desktop.
koajs + socket.io server side example
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
| const Koa = require('koa'); | |
| const app = new Koa(); | |
| const server = require('http').createServer(app.callback()); | |
| const io = require('socket.io')(server, {path: '/remote-control-sockjs'}); | |
| const port = process.env.PORT || 8080; | |
| server.listen(port); | |
| io.on('connection', function (socket) { | |
| socket.on('slide-change', function (detail) { | |
| console.log(detail); | |
| io.emit('slide-change', detail); | |
| }); | |
| }); | |
| console.log('koa app running on http://localhost:' + port); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment