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