From cb6cea04874bef55f72295482daacbad9ee2a076 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 10 Oct 2024 16:41:27 +0800 Subject: [PATCH] bugfix --- bricks/rtc.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/bricks/rtc.js b/bricks/rtc.js index e887c2a..6219b09 100644 --- a/bricks/rtc.js +++ b/bricks/rtc.js @@ -21,6 +21,8 @@ bricks.Signaling = class { signaling_url: info: connect_opts: + onclose: + onpeers } */ constructor(opts){ @@ -33,6 +35,10 @@ bricks.Signaling = class { this.sessionhandlers = {}; this.init_websocket(); this.hb_task = null; + this.heartbeat_period = opts.heartbeat_period; + this.onclose = opts.onclose; + this.onopen = opts.onopen; + this.onpeers = opts.onpeers; if (!this.heartbeat_period){ this.heartbeat_period = 0; } @@ -90,11 +96,13 @@ bricks.Signaling = class { async recvdata_handler(data){ if (data.type == 'online'){ data.online.forEach(p => { - var d = self.peers[p.id]; + var d = this.peers[p.id]; if (!d) d = {}; d = bricks.extend(d, p); - self.peers[p.id] = d; - }) + this.peers[p.id] = d; + }); + if (this.onpeers){ + this.onpeers(this.peers); return; } if (data.type == 'new_session'){