/** * 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 videoHeartBeatUrl = 'http://{address}/STREAM/{playHandle}/BEATS'; 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 fetchHeartBeat(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 fetchHeartBeat(searchParams) { return new Promise((resolve, reject) => { const objSearchParams = searchParams; const apiPath = videoHeartBeatUrl.replace('{address}', objSearchParams.address) .replace('{playHandle}', objSearchParams.playHandle); request .get(apiPath) .set('Content-Type', 'application/json') .set('async', false) .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('/_heart/beat', co.wrap(Exporting)); };