巴林闲侠
2 years ago
22 changed files with 417 additions and 153 deletions
@ -0,0 +1,59 @@ |
|||
'use strict'; |
|||
const moment = require('moment') |
|||
const request = require('superagent') |
|||
|
|||
function videoList (opts) { |
|||
return async function (ctx) { |
|||
try { |
|||
const { models, } = ctx.fs.dc; |
|||
const { app, yingshiTokenRes } = ctx |
|||
|
|||
let yingshiToken = '' |
|||
if (yingshiTokenRes && yingshiTokenRes.token && yingshiTokenRes.expire && moment().isBefore(moment(yingshiTokenRes.expire))) { |
|||
yingshiToken = yingshiTokenRes.token |
|||
} else { |
|||
const tokenRes = await app.fs.yingshiRequest.post(`lapp/token/get`, { |
|||
query: { |
|||
appKey: opts.yingshiKey, |
|||
appSecret: opts.yingshiSecret |
|||
} |
|||
}) |
|||
if (tokenRes.code == 200 && tokenRes.data) { |
|||
const { accessToken, expireTime } = tokenRes.data |
|||
|
|||
ctx.yingshiTokenRes = { |
|||
token: accessToken, |
|||
expire: expireTime |
|||
} |
|||
yingshiToken = accessToken |
|||
} else { |
|||
throw '未能获取进行萤石鉴权' |
|||
} |
|||
} |
|||
|
|||
const deviceRes = await app.fs.yingshiRequest.post(`lapp/device/list`, { |
|||
query: { |
|||
accessToken: yingshiToken, |
|||
} |
|||
}) |
|||
|
|||
ctx.status = 200; |
|||
ctx.body = (deviceRes.data || []).map(item => { |
|||
return { |
|||
...item, |
|||
token: yingshiToken, |
|||
} |
|||
}) |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); |
|||
ctx.status = 400; |
|||
ctx.body = { |
|||
message: typeof error == 'string' ? error : undefined |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
module.exports = { |
|||
videoList |
|||
}; |
@ -1,50 +0,0 @@ |
|||
'use strict'; |
|||
|
|||
const request = require('superagent'); |
|||
const buildUrl = (url,token) => { |
|||
let connector = url.indexOf('?') === -1 ? '?' : '&'; |
|||
return `${url}${connector}token=${token}`; |
|||
}; |
|||
|
|||
function factory(app, router, opts) { |
|||
return async function (ctx, next) { |
|||
|
|||
const token = ctx.fs.api.token; |
|||
|
|||
//console.log(username,password)
|
|||
const req = { |
|||
get: (url, query) => { |
|||
return request |
|||
.get(buildUrl(url,token)) |
|||
.query(query) |
|||
}, |
|||
post: (url, data, query) => { |
|||
return request |
|||
.post(buildUrl(url,token)) |
|||
.query(query) |
|||
//.set('Content-Type', 'application/json')
|
|||
.send(data); |
|||
}, |
|||
|
|||
put: (url, data) => { |
|||
return request |
|||
.put(buildUrl(url,token)) |
|||
//.set('Content-Type', 'application/json')
|
|||
.send(data); |
|||
}, |
|||
|
|||
delete: (url) => { |
|||
return request |
|||
.del(buildUrl(url,token)) |
|||
}, |
|||
}; |
|||
|
|||
app.business = app.business || {}; |
|||
app.business.request = req; |
|||
|
|||
await next(); |
|||
}; |
|||
} |
|||
|
|||
module.exports = factory; |
|||
|
@ -0,0 +1,67 @@ |
|||
'use strict'; |
|||
const request = require('superagent') |
|||
|
|||
class paasRequest { |
|||
constructor(root, { query = {} } = {}, option) { |
|||
this.root = root; |
|||
this.query = query |
|||
this.option = option |
|||
} |
|||
|
|||
#buildUrl = (url) => { |
|||
return `${this.root}/${url}`; |
|||
} |
|||
|
|||
#resultHandler = (resolve, reject) => { |
|||
return (err, res) => { |
|||
if (err) { |
|||
reject(err); |
|||
} else { |
|||
resolve(res[this.option.dataWord]); |
|||
} |
|||
}; |
|||
} |
|||
|
|||
get = (url, { query = {}, header = {} } = {}) => { |
|||
return new Promise((resolve, reject) => { |
|||
request.get(this.#buildUrl(url)).set(header).query(Object.assign(query, this.query)).end(this.#resultHandler(resolve, reject)); |
|||
}) |
|||
} |
|||
|
|||
post = (url, { data = {}, query = {}, header = {} } = {}) => { |
|||
return new Promise((resolve, reject) => { |
|||
request.post(this.#buildUrl(url)).set(header).query(Object.assign(query, this.query)).send(data).end(this.#resultHandler(resolve, reject)); |
|||
}) |
|||
} |
|||
|
|||
put = (url, { data = {}, header = {}, query = {}, } = {}) => { |
|||
return new Promise((resolve, reject) => { |
|||
request.put(this.#buildUrl(url)).set(header).query(Object.assign(query, this.query)).send(data).end(this.#resultHandler(resolve, reject)); |
|||
}) |
|||
} |
|||
|
|||
delete = (url, { header = {}, query = {} } = {}) => { |
|||
return new Promise((resolve, reject) => { |
|||
request.delete(this.#buildUrl(url)).set(header).query(Object.assign(query, this.query)).end(this.#resultHandler(resolve, reject)); |
|||
}) |
|||
} |
|||
} |
|||
|
|||
function factory (app, opts) { |
|||
if (opts.pssaRequest) { |
|||
try { |
|||
for (let r of opts.pssaRequest) { |
|||
if (r.name && r.root) { |
|||
app.fs[r.name] = new paasRequest(r.root, { ...(r.params || {}) }, { dataWord: r.dataWord || 'body' }) |
|||
} else { |
|||
throw 'opts.pssaRequest 参数错误!' |
|||
} |
|||
} |
|||
} catch (error) { |
|||
console.error(error) |
|||
process.exit(-1); |
|||
} |
|||
} |
|||
} |
|||
|
|||
module.exports = factory; |
@ -0,0 +1,52 @@ |
|||
/** |
|||
* 萤石视频直播(基于萤石云iframe模式,使用方式简单) |
|||
* 官方参考:https://open.ys7.com/console/ezopenIframe.html
|
|||
*/ |
|||
'use strict'; |
|||
|
|||
import React from 'react'; |
|||
import { connect } from 'react-redux'; |
|||
|
|||
const YSIframePlayer = props => { |
|||
|
|||
const { containerId, height, width, url, autoplay, audio, videoState, ysToken } = props; |
|||
const at = ysToken |
|||
if (!url || !at) return null; |
|||
const src = `https://open.ys7.com/ezopen/h5/iframe?audio=${audio ? '1' : '0'}&url=${url}&autoplay=${autoplay || 1}&accessToken=${at}` |
|||
// const src = `https://open.ys7.com/ezopen/h5/iframe?audio=1&url=${url}&autoplay=${autoplay || 1}&accessToken=${at}`
|
|||
return ( |
|||
<div |
|||
style={{ position: 'relative', height: '100%', width: '100%' }}> |
|||
<iframe |
|||
frameBorder="0" |
|||
id={containerId || 'myPlayer'} |
|||
src={src} |
|||
// https://open.ys7.com/doc/zh/book/index/live_proto.html 单个播放器的长宽比例限制最小为{width: 400px;height: 300px;}
|
|||
width={width || 400} |
|||
height={height || 300} |
|||
allowFullScreen |
|||
wmode="transparent" |
|||
> |
|||
</iframe> |
|||
{ |
|||
videoState && videoState.status == 0 ? |
|||
<div style={{ |
|||
height: width || 300, width: width || 400, position: 'absolute', top: 0, background: '#000', |
|||
display: 'flex', justifyContent: 'center', alignItems: 'center', color: '#fff' |
|||
}}> |
|||
设备中断,正在处理中... |
|||
</div> |
|||
: '' |
|||
} |
|||
</div> |
|||
) |
|||
} |
|||
|
|||
function mapStateToProps (state) { |
|||
const { auth, } = state; |
|||
return { |
|||
user: auth.user, |
|||
}; |
|||
} |
|||
|
|||
export default connect(mapStateToProps)(YSIframePlayer); |
@ -0,0 +1,30 @@ |
|||
import React, { useState, useEffect } from 'react'; |
|||
import { connect } from 'react-redux'; |
|||
import { getAssess, delAssess, editAssess } from '../actions/assess'; |
|||
import ProTable from '@ant-design/pro-table'; |
|||
import AssessModal from '../components/assessModal'; |
|||
import { Form, Space, DatePicker, Button, Select, Popconfirm } from 'antd' |
|||
import moment from 'moment'; |
|||
|
|||
function VideoCenter (props) { |
|||
const { dispatch, vcmpWebUrl, vcmpMirrorId } = props; |
|||
|
|||
useEffect(() => { |
|||
return () => { }; |
|||
}, []); |
|||
|
|||
return ( |
|||
<div> |
|||
<iframe src={`${vcmpWebUrl}/callService?mid=${vcmpMirrorId}`} style={{ height: 'calc(100vh - 142px)', width: '100%', display: 'block' }} frameBorder={0}></iframe> |
|||
</div> |
|||
); |
|||
} |
|||
function mapStateToProps (state) { |
|||
const { auth, global } = state |
|||
return { |
|||
user: auth.user, |
|||
vcmpWebUrl: global.vcmpWebUrl, |
|||
vcmpMirrorId: global.vcmpMirrorId, |
|||
} |
|||
} |
|||
export default connect(mapStateToProps)(VideoCenter); |
@ -1,19 +1,30 @@ |
|||
import React from 'react' |
|||
import React, { useEffect, useState } from 'react' |
|||
import Left from './left' |
|||
import Right from './right' |
|||
import CenterLeft from "./centerLeft" |
|||
import Centerright from "./centerRight" |
|||
import { connect } from 'react-redux' |
|||
import { getNearestAssessData, getVideoCenterList } from "../../../actions/example" |
|||
|
|||
const Leadership = (props) => { |
|||
const { dispatch } = props |
|||
|
|||
useEffect(() => { |
|||
dispatch(getVideoCenterList()) |
|||
}, []) |
|||
|
|||
return ( |
|||
<> |
|||
<Left dispatch={dispatch} /> |
|||
<CenterLeft dispatch={dispatch} /> |
|||
<Right dispatch={dispatch} /> |
|||
{/* <Centerright /> */} |
|||
|
|||
</> |
|||
) |
|||
} |
|||
export default Leadership |
|||
function mapStateToProps (state) { |
|||
return { |
|||
|
|||
} |
|||
} |
|||
export default connect(mapStateToProps)(Leadership) |
Loading…
Reference in new issue