实时Web框架:koa.io
jopen
10年前
特性
socket.io
支持 koa 风格的中间件当socket连接和断开时- socket事件路由支持
- Make
socket.io
's event handler support generator function. - Extent
socket.io
'ssocket
object likekoa
'scontext
, to compact with somekoa
's middlewares.
用法
var koa = require('koa.io'); var app = koa(); // middleware for koa app.use(function*() { }); // middleware for scoket.io's connect and disconnect app.io.use(function* (next) { // on connect yield* next; // on disconnect }); // router for socket event app.io.route('new message', function* () { // we tell the client to execute 'new message' var message = this.args[0]; this.broadcast.emit('new message', message); }); app.listen(3000);