lightings f155aa73d8 ...
2023-04-19 12:23:04 +08:00

60 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var Code = require("../../../lib/code");
var dispatcher = require("../../../util/dispatcher");
module.exports = function (app) {
return new Handler(app);
};
var Handler = function (app) {
this.app = app;
};
var handler = Handler.prototype;
/** @api {post} gate.gateHandler.queryEntry queryEntry 获取空闲接入服务器
*
* @apiGroup Gate
* @apiDescription 获取空闲接入服务器
* @apiParam {String} uid 用户ID
*
* @apiSuccess {Number} code 状态码
* @apiSuccess {String} host 接入服务器地址
* @apiSuccess {Number} port 接入服务器端口
*
* @apiSuccessExample {json} Success-200:
* {
* "code": 200,
* "host": "192.168.100.83",
* "port": 4010
* }
*
* @apiErrorExample {json} Error-500:
* {
* "code": 500 // 参数失败必须设置uid
* }
*
* @apiErrorExample {json} Error-2001:
* {
* "code": 2001 // 无可用接入服务器
* }
*/
handler.queryEntry = function (msg, session, next) {
var uid = msg.uid;
if (!uid) {
next(null, { code: Code.FAIL });
return;
}
var connectors = this.app.getServersByType("connector");
if (!connectors || connectors.length === 0) {
next(null, { code: Code.GATE.FA_NO_SERVER_AVAILABLE });
return;
}
var res = dispatcher.dispatch(uid, connectors);
let host = res.proxyHost || res.clientHost || res.host;
let port = res.proxyPort || res.clientPort || res.port;
next(null, { code: Code.OK, host: host, port: port });
};