连云港陪玩陪聊
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
chunwan/pages/pipei/shipin/detail.nvue

264 lines
8.0 KiB

3 months ago
<template>
3 months ago
<view class="room" :style="{'width': winWidth+'px', 'height': winHeight+'px'}">
<view class="room-hd">
<zego-remote-view class="video-view" :style="{'width': winWidth+'px', 'height': winHeight+'px'}" :streamID="sellerStreamId"></zego-remote-view>
<zego-local-view class="shitu"></zego-local-view>
</view>
<view class="room-fd" :style="{'width': winWidth+'px'}">
<view class="item">
<view class="pic">
<image class="pimg" src="@/static/yuyin-01-on.png"></image>
</view>
<view class="txt"><text>开启</text></view>
</view>
<view class="item">
<view class="pic">
<image class="pimg" src="@/static/yuyin-02.png"></image>
</view>
<view class="txt"><text>开启</text></view>
</view>
<view class="item">
<view class="pic">
<image class="pimg" src="@/static/yuyin-03.png"></image>
</view>
<view class="txt"><text>开启</text></view>
</view>
</view>
3 months ago
</view>
</template>
<script>
3 months ago
import api from '@/api/index.js'
3 months ago
import permision from "@/js_sdk/wa-permission/permission.js"
//导入 ZEGO Express SDK
import ZegoExpressEngine from '@/uni_modules/zego-ZegoExpressUniApp-JS/components/zego-ZegoExpressUniApp-JS/lib/ZegoExpressEngine';
3 months ago
import ZegoRemoteView from "@/uni_modules/zego-ZegoExpressUniApp-JS/components/zego-ZegoExpressUniApp-JS/zego-view/ZegoRemoteView";
import ZegoLocalView from "@/uni_modules/zego-ZegoExpressUniApp-JS/components/zego-ZegoExpressUniApp-JS/zego-view/ZegoLocalView";
3 months ago
let roomConfig = {};
roomConfig.isUserStatusNotify = true;
const profile = {
appID : 267111980,
appSign: 'afcaa90a7750ee556e450ca62287c5f9a362e9ed711789717cda0e18f088858e',
scenario : 0
};
3 months ago
export default {
components: {
ZegoLocalView,
ZegoRemoteView,
},
data() {
return {
3 months ago
winWidth: 0,
winHeight: 0,
userInfo: {},
playStreamId: "",
3 months ago
title: "视频语音",
background: {
// 导航栏背景图
background: 'url(https://api.lyiyuan.cn/profile/upload/static/yuyin-bg.png) center top no-repeat',
// 还可以设置背景图size属性
backgroundSize: '100 auto',
},
3 months ago
engine: null,
roomId: "",
sellerStreamId: ""
3 months ago
}
},
3 months ago
onLoad(o) {
this.id = o.id;
this.type=o.type;
3 months ago
this.winWidth = uni.getSystemInfoSync().windowWidth;
this.winHeight = uni.getSystemInfoSync().windowHeight;
3 months ago
},
3 months ago
mounted() {
this.toPermission();
3 months ago
},
methods: {
3 months ago
async toPermission() {
// #ifdef APP-PLUS
if (uni.getSystemInfoSync().platform === "android") {
const res = await permision.requestAndroidPermission(
"android.permission.RECORD_AUDIO"
);
const res1 = await permision.requestAndroidPermission(
"android.permission.CAMERA"
);
this.getUserInfo();
return ;
}
// #endif
this.getUserInfo();
},
//查询个人信息
async getUserInfo() {
const { code, data , msg} = await api.findUserInfo({userId: uni.getStorageSync("userInfo").id});
if(code == 200){
console.log("getUserInfo",data)
this.userInfo = data;
this.loginRoom();
}else{
uni.showToast({
title: msg,
position: "bottom",
icon: "none",
})
}
},
3 months ago
async loginRoom(){
3 months ago
const that = this;
const res = await api.findZegoToken({
3 months ago
userId: uni.getStorageSync("userInfo").id,
sellerId: this.id
})
3 months ago
if(res.code == 200){
3 months ago
// 获取token传入
3 months ago
roomConfig.token = res.data.token;
this.playStreamId = res.data.userStreamId;
this.sellerStreamId = res.data.userStreamId;
this.roomId = res.data.roomId;
console.log("loginRoom11",res.data)
this.engine = await ZegoExpressEngine.createEngineWithProfile(profile);
this.engine.enableCamera(this.type == 1?true:false)
this.engine.enableEffectsBeauty(true);
// 创建美颜参数对象
let beautyParam = {};
// 美白、红润、磨皮、锐化
beautyParam.whitenIntensity = this.userInfo.reserved5;
beautyParam.rosyIntensity = this.userInfo.reserved6;
beautyParam.smoothIntensity = this.userInfo.reserved7;
beautyParam.sharpenIntensity = this.userInfo.reserved8;
// 设置美颜参数
this.engine.setEffectsBeautyParam(beautyParam);
this.engine.useFrontCamera(true)
3 months ago
// 以下为常用的房间相关回调
3 months ago
this.engine.on('roomStateUpdate', (roomID, state, errorCode, extendedData) => {
console.log("roomStateUpdate",roomID)
3 months ago
// 房间状态更新回调,登录房间后,当房间连接状态发生变更(如出现房间断开,登录认证失败等情况),SDK会通过该回调通知
}); ;
3 months ago
this.engine.on('roomUserUpdate', (roomID, updateType, userList) => {
3 months ago
// 用户状态更新,登录房间后,当房间内有用户新增或删除时,SDK会通过该回调通知
3 months ago
console.log("roomUserUpdate",roomID,userList)
3 months ago
});
3 months ago
this.engine.on('playerStateUpdate', (roomID, updateType, streamList) => {
console.log("playerStateUpdate",roomID)
// 调用拉流接口成功后,当拉流器状态发生变更,如出现网络中断导致推流异常等情况,SDK在重试拉流的同时,会通过该回调通知
});
this.engine.on('roomStreamUpdate', (roomID, updateType, streamList) => {
console.log("playerStateUpdate",streamList)
3 months ago
// 流状态更新,登录房间后,当房间内有用户新推送或删除音视频流时,SDK会通过该回调通知
3 months ago
// this.sellerStreamId = streamList[0].streamID;
3 months ago
});
3 months ago
// 调用推流接口成功后,当推流器状态发生变更,如出现网络中断导致推流异常等情况,SDK在重试推流的同时,会通过该回调通知
that.engine.on('publisherStateUpdate', (streamID, state, errorCode, extendedData) => {
console.log("publisherStateUpdate",streamID)
});
// 登录房间
// 开始登录房间
this.engine.loginRoom(res.data.roomId,
{
'userID': uni.getStorageSync("userInfo").id,
'userName': uni.getStorageSync("userInfo").nickname
},
roomConfig
);
this.engine.startPreview();
this.engine.startPublishingStream(this.playStreamId);
setTimeout(()=>{
this.toTuiliu()
},100)
3 months ago
}
},
3 months ago
toTuiliu() {
const that = this;
console.log(this.sellerStreamId)
that.engine.startPlayingStream(this.sellerStreamId);
ZegoExpressEngine.instance().on("playerStateUpdate", (streamID, state, errorCode, extendedData) => {
/** 调用拉流接口成功后,当拉流器状态发生变更,如出现网络中断导致推流异常等情况,SDK在重试拉流的同时,会通过该回调通知 */
console.log("playerStateUpdate",roomID)
});
}
},
onBackPress() {
uni.sendSocketMessage({data:JSON.stringify({
"userId": uni.getStorageSync("userInfo").id,
type: 11,
"topic":"message"
})})
/** 停止推流 */
this.engine?.stopPublishingStream();
/** 停止本地预览 */
this.engine?.stopPreview();
/** 停止拉流 */
this.engine?.stopPlayingStream(this.sellerStreamId);
/** 退出房间 */
this.engine?.logoutRoom(this.roomId);
3 months ago
}
}
</script>
<style lang="scss">
3 months ago
.room{
&-hd{
flex-direction: column;
position: relative;
.shitu{
width: 300rpx;
height: 300rpx;
border-radius: 10rpx;
overflow: hidden;
position: fixed;
right: 20rpx;
top: 150rpx;
z-index: 1222;
}
}
&-fd{
height: 220rpx;
position: fixed;
left: 0;
bottom: 40rpx;
z-index: 44;
flex-direction: row;
.item{
flex: 1;
text-align: center;
font-size: 30rpx;
font-weight: 400;
display: flex;
justify-content: center;
align-items: center;
.txt{
margin-top: 20rpx;
text{
font-size: 30rpx;
color: #ffffff;
}
}
.pic{
width: 130rpx;
height: 130rpx;
background-color: rgba(0, 0, 0,0.36);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto;
margin-bottom: 10rpx;
.pimg{
width: 130rpx;
height: 130rpx;
}
}
}
}
3 months ago
}
</style>