简单,易用,可组合的中间件,用于Koa中的Websocket处理
用法
const Koa = require ( 'koa' )
const websocket = require ( 'koa-easy-ws' )
const app = new Koa ( )
app . use ( websocket ( ) )
app . use ( async ( ctx , next ) => {
// check if the current request is websocket
if ( ctx . ws ) {
const ws = await ctx . ws ( ) // retrieve socket
// now you have a ws instance, you can use it as you see fit
return ws .