This commit is contained in:
yumoqing 2024-10-11 17:24:39 +08:00
parent b6ca1750b2
commit 520e2ad10c

View File

@ -335,12 +335,13 @@ bricks.RTCP2PConnect = class {
this.opts.data_connect,
'role=', role);
if (role == 'requester'){
var dc = pc.createDataChannel('chat');
await this.dc_created(peer, dc);
this.peers[peer.id].dc = pc.createDataChannel('chat');
var dc = this.peers[peer.id].dc;
await this.dc_created(peer, this.peers[peer.id].dc);
if(this.opts.on_pc_connected){
this.opts.on_pc_connected(peer);
}
console.log('dc created', dc);
console.log('dc created', this.peers[peer.id].dc);
} else {
console.log('87y333333333333333333333333333333333354');
}
@ -349,33 +350,32 @@ bricks.RTCP2PConnect = class {
async dc_accepted(peer, event){
console.log('accept datachannel ....');
dc = event.channel;
await this.dc_created(peer, event);
this.peers[peer.id].dc = event.channel;
await this.dc_created(peer, this.peers[peer.id].dc);
}
async dc_created(peer, dc){
console.log('dc_created.....', dc);
this.peers[peer.id].dc = dc;
dc.onmessage = this.datachannel_message.bind(this, peer);
dc.onopen = this.datachannel_open(this, peer);
dc.onclose = this.datachannel_close(this, peer);
}
async datachannel_message(peer, msg){
console.log('datachannel_message():', peer. msg);
console.log('datachannel_message():', this, peer, msg);
var dc = this.peers[peer.id].dc;
if (this.opts.on_dc_messaage){
await this.opts.on_dc_message(dc, msg);
}
}
async datachannel_open(peer){
console.log('datachannel_open():', arguments, peer);
console.log('datachannel_open():', this, peer);
var dc = this.peers[peer.id].dc
if (this.opts.on_dc_open){
await this.opts.on_dc_open(dc);
}
}
async datachannel_close(peer){
console.log('datachannel_close():', peer);
console.log('datachannel_close():', this, peer);
var dc = this.peers[peer.id].dc
if (this.opts.on_dc_close){
await this.opts.on_dc_close(dc);