This commit is contained in:
yumoqing 2024-10-10 16:41:27 +08:00
parent 3594dd3161
commit cb6cea0487

View File

@ -21,6 +21,8 @@ bricks.Signaling = class {
signaling_url: signaling_url:
info: info:
connect_opts: connect_opts:
onclose:
onpeers
} }
*/ */
constructor(opts){ constructor(opts){
@ -33,6 +35,10 @@ bricks.Signaling = class {
this.sessionhandlers = {}; this.sessionhandlers = {};
this.init_websocket(); this.init_websocket();
this.hb_task = null; 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){ if (!this.heartbeat_period){
this.heartbeat_period = 0; this.heartbeat_period = 0;
} }
@ -90,11 +96,13 @@ bricks.Signaling = class {
async recvdata_handler(data){ async recvdata_handler(data){
if (data.type == 'online'){ if (data.type == 'online'){
data.online.forEach(p => { data.online.forEach(p => {
var d = self.peers[p.id]; var d = this.peers[p.id];
if (!d) d = {}; if (!d) d = {};
d = bricks.extend(d, p); d = bricks.extend(d, p);
self.peers[p.id] = d; this.peers[p.id] = d;
}) });
if (this.onpeers){
this.onpeers(this.peers);
return; return;
} }
if (data.type == 'new_session'){ if (data.type == 'new_session'){