shop-live/pages/live/anchor.nvue

84 lines
2.3 KiB
Plaintext
Raw Normal View History

2023-10-28 16:31:53 +08:00
<template>
<view>
<live-pusher id='livePusher' ref="livePusher" class="livePusher" :url="url" mode="SD" :muted="true"
:enable-camera="true" :auto-focus="true" :beauty="1" whiteness="2" aspect="9:16" @statechange="statechange"
@netstatus="netstatus" @error="error"
:style="'width: '+ windowWidth +'px; height: '+ windowHeight +'px;z-inde:-1;'">
</live-pusher>
<sd-float-page :room='room' @switchCamera='switchCamera' :msgList='msgList'
:style="'width: '+ windowWidth +'px; height: '+ windowHeight +'px;position: absolute;z-index:999999;' "></sd-float-page>
</view>
</template>
<script>
import sdFloatPage from '@/components/sd-live-page/livepage.nvue';
export default {
components: {
sdFloatPage
},
data() {
return {
url: '',
windowHeight: 0,
windowWidth: 0,
room: {},
pusherContext: null,
userName:this.userName,
inputModel:'',
msgList:[]
};
},
onReady() {
// this.context = uni.createLivePusherContext('livePusher', this);
// this.context.switchCamera() // 摄像头切换(切换为后置)
// this.context.startPreview() // 摄像头预览 (不加会黑屏)
this.windowWidth = uni.getSystemInfoSync().screenWidth //获取屏幕宽度
this.windowHeight = uni.getSystemInfoSync().screenHeight; //获取屏幕高度
// 监听窗口大小的变化
uni.onWindowResize((res) => {
this.windowHeight = res.size.windowHeight;
})
},
onLoad(options) {
this.room = JSON.parse(decodeURIComponent(options.data));
this.url = this.room.push_url
},
mounted() {
this.pusherContext = uni.createLivePusherContext('livePusher', this);
// console.log('创建 pusherContext', this.pusherContext);
//开始推流
this.pusherContext.start(function(e) {
console.log('推流情况')
// console.log(e)
});
},
methods: {
statechange(e) {
// console.log("statechange:" + JSON.stringify(e));
},
//切换摄像头
switchCamera: function() {
this.pusherContext.switchCamera({
success: (a) => {
console.log("livePusher.switchCamera:" + JSON.stringify(a));
}
});
},
netstatus(e) {
// console.log("netstatus:" + JSON.stringify(e));
},
error(e) {
// console.log("error:" + JSON.stringify(e));
},
}
};
</script>