Browse Source

mqtt 引入 40%

release_0.0.2
yuan_yi 3 years ago
parent
commit
12815a3cee
  1. 3
      code/VideoAccess-VCMP/api/.vscode/launch.json
  2. 2
      code/VideoAccess-VCMP/api/app/lib/index.js
  3. 22
      code/VideoAccess-VCMP/api/app/lib/service/mqttVideoServer.js
  4. 36
      code/VideoAccess-VCMP/api/app/lib/service/redis.js
  5. 60
      code/VideoAccess-VCMP/api/config.js
  6. 1
      code/VideoAccess-VCMP/api/package.json
  7. 2
      code/VideoAccess-VCMP/web/client/src/layout/index.jsx

3
code/VideoAccess-VCMP/api/.vscode/launch.json

@ -22,7 +22,8 @@
"--iotAuthApi http://127.0.0.1:4200", "--iotAuthApi http://127.0.0.1:4200",
"--iotVideoServerUrl http://221.230.55.27:8081", "--iotVideoServerUrl http://221.230.55.27:8081",
"--godUrl https://restapi.amap.com/v3", "--godUrl https://restapi.amap.com/v3",
"--godKey 21c2d970e1646bb9a795900dd00093ce" "--godKey 21c2d970e1646bb9a795900dd00093ce",
"--mqttVideoServer mqtt://127.0.0.1"
] ]
}, },
{ {

2
code/VideoAccess-VCMP/api/app/lib/index.js

@ -4,6 +4,7 @@ const utils = require('./utils')
const routes = require('./routes'); const routes = require('./routes');
const redisConnect = require('./service/redis') const redisConnect = require('./service/redis')
const socketConect = require('./service/socket') const socketConect = require('./service/socket')
const mqttVideoServer = require('./service/mqttVideoServer')
const paasRequest = require('./service/paasRequest'); const paasRequest = require('./service/paasRequest');
const authenticator = require('./middlewares/authenticator'); const authenticator = require('./middlewares/authenticator');
// const apiLog = require('./middlewares/api-log'); // const apiLog = require('./middlewares/api-log');
@ -19,6 +20,7 @@ module.exports.entry = function (app, router, opts) {
// 顺序固定 ↓ // 顺序固定 ↓
redisConnect(app, opts) redisConnect(app, opts)
socketConect(app, opts) socketConect(app, opts)
mqttVideoServer(app, opts)
// 实例其他平台请求方法 // 实例其他平台请求方法
paasRequest(app, opts) paasRequest(app, opts)

22
code/VideoAccess-VCMP/api/app/lib/service/mqttVideoServer.js

@ -0,0 +1,22 @@
'use strict';
const mqtt = require('mqtt');
module.exports = async function factory (app, opts) {
// const client = mqtt.connect(opts.mqtt.mqttVideoServer);
// client.on('connect', function () {
// console.info(`mqtt connect success ${opts.mqtt.mqttVideoServer}`);
// })
// client.on('error', function (e) {
// console.error(`mqtt connect failed ${opts.mqtt.mqttVideoServer}`);
// app.fs.logger.error('info', '[FS-AUTH-MQTT]', `mqtt connect failed ${opts.mqtt.mqttVideoServer}`);
// })
// client.subscribe('test', { qos: 2 });//订阅主题为test的消息
// client.on('message', function (top, message) {
// console.log(message.toString());
// });
// app.mqttVideoServer = client
}

36
code/VideoAccess-VCMP/api/app/lib/service/redis.js

@ -3,26 +3,26 @@
const redis = require("ioredis") const redis = require("ioredis")
module.exports = async function factory (app, opts) { module.exports = async function factory (app, opts) {
let client = new redis(opts.redis.port, opts.redis.host); let client = new redis(opts.redis.port, opts.redis.host);
client.on("error", function (err) { client.on("error", function (err) {
app.fs.logger.error('info', '[FS-AUTH-REDIS]', 'redis connect error.'); app.fs.logger.error('info', '[FS-AUTH-REDIS]', `redis connect error. ${opts.redis.host + ':' + opts.redis.port}` );
console.error("Error :", err); // console.error("Error :", err);
process.exit(-1); // process.exit(-1);
}); });
client.on('connect', function () { client.on('connect', function () {
console.log(`redis connect success ${opts.redis.host + ':' + opts.redis.port}`); console.info(`redis connect success ${opts.redis.host + ':' + opts.redis.port}`);
}) })
// 自定义方法 // 自定义方法
async function hdelall (key) { async function hdelall (key) {
const obj = await client.hgetall(key); const obj = await client.hgetall(key);
await client.hdel(key, Object.keys(obj)) await client.hdel(key, Object.keys(obj))
} }
app.redis = client app.redis = client
app.redisTools = { app.redisTools = {
hdelall, hdelall,
} }
} }

60
code/VideoAccess-VCMP/api/config.js

@ -19,6 +19,7 @@ args.option('iotAuthApi', 'IOT 鉴权 api');
args.option('iotVideoServerUrl', '视频后端服务地址'); args.option('iotVideoServerUrl', '视频后端服务地址');
args.option('godUrl', '高德地图API请求地址'); args.option('godUrl', '高德地图API请求地址');
args.option('godKey', '高德地图API key'); args.option('godKey', '高德地图API key');
args.option('mqttVideoServer', '视频后台 mqtt 服务 URL');
const flags = args.parse(process.argv); const flags = args.parse(process.argv);
@ -29,6 +30,8 @@ const IOTA_REDIS_SERVER_HOST = process.env.IOTA_REDIS_SERVER_HOST || flags.redis
const IOTA_REDIS_SERVER_PORT = process.env.IOTA_REDIS_SERVER_PORT || flags.redisPort || "6379";//redis 端口 const IOTA_REDIS_SERVER_PORT = process.env.IOTA_REDIS_SERVER_PORT || flags.redisPort || "6379";//redis 端口
const IOTA_REDIS_SERVER_PWD = process.env.IOTA_REDIS_SERVER_PWD || flags.redisPswd || "";//redis 密码 const IOTA_REDIS_SERVER_PWD = process.env.IOTA_REDIS_SERVER_PWD || flags.redisPswd || "";//redis 密码
const MQTT_VIDEO_SERVER = process.env.MQTT_VIDEO_SERVER || flags.mqttVideoServer;
const IOT_AUTH_API = process.env.IOT_AUTH_API || flags.iotAuthApi; const IOT_AUTH_API = process.env.IOT_AUTH_API || flags.iotAuthApi;
const IOT_VIDEO_SERVER_URL = process.env.IOT_VIDEO_SERVER_URL || flags.iotVideoServerUrl const IOT_VIDEO_SERVER_URL = process.env.IOT_VIDEO_SERVER_URL || flags.iotVideoServerUrl
const AXY_API_URL = process.env.AXY_API_URL || flags.axyApiUrl; const AXY_API_URL = process.env.AXY_API_URL || flags.axyApiUrl;
@ -36,7 +39,7 @@ const GOD_URL = process.env.GOD_URL || flags.godUrl || 'https://restapi.amap.com
const GOD_KEY = process.env.GOD_KEY || flags.godKey; const GOD_KEY = process.env.GOD_KEY || flags.godKey;
const YINGSHI_URL = process.env.YINGSHI_URL || flags.yingshiUrl || 'https://open.ys7.com/api'; const YINGSHI_URL = process.env.YINGSHI_URL || flags.yingshiUrl || 'https://open.ys7.com/api';
if (!IOT_VIDEO_ACCESS_DB || !IOTA_REDIS_SERVER_HOST || !IOTA_REDIS_SERVER_PORT || !GOD_KEY) { if (!IOT_VIDEO_ACCESS_DB || !IOTA_REDIS_SERVER_HOST || !IOTA_REDIS_SERVER_PORT || !GOD_KEY || !MQTT_VIDEO_SERVER) {
console.log('缺少启动参数,异常退出'); console.log('缺少启动参数,异常退出');
args.showHelp(); args.showHelp();
process.exit(-1); process.exit(-1);
@ -65,33 +68,38 @@ const product = {
port: IOTA_REDIS_SERVER_PORT, port: IOTA_REDIS_SERVER_PORT,
pwd: IOTA_REDIS_SERVER_PWD pwd: IOTA_REDIS_SERVER_PWD
}, },
pssaRequest: [{// name 会作为一个 request 出现在 ctx.app.fs mqtt: {
name: 'authRequest', mqttVideoServer: MQTT_VIDEO_SERVER,
root: IOT_AUTH_API },
}, { pssaRequest: [
name: 'axyRequest', {// name 会作为一个 request 出现在 ctx.app.fs
root: AXY_API_URL name: 'authRequest',
}, { root: IOT_AUTH_API
name: 'godRequest', }, {
root: GOD_URL, name: 'axyRequest',
params: { root: AXY_API_URL
query: { }, {
key: GOD_KEY name: 'godRequest',
root: GOD_URL,
params: {
query: {
key: GOD_KEY
}
} }
} }, {
}, { name: 'yingshiRequest',
name: 'yingshiRequest', root: YINGSHI_URL,
root: YINGSHI_URL, params: {
params: { query: {
query: { key: GOD_KEY
key: GOD_KEY }
} }
} }, {
}, { name: 'videoServerRequest',
name: 'videoServerRequest', root: IOT_VIDEO_SERVER_URL + '/api',
root: IOT_VIDEO_SERVER_URL + '/api', dataWord: 'text'
dataWord: 'text' },
},] ]
} }
} }
], ],

1
code/VideoAccess-VCMP/api/package.json

@ -23,6 +23,7 @@
"koa-convert": "^1.2.0", "koa-convert": "^1.2.0",
"koa-proxy": "^0.9.0", "koa-proxy": "^0.9.0",
"moment": "^2.24.0", "moment": "^2.24.0",
"mqtt": "^4.3.7",
"path": "^0.12.7", "path": "^0.12.7",
"path-to-regexp": "^3.0.0", "path-to-regexp": "^3.0.0",
"pg": "^7.9.0", "pg": "^7.9.0",

2
code/VideoAccess-VCMP/web/client/src/layout/index.jsx

@ -162,7 +162,7 @@ const Root = props => {
setAuthCrossLoading(false) setAuthCrossLoading(false)
}); });
setAuthCrossLoading(false) // setAuthCrossLoading(false)
}, []) }, [])
return ( return (

Loading…
Cancel
Save