This commit is contained in:
yumoqing 2024-10-11 17:45:17 +08:00
parent 79154df9fb
commit 7d5a13850d

View File

@ -335,7 +335,7 @@ bricks.RTCP2PConnect = class {
this.opts.data_connect, this.opts.data_connect,
'role=', role); 'role=', role);
if (role == 'requester'){ if (role == 'requester'){
this.peers[peer.id].dc = pc.createDataChannel('chat'); this.peers[peer.id].dc = pc.createDataChannel('chat', {ordered:true});
var dc = this.peers[peer.id].dc; var dc = this.peers[peer.id].dc;
await this.dc_created(peer, this.peers[peer.id].dc); await this.dc_created(peer, this.peers[peer.id].dc);
if(this.opts.on_pc_connected){ if(this.opts.on_pc_connected){
@ -360,16 +360,17 @@ bricks.RTCP2PConnect = class {
dc.onclose = this.datachannel_close(peer); dc.onclose = this.datachannel_close(peer);
} }
async datachannel_message(peer, msg){ async datachannel_message(peer, event){
console.log('datachannel_message():', this, arguments); console.log('datachannel_message():', this, arguments);
var dc = this.peers[peer.id].dc; var dc = this.peers[peer.id].dc;
if (this.opts.on_dc_messaage){ if (this.opts.on_dc_messaage){
await this.opts.on_dc_message(dc, msg); await this.opts.on_dc_message(dc, event.data);
} }
} }
async datachannel_open(peer){ async datachannel_open(peer){
console.log('datachannel_open():', this, arguments); console.log('datachannel_open():', this, arguments);
var dc = this.peers[peer.id].dc var dc = this.peers[peer.id].dc
dc.send('test');
if (this.opts.on_dc_open){ if (this.opts.on_dc_open){
await this.opts.on_dc_open(dc); await this.opts.on_dc_open(dc);
} }