Authored by 郝肖肖

'live-ctx'

/* eslint no-unused-vars: ["error", {"args": "none"}] */
'use strict';
const model = require('../models/live');
const liveModel = require('../models/live');
exports.index = (req, res, next) => {
liveModel.getAllList().then(result => {
req.ctx(liveModel).getAllList().then(result => {
res.render('live/entry', {
title: '直播列表',
module: 'activity',
... ... @@ -30,7 +29,7 @@ exports.main = (req, res, next) => {
res.locals.page = 'live-play';
res.locals.enableFoot = Number(req.query.no) !== 1;
model.fetchInfo(id, isReplay)
req.ctx(liveModel).fetchInfo(id, isReplay)
.then(result => {
if (!result.data) {
return next();
... ... @@ -44,7 +43,7 @@ exports.main = (req, res, next) => {
exports.barrage = (req, res, next) => {
const type = req.query.type;
model.getBarrageHost(type)
req.ctx(liveModel).getBarrageHost(type)
.then(result => {
if (result.code !== 200) {
next(result.message);
... ... @@ -61,7 +60,7 @@ exports.replayBarrage = (req, res, next) => {
const startTime = req.query.startTime;
const timeInterval = req.query.timeInterval;
model.getReplyBarrage(id, startTime, timeInterval)
req.ctx(liveModel).getReplyBarrage(id, startTime, timeInterval)
.then(result => {
res.json(result);
})
... ...
'use strict';
const moment = require('moment');
const service = global.yoho.ServiceAPI;
const serviceAPI = global.yoho.ServiceAPI;
const liveAPI = global.yoho.LiveAPI;
const contentCodeConfig = require('../../../config/content-code');
const resourcesProcess = require(`${global.utils}/resources-process`);
... ... @@ -47,21 +47,31 @@ const _getHumanDuration = (duration) => {
return `${duration[0]}:${duration[1]}:${duration[2]}`;
};
// 获取顶部bannel
let _getBannerData = () => {
return service.get('operations/api/v5/resource/get', {
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
// 获取顶部bannel
_getBannerData() {
return this.get({
api: serviceAPI,
url: 'operations/api/v5/resource/get',
data: {
content_code: contentCodeConfig.live.index,
platform: 'iphone'
}, {
},
param: {
code: 200,
cache: true
}
}).then((result) => {
return result && result.data ? resourcesProcess(result.data) : [];
});
};
}
// 获取精选视频
const _getBestList = () => {
// 获取精选视频
_getBestList() {
return liveAPI.get('v1/living/best', {}, {
code: 200,
cache: false
... ... @@ -93,20 +103,20 @@ const _getBestList = () => {
return result && result.data || [];
});
};
}
// 获取直播中所有视频
const _getLivingList = () => {
// 获取直播中所有视频
_getLivingList() {
return liveAPI.get('v1/living/listing', {}, {
code: 200,
cache: false
}).then(result => {
return result && result.data || [];
});
};
}
// 获取直播预告列表
const _getPrelivingList = () => {
// 获取直播预告列表
_getPrelivingList() {
return liveAPI.get('v1/living/starting', {}, {
code: 200,
cache: false
... ... @@ -118,25 +128,31 @@ const _getPrelivingList = () => {
}
return result && result.data || [];
});
};
}
// 获取回看列表
const _getRecordList = () => {
// 获取回看列表
_getRecordList() {
return liveAPI.get('v1/living/replaying', {}, {
code: 200,
cache: false
}).then(result => {
return result && result.data || [];
});
};
}
// 返回所有数据
const getAllList = () => {
return Promise.all([_getBestList(), _getLivingList(), _getPrelivingList(), _getRecordList(), _getBannerData()]);
};
// 返回所有数据
getAllList() {
return Promise.all([
this._getBestList(),
this._getLivingList(),
this._getPrelivingList(),
this._getRecordList(),
this._getBannerData()
]);
}
// 获取 回放视屏 信息
const fetchReplayInfo = (videoID) => {
// 获取 回放视屏 信息
fetchReplayInfo(videoID) {
let url = 'v1/living/detail';
let data = { video_id: videoID };
let options = { cache: true };
... ... @@ -162,15 +178,14 @@ const fetchReplayInfo = (videoID) => {
return result || {};
});
};
}
// 获取 直播视屏 信息
const fetchLiveInfo = (roomID) => {
// 获取 直播视屏 信息
fetchLiveInfo(roomID) {
let url = 'v1/living/detail';
let data = { room_id: roomID };
return liveAPI.get(url, data)
.then(result => {
return liveAPI.get(url, data).then(result => {
if (result && result.data) {
let d = result.data;
... ... @@ -189,22 +204,22 @@ const fetchLiveInfo = (roomID) => {
return result || {};
});
};
}
const fetchInfo = (id, isReplay) => {
fetchInfo(id, isReplay) {
if (isReplay) {
return fetchReplayInfo(id);
return this.fetchReplayInfo(id);
} else {
return fetchLiveInfo(id);
return this.fetchLiveInfo(id);
}
}
};
// 获取 直播 弹幕 host
const getBarrageHost = (type) => {
// 获取 直播 弹幕 host
getBarrageHost(type) {
return liveAPI.get('v1/system/gethosts', { type });
};
}
const getReplyBarrage = (videoID, startTime, timeInterval) => {
getReplyBarrage(videoID, startTime, timeInterval) {
const url = 'v1/living/getreplaybarrage';
const data = {
startTime,
... ... @@ -214,12 +229,5 @@ const getReplyBarrage = (videoID, startTime, timeInterval) => {
const options = { cache: true };
return liveAPI.get(url, data, options);
};
// 处理直播时间
module.exports = {
getAllList,
fetchInfo,
getBarrageHost,
getReplyBarrage
}
};
... ...