UNPKG

mm_os

Version:

这是超级美眉服务端框架,用于快速构建应用程序。

62 lines (57 loc) 1.4 kB
const Index = require('mm_machine').Index; const Drive = require('./drive'); /** * 任务类 * @extends {Index} * @class */ class Socket extends Index { /** * 构造函数 * @param {Object} scope 作用域 * @param {String} title 标题 * @constructor */ constructor(scope, title) { super(scope, __dirname); this.Drive = Drive; this.type = "socket"; this.dict = {}; this.title = title; } } /** * 处理socket请求 * @param {Object} ctx 请求上下文 * @param {Function} next 跳过当前, 然后继续执行函数 */ Socket.prototype.run = async function(ctx, next) { await next(); var list = this.list; const path = ctx.path.toLocaleLowerCase(); for (var i = 0, o; o = list[i++];) { // console.log("监听webscoket路径是否正确", path === o.config.path); if (path === o.config.path) { o.add(ctx); break; } } }; /** * 加载插件 * @param {String} path 检索路径 * @param {Boolean} isApp 是否APP */ Socket.prototype.update_config_all = async function(path) { if (!path) { path = "./app/"; } // 获取所有应用路径 var list_scope = $.dir.getAll(path, "socket"); // 遍历目录路径 for (var i = 0, f; f = list_scope[i++];) { var list_file = $.file.getAll(f, "*" + _this.type + ".json"); await this.load_list(list_file); } } module.exports = Socket;