This commit is contained in:
yumoqing 2024-10-11 16:56:28 +08:00
parent 60cc94d404
commit fb54707c6f

View File

@ -217,12 +217,9 @@ bricks.RTCP2PConnect = class {
aconsole.log(peer, 'connect exists', this);
}
console.log('p2pconnect() called, this=', this, 'peer=', peer);
if (role=='requester'){
await this.send_offer(peer);
}
}
async h_sessioncreated(data){
await this.p2pconnect(data.msgfrom, 'requester');
if (this.opts.peer_info){
var d = {
type:'callrequest',
@ -234,17 +231,17 @@ bricks.RTCP2PConnect = class {
}
async h_callrequest(data){
if (this.opts.auto_callaccept || true){
await this.p2pconnect(data.msgfrom, 'responser');
var d = {
type:'callaccepted',
msgto:data.msgfrom
};
this.signaling_send(d);
await this.p2pconnect(data.msgfrom, 'responser');
return;
}
}
async h_callaccepted(data){
await this.p2pconnect(data.msgfrom, 'requester');
await this.send_offer(data.msgfrom);
}
async h_offer(data){
console.log('h_offer(), this=', this, 'peer=', data.msgfrom);
@ -326,13 +323,11 @@ bricks.RTCP2PConnect = class {
var pc = this.peers[peer.id].pc;
var role = this.peers[peer.id].role;
console.log(`${peer.id} state changed. new state=${pc.connectionState}`);
console.log('state=', pc.connectionState, typeof(pc.connectionState));
if (pc.connectionState == 'disconnected'){
var w = new bricks.Error({
title:'Error',
message:'lose connection',
timeout:4
});
w.open();
if (this.opts.on_pc_disconnected){
this.opts.on_pc_disconnected(peer);
}
return;
}
if (pc.connectionState == 'connected'){
@ -342,6 +337,9 @@ bricks.RTCP2PConnect = class {
if (this.opts.data_connect && role == 'requester'){
var dc = pc.createDataChannel('chat');
await this.dc_created(peer, dc);
if(this.opts.on_pc_connected){
this.opts.on_pc_connected(peer);
}
} else {
console.log('87y333333333333333333333333333333333354');
}