This commit is contained in:
yumoqing 2024-08-23 11:53:23 +08:00
parent 3af4d43157
commit 224afacc2c

View File

@ -152,7 +152,7 @@ bricks.RTCClient = class extends bricks.VBox {
async send_offer(){
var offer = await this.pc.createOffer();
await this.pc.setLocalDescription(offer);
console.log('offer =', offer, this.pc.localDescription);
console.log('########send_offer =', offer, this.pc.localDescription);
this.socket.send(JSON.stringify({
type:'offer',
offer:this.pc.localDescription,
@ -190,6 +190,7 @@ bricks.RTCClient = class extends bricks.VBox {
}));
}
async call_close(active){
this.role = null;
this.pc.onicecandidate = null;
this.pc.ontrack = null;
this.pc.close();
@ -241,16 +242,19 @@ bricks.RTCClient = class extends bricks.VBox {
await this.pc.setRemoteDescription(offer);
var answer = await this.pc.createAnswer();
await this.pc.setLocalDescription(answer);
console.log('answer=', answer, 'desc=', this.pc.localDescription);
console.log('###### send_answer=', answer, 'desc=', this.pc.localDescription);
this.socket.send(JSON.stringify({
type:'answer',
answer:this.pc.localDescription,
to:this.peer_info
}));
console.log('offer branch exe');
if (this.role == 'responser'){
this.send_offer();
}
break;
case 'answer':
console.log('answer: d.from=', d.from, 'peer_info=', this.peer_info);
console.log('#### receive_answer: d.from=', d.from, 'peer_info=', this.peer_info);
if (d.from.id == this.peer_info.id){
var desc = new RTCSessionDescription(d.answer);
await this.pc.setRemoteDescription(desc);
@ -321,18 +325,14 @@ bricks.RTCClient = class extends bricks.VBox {
this.pc.ontrack = event => {
this.remoteVideo.set_stream(event.streams[0]);
};
await this.send_offer();
if (this.role == 'requester'){
await this.send_offer();
}
console.log('createPeerConnection() finished');
}
async ice_statechange(event){
console.log(`oniceconnectionstatechange, pc.iceConnectionState is ${this.pc.iceConnectionState}.`);
if (this.pc.iceConnectionState === 'disconnected'){
if (this.role == 'requester'){
await this.send_offer();
}
}
}
async connection_statechange(event){
console.log(`onconnectionstatechange, pc.connectionState is ${this.pc.connectionState}.`);