运维服务中台
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.
 
 
 
 
 

48 lines
1.8 KiB

/**
* Created by suntao
* on 2017/10/13.
*/
'use strict';
const co = require('co');
const proxy = require('koa-proxy');
const convert = require('koa-convert');
const request = require('superagent');
const CurrentTimeVideoUrl = 'http://{address}/STREAM/{playHandle}/POSITION';
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 fetchCurrentVideoPlayback(searchParams);
ctx.status = 200;
ctx.body = data;
} catch (err) {
app.fs.logger.log('error', 'get video current time playback error:', err);
ctx.status = 400;
ctx.body = err;
}
}
function fetchCurrentVideoPlayback(searchParams) {
return new Promise((resolve, reject) => {
const objSearchParams = searchParams;
const apiPath = CurrentTimeVideoUrl.replace('{address}', objSearchParams.pushServerAddress)
.replace('{playHandle}', objSearchParams.playHandle);
request
.post(apiPath)
.send(objSearchParams)
.set('Content-Type', 'application/json')
.end(function (err, res) {
if (err) {
app.fs.logger.log('error', '[video current time playback post error]', err);
reject(err);
} else {
app.fs.logger.log('debug', '[video current time playback post res.body]', res.body);
resolve(res.body);
}
});
});
}
router.post('/_video/currentPlayback', co.wrap(Exporting));
};