Skip to content
关注公众号,获取新课通知

封装全局是否在线中间件


js
// app/online.js
module.exports = (options, app) => {
  return async (ctx, next) => {
    let current_user_id = ctx.authUser.id;
    console.log(app.ws);
    if (!app.ws.user || !app.ws.user[current_user_id]) {
      return ctx.throw(400, "当前处于离线状态");
    }
    // 6. 继续执行
    await next(options);
  };
};