koa.io

集成koasocket.io的时事web框架.

本项目还在开发中.

功能

  • socket.io 支持koa式中间件连接和断开连接.
  • socket 事件路由支持.
  • 使 socket.io's 事件处理器支持 generator 函数.
  • 扩展socket.iosocket 对象和koacontext,压缩 koa的中间件.

安装

$ npm install koa.io --save

使用

var koa = require('koa.io');

var app = koa();

// koa中间件
app.use(function*() {
});


// socket.io的连接和断开连接的中间件
app.io.use(function* (next) {
  // 监听连接
  yield* next;
  // 坚定断开连接
});

// socket事件路由
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);

请查看这个简单的 聊天示例.

证书

MIT

results matching ""

    No results matching ""