实时Web框架:koa.io

jopen 10年前

联合koasocket.io的实时Web框架。

特性

  • socket.io 支持 koa 风格的中间件当socket连接和断开时
  • socket事件路由支持
  • Make socket.io's event handler support generator function.
  • Extent socket.io's socket object like koa's context, to compact with some koa'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);

项目主页:http://www.open-open.com/lib/view/home/1414419681481