From 33ef5372e72b0450418bfa15e4ccafb1d901ae85 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sat, 12 Oct 2024 11:50:46 +0800 Subject: [PATCH] bugfix --- bricks/rtc.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/bricks/rtc.js b/bricks/rtc.js index eaebd20..f30bc48 100644 --- a/bricks/rtc.js +++ b/bricks/rtc.js @@ -241,6 +241,7 @@ bricks.RTCP2PConnect = class { } } async h_callaccepted(data){ + this.createDataChannel(data.msgfrom); await this.send_offer(data.msgfrom, true); } async h_offer(data){ @@ -374,6 +375,15 @@ bricks.RTCP2PConnect = class { await this.opts.on_dc_close(dc); } } + createDataChannel(peer){ + this.peers[peer.id].dc = pc.createDataChannel('chat', {ordered:true}); + 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', this.peers[peer.id].dc); + } async createPeerConnection(peer){ const configuration = { iceServers:this.opts.ice_servers @@ -391,15 +401,6 @@ bricks.RTCP2PConnect = class { this.peers[peer.id].role = ''; var remoteVideo = new bricks.VideoBox(); this.peers[peer.id].video = remoteVideo; - if (role == 'requester'){ - this.peers[peer.id].dc = pc.createDataChannel('chat', {ordered:true}); - 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', this.peers[peer.id].dc); - } pc.onicecandidate = this.send_candidate.bind(this, peer); pc.oniceconnectionstatechange = this.ice_statechange.bind(this, peer); pc.onconnectionstatechange = this.connection_statechange.bind(this, peer);