/** * Created by wuqun * on 2017/9/27. */ 'use strict'; const co = require('co'); const proxy = require('koa-proxy'); const convert = require('koa-convert'); const request = require('superagent'); const realTimeVideoUrl = 'http://{address}/BACK_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 fetchVideoPlayback(searchParams); ctx.status = 200; ctx.body = data; } catch (err) { app.fs.logger.log('error', 'get video playback error:', err); ctx.status = 400; ctx.body = err; } } function fetchVideoPlayback(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') .end(function (err, res) { if (err) { app.fs.logger.log('error', '[video playback post error]', err); reject(err); } else { app.fs.logger.log('debug', '[video playback post res.body]', res.body); resolve(res.body); } }); }); } router.post('/_video/playback', co.wrap(Exporting)); };