Browse Source

视频聊天功能-开发中

master
xie.bx 3 years ago
parent
commit
e713639bc2
  1. 27
      im-ui/src/components/chat/ChatPrivateVideo.vue

27
im-ui/src/components/chat/ChatPrivateVideo.vue

@ -48,8 +48,7 @@
state: 'NOT_CONNECTED', state: 'NOT_CONNECTED',
candidates: [], candidates: [],
configuration: { configuration: {
iceServers: [ iceServers: [{
{
urls: 'stun:stun.l.google.com:19302' urls: 'stun:stun.l.google.com:19302'
}, },
{ {
@ -127,15 +126,23 @@
console.log("onaddstream") console.log("onaddstream")
this.$refs.friendVideo.srcObject = e.streams[0]; this.$refs.friendVideo.srcObject = e.streams[0];
}; };
this.peerConnection.onicegatheringstatechange = (event) => {
if (this.peerConnection.iceGatheringState == 'complete') {
this.candidates.forEach((candidate) => {
this.sendCandidate(candidate);
})
}
}
this.peerConnection.onicecandidate = (event) => { this.peerConnection.onicecandidate = (event) => {
if (event.candidate) { if (event.candidate) {
if (this.state == 'CONNECTED') { // if (this.state == 'CONNECTED') {
// , // // ,
this.sendCandidate(event.candidate); // this.sendCandidate(event.candidate);
} else { // } else {
// , // ,
this.candidates.push(event.candidate) this.candidates.push(event.candidate)
} //}
} }
} }
if (stream) { if (stream) {
@ -158,9 +165,9 @@
// //
this.state = 'CONNECTED'; this.state = 'CONNECTED';
// candidate // candidate
this.candidates.forEach((candidate) => { // this.candidates.forEach((candidate) => {
this.sendCandidate(candidate); // this.sendCandidate(candidate);
}) // })
} }
if (msg.type == this.$enums.MESSAGE_TYPE.RTC_REJECT) { if (msg.type == this.$enums.MESSAGE_TYPE.RTC_REJECT) {
this.$message.error("对方拒绝了您的视频请求"); this.$message.error("对方拒绝了您的视频请求");

Loading…
Cancel
Save