|
@@ -2,11 +2,12 @@
|
|
|
* srs webrtc palyer
|
|
* srs webrtc palyer
|
|
|
* auth Caner
|
|
* auth Caner
|
|
|
*/
|
|
*/
|
|
|
|
|
+ import MD5 from 'js-md5'
|
|
|
class WebRtcPlayer {
|
|
class WebRtcPlayer {
|
|
|
private Peer: any
|
|
private Peer: any
|
|
|
private TIMER: any
|
|
private TIMER: any
|
|
|
- constructor(option: { HOST: string; TOKEN: string; UUID: string; PROFILE: number; PORT: number; DOM: HTMLVideoElement }) {
|
|
|
|
|
- this.initWebRtc(option.HOST, option.PORT, option.TOKEN, option.UUID, option.PROFILE, option.DOM).then(res => {
|
|
|
|
|
|
|
+ constructor(option: { HOST: string; TOKEN: string; UUID: string; PROFILE: number; PORT: number; DOM: HTMLVideoElement, starttime?: number; endtime?: number }) {
|
|
|
|
|
+ this.initWebRtc(option.HOST, option.PORT, option.TOKEN, option.UUID, option.PROFILE, option.DOM, option.starttime, option.endtime).then(res => {
|
|
|
this.Peer = res
|
|
this.Peer = res
|
|
|
}).catch(() => {
|
|
}).catch(() => {
|
|
|
this.Peer = null
|
|
this.Peer = null
|
|
@@ -28,7 +29,7 @@ class WebRtcPlayer {
|
|
|
* @param DOM video节点
|
|
* @param DOM video节点
|
|
|
* @returns
|
|
* @returns
|
|
|
*/
|
|
*/
|
|
|
- private async initWebRtc(HOST: string, PORT: number, TOKEN: string, UUID: string, PROFILE: number, DOM: HTMLVideoElement) {
|
|
|
|
|
|
|
+ private async initWebRtc(HOST: string, PORT: number, TOKEN: string, UUID: string, PROFILE: number, DOM: HTMLVideoElement, STIME?: number, ETIME?: number) {
|
|
|
try {
|
|
try {
|
|
|
const Peer = new RTCPeerConnection() as any
|
|
const Peer = new RTCPeerConnection() as any
|
|
|
Peer.addTransceiver('video', { direction: 'recvonly' })
|
|
Peer.addTransceiver('video', { direction: 'recvonly' })
|
|
@@ -59,11 +60,18 @@ class WebRtcPlayer {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// SDP SRS params
|
|
// SDP SRS params
|
|
|
- const params = {
|
|
|
|
|
|
|
+ const STREAM = STIME && ETIME ? MD5(UUID + PROFILE + Math.floor(new Date().getTime() * Math.random() * 100)) : UUID + PROFILE
|
|
|
|
|
+ const params = STIME && ETIME ? {
|
|
|
api: `http://${HOST}:${PORT}/rtc/v1/play/?token=${TOKEN}&uuid=${UUID}&stream=${UUID + PROFILE}&profile=${PROFILE}`,
|
|
api: `http://${HOST}:${PORT}/rtc/v1/play/?token=${TOKEN}&uuid=${UUID}&stream=${UUID + PROFILE}&profile=${PROFILE}`,
|
|
|
clientip: null,
|
|
clientip: null,
|
|
|
sdp: offer.sdp,
|
|
sdp: offer.sdp,
|
|
|
- streamurl: `webrtc://${HOST}/live/${UUID + PROFILE}?token=${TOKEN}&uuid=${UUID}&stream=${UUID + PROFILE}&profile=${PROFILE}`,
|
|
|
|
|
|
|
+ streamurl: `webrtc://${HOST}/replay/${STREAM}?token=${TOKEN}&starttime=${STIME}&endtime=${ETIME}&uuid=${UUID}&stream=${STREAM}&profile=${PROFILE}`,
|
|
|
|
|
+ tid: Number(Math.floor(new Date().getTime() * Math.random() * 100)).toString(16).slice(0, 7)
|
|
|
|
|
+ } : {
|
|
|
|
|
+ api: `http://${HOST}:${PORT}/rtc/v1/play/?token=${TOKEN}&uuid=${UUID}&stream=${UUID + PROFILE}&profile=${PROFILE}`,
|
|
|
|
|
+ clientip: null,
|
|
|
|
|
+ sdp: offer.sdp,
|
|
|
|
|
+ streamurl: `webrtc://${HOST}/live/${STREAM}?token=${TOKEN}&uuid=${UUID}&stream=${STREAM}&profile=${PROFILE}`,
|
|
|
tid: Number(Math.floor(new Date().getTime() * Math.random() * 100)).toString(16).slice(0, 7)
|
|
tid: Number(Math.floor(new Date().getTime() * Math.random() * 100)).toString(16).slice(0, 7)
|
|
|
}
|
|
}
|
|
|
console.log('params', params)
|
|
console.log('params', params)
|
|
@@ -157,6 +165,31 @@ class WebRtcPlayer {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 倍数播放
|
|
|
|
|
+ * @param URL
|
|
|
|
|
+ * @param TOKEN
|
|
|
|
|
+ * @param uuid
|
|
|
|
|
+ * @param stream
|
|
|
|
|
+ */
|
|
|
|
|
+ public async speedPlay(URL: string, TOKEN: string, uuid: string, stream: string) {
|
|
|
|
|
+ window.fetch(URL, {
|
|
|
|
|
+ method: 'POST',
|
|
|
|
|
+ headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
+ body: JSON.stringify({
|
|
|
|
|
+ code: 'replay.play',
|
|
|
|
|
+ token: TOKEN,
|
|
|
|
|
+ body: {
|
|
|
|
|
+ uuid: uuid, // 摄像头id
|
|
|
|
|
+ stream: stream, // 播放视频生成的stream
|
|
|
|
|
+ startTime: 1667836800000, // 播放开始时间,默认0,即当前时间
|
|
|
|
|
+ endTime: 1667923199000, // 播放结束时间。默认0,即一直播放,不主动结束
|
|
|
|
|
+ speed: 4.0 // 速度 0.25、0.5、1、2、4。
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 关闭webrtc
|
|
* 关闭webrtc
|
|
|
*/
|
|
*/
|