You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.7 KiB
49 lines
1.7 KiB
/**
|
|
* Created by wuqun
|
|
* on 2017/9/19.
|
|
*/
|
|
'use strict';
|
|
const co = require('co');
|
|
const proxy = require('koa-proxy');
|
|
const convert = require('koa-convert');
|
|
const request = require('superagent');
|
|
const realTimeVideoUrl = 'http://{address}/REAL_STREAM';
|
|
exports.entry = function (app, router, opts) {
|
|
function* Exporting(ctx) {
|
|
try {
|
|
const searchParams = ctx.request.body; //字符串
|
|
app.fs.logger.log('info', 'params:', searchParams);
|
|
const data = yield fetchVideo(searchParams);
|
|
ctx.status = 200;
|
|
ctx.body = data;
|
|
|
|
} catch (err) {
|
|
app.fs.logger.log('error', 'get reltime video error:', err);
|
|
ctx.status = 400;
|
|
ctx.body = err;
|
|
}
|
|
}
|
|
|
|
function fetchVideo(searchParams) {
|
|
return new Promise((resolve, reject) => {
|
|
const objSearchParams = searchParams;
|
|
const apiPath = realTimeVideoUrl.replace('{address}', objSearchParams.pushServerAddress);
|
|
|
|
request
|
|
.post(apiPath)
|
|
.send(objSearchParams)
|
|
.set('Content-Type', 'application/json')
|
|
//.set('Content-Length', searchParams.length)
|
|
.end(function (err, res) {
|
|
if (err) {
|
|
app.fs.logger.log('error', '[Realtime video post error]', err);
|
|
reject(err);
|
|
} else {
|
|
app.fs.logger.log('debug', '[Realtime video post res.body]', res.body);
|
|
resolve(res.body);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
router.post('/_realtime/video', co.wrap(Exporting));
|
|
};
|