food/src/views/layout/components/main/site/index.vue

46 lines
813 B
Vue
Raw Normal View History

2023-09-20 21:33:11 +08:00
<template>
<div>
<video
ref="video"
autoplay
controls
playsinline
muted
width="640"
height="360"
></video>
2023-09-20 21:33:11 +08:00
</div>
</template>
<script>
export default {
data () {
return {
url: 'http://82.156.122.87:80/rtc/v1/whep/?app=live&stream=083AF27BB2D0',
sdk: null
2023-09-20 21:33:11 +08:00
}
},
mounted () {
this.startPlay()
2023-09-20 21:33:11 +08:00
},
methods: {
async startPlay () {
if (this.sdk) {
this.sdk.close()
this.sdk = null
2023-09-20 21:33:11 +08:00
}
this.sdk = new window.SrsRtcWhipWhepAsync()
this.$refs.video.srcObject = this.sdk.stream
2023-09-20 21:33:11 +08:00
try {
const session = await this.sdk.play(this.url)
console.log('播放成功session:', session)
} catch (e) {
console.error('播放失败', e)
}
}
2023-09-20 21:33:11 +08:00
}
}
</script>