From 6fa7be2466c6ec2e5dc8f0547ed8a7c850ee387c Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 30 Aug 2024 16:48:43 +0800 Subject: [PATCH] bugfix --- bricks/rtc.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/bricks/rtc.js b/bricks/rtc.js index 2fba339..9d23407 100644 --- a/bricks/rtc.js +++ b/bricks/rtc.js @@ -153,14 +153,14 @@ bricks.RTCClient = class extends bricks.VBox { type:'login', info:this.info } - this.socket.send(JSON.stringify(d)); + this.socket_send(JSON.stringify(d)); } signaling_logout(){ var d= { type:'logout', info:this.info } - this.socket.send(JSON.stringify(d)); + this.socket_send(JSON.stringify(d)); } // 获取本地媒体流 async getLocalStream() { @@ -183,13 +183,13 @@ bricks.RTCClient = class extends bricks.VBox { } this.peer_info = peer_info; this.role = 'requester'; - this.socket.send(JSON.stringify(d)); + this.socket_send(JSON.stringify(d)); } async send_offer(){ var offer = await this.pc.createOffer(); await this.pc.setLocalDescription(offer); console.log('########send_offer =', offer, this.pc.localDescription); - this.socket.send(JSON.stringify({ + this.socket_send(JSON.stringify({ type:'offer', offer:this.pc.localDescription, to:this.peer_info @@ -199,7 +199,7 @@ bricks.RTCClient = class extends bricks.VBox { if (event.candidate) { var candidate = event.candidate; console.log('send_candidate(), candidate=', candidate); - this.socket.send(JSON.stringify({ + this.socket_send(JSON.stringify({ type: 'iceCandidate', to:peer_info, candidate: candidate @@ -220,7 +220,7 @@ bricks.RTCClient = class extends bricks.VBox { this.peer_info = peer_info this.role = 'responser' await this.createPeerConnection(this.peer_info); - this.socket.send(JSON.stringify({ + this.socket_send(JSON.stringify({ type: 'callAccepted', to: peer_info })); @@ -231,7 +231,7 @@ bricks.RTCClient = class extends bricks.VBox { this.pc.ontrack = null; this.pc.close(); if (! active){ - this.socket.send(JSON.stringify({ + this.socket_send(JSON.stringify({ type:'disconnect', to:this.peer_info })); @@ -251,11 +251,19 @@ bricks.RTCClient = class extends bricks.VBox { this.peer_w.set_text(''); } call_rejected(peer_info){ - this.socket.send(JSON.stringify({ + this.socket_send(JSON.stringify({ type: 'callRejected', to: peer_info })); } + socket_send(s){ + try { + this.socket.send(s); + } catch (e){ + this.init_websocket(); + this.socket.send(s); + } + } async signaling_message_handle(event){ var datapkg = JSON.parse(event.data); var d = datapkg.data; @@ -279,7 +287,7 @@ bricks.RTCClient = class extends bricks.VBox { var answer = await this.pc.createAnswer(); await this.pc.setLocalDescription(answer); console.log('###### send_answer=', answer, 'desc=', this.pc.localDescription); - this.socket.send(JSON.stringify({ + this.socket_send(JSON.stringify({ type:'answer', answer:this.pc.localDescription, to:this.peer_info