rtc.client = AgoraRTC.createClient({ mode: "rtc", codec: "h264" });
console.log('new success',rtc.client)
rtc.client.on("user-published", async (user, mediaType,config) => {
console.log('1111',user, mediaType,config)
await rtc.client.subscribe(user, mediaType);
console.log('2222',user, mediaType)
if (mediaType === "video") {
if (user._videoTrack._isClosed) {
if(this.duoRenLT){
let dangQianYH = this.shiPinTHList.findIndex(item=>item.uid == user.uid)
this.$set(this.shiPinTHList[dangQianYH],'sheXiangTou',true)
}
this.isHZGuanBiSXT = false
uni.showToast({
title: "对方已打开摄像头",
icon: "none",
});
}else{
this.isHZGuanBiSXT = false
uni.showToast({
title: '患者已加入视频聊天',
icon: 'none',
})
}
this.huanZheJR = true
clearTimeout(this.chaoShi)
this.chaoShi = null
const remoteVideoTrack = user.videoTrack;
if(this.duoRenLT){
this.shiPinTHList.push({
uid:user.uid.toString(),
sheXiangTou:true
})
this.$nextTick(()=>{
const boFangRQ = document.getElementById(user.uid);
remoteVideoTrack.play(boFangRQ)
})
}else{
const remotePlayerContainer = document.createElement("div");
remotePlayerContainer.id = user.uid.toString();
// remotePlayerContainer.textContent = "Remote user " + user.uid.toString();
remotePlayerContainer.style.width = '100%';
remotePlayerContainer.style.height = '100%';
document.getElementById('shiPinTHSmall').append(remotePlayerContainer);
remoteVideoTrack.play(remotePlayerContainer);
}
}
})
上述代码,web端通信时user-published能正常执行, web端与小程序通信时user-published 不生效,web监听不到小程序的视频流, 小程序能监听到web的视频流
这个回调只有在远端是主播身份时才会触发,观众不能发流 只能收流,检查下小程序是不是主播