fix(amap):core
This commit is contained in:
parent
5941a69f96
commit
a99a9d7acc
|
@ -61,40 +61,60 @@ class WebRtc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async createOffer() {
|
async createOffer() {
|
||||||
try {
|
|
||||||
const configuration = {
|
|
||||||
iceServers: [{ urls: 'stun:127.0.0.1:19302' }]
|
|
||||||
};
|
|
||||||
const peerConnection = new RTCPeerConnection(configuration);
|
|
||||||
this.pee = peerConnection
|
|
||||||
|
|
||||||
// 获取远方流添加到页面播放
|
|
||||||
peerConnection.ontrack = event => {
|
|
||||||
const remoteVideo = document.querySelector('#remoteVideo') as HTMLVideoElement;
|
|
||||||
remoteVideo.autoplay = true
|
|
||||||
remoteVideo.controls = true
|
|
||||||
remoteVideo.srcObject = event.streams[0];
|
|
||||||
event.track.onmute = function (event) {
|
|
||||||
remoteVideo.play()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
await this.getMedia(peerConnection)
|
|
||||||
|
|
||||||
peerConnection.onicecandidate = e => {
|
var url =
|
||||||
if (!e.candidate) {
|
'http://rw.quwanya.cn:12217/api/turn?service=turn&username=flutter-webrtc';
|
||||||
return
|
fetch(url)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
const configuration = {
|
||||||
|
iceServers: [
|
||||||
|
{
|
||||||
|
urls: data.uris,
|
||||||
|
"username": data.username,
|
||||||
|
"credential": data.password
|
||||||
|
},
|
||||||
|
]
|
||||||
}
|
}
|
||||||
this.ws?.send(JSON.stringify({ type: 'candidate', data: e }))
|
this.gets(configuration)
|
||||||
}
|
})
|
||||||
|
try {
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async gets(configuration) {
|
||||||
|
console.log(configuration);
|
||||||
|
|
||||||
|
const peerConnection = new RTCPeerConnection(configuration);
|
||||||
|
this.pee = peerConnection
|
||||||
|
|
||||||
|
// 获取远方流添加到页面播放
|
||||||
|
peerConnection.ontrack = event => {
|
||||||
|
const remoteVideo = document.querySelector('#remoteVideo') as HTMLVideoElement;
|
||||||
|
remoteVideo.autoplay = true
|
||||||
|
remoteVideo.controls = true
|
||||||
|
remoteVideo.srcObject = event.streams[0];
|
||||||
|
event.track.onmute = function (event) {
|
||||||
|
remoteVideo.play()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
await this.getMedia(peerConnection)
|
||||||
|
|
||||||
|
peerConnection.onicecandidate = e => {
|
||||||
|
if (!e.candidate) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.ws?.send(JSON.stringify({ type: 'candidate', data: e }))
|
||||||
|
}
|
||||||
|
}
|
||||||
sendOffer(userId) {
|
sendOffer(userId) {
|
||||||
let that = this;
|
let that = this;
|
||||||
that.userToId = userId;
|
that.userToId = userId;
|
||||||
that.video = document.getElementById('rtcVideo') as HTMLVideoElement;
|
that.video = document.getElementById('rtcVideo') as HTMLVideoElement;
|
||||||
if (that.pee?.connectionState==="closed"){
|
if (that.pee?.connectionState === "closed") {
|
||||||
that.createOffer()
|
that.createOffer()
|
||||||
}
|
}
|
||||||
that.pee?.createOffer().then(function (offer) {
|
that.pee?.createOffer().then(function (offer) {
|
||||||
|
|
Loading…
Reference in New Issue