Skip to content

Commit

Permalink
fix : fix on connect event should wait true connection
Browse files Browse the repository at this point in the history
  • Loading branch information
nuzulul committed Jul 17, 2024
1 parent da0b89f commit e33beae
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/webpeerjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class webpeerjs{

//track last connect to webpeer network
#lastTimeConnectToNetwork
#lastTimeReceiveData

//arr to track on connect event
#onConnectQueue
Expand Down Expand Up @@ -131,6 +132,7 @@ class webpeerjs{
this.#msgIdtracker = []
this.#peerexchangedata = new Map()
this.#lastTimeConnectToNetwork = new Date().getTime()
this.#lastTimeReceiveData = new Date().getTime()
this.#onConnectQueue = []

this.peers = (function(f) {
Expand Down Expand Up @@ -208,7 +210,7 @@ class webpeerjs{
const metadata = {addrs:address,last:now}
this.#connectedPeers.set(id,metadata)
}
else{
else if(this.#lastTimeReceiveData < 10*1000){
//add to connected webpeers
this.#onConnectFnUpdate(id)
const now = new Date().getTime()
Expand Down Expand Up @@ -239,6 +241,10 @@ class webpeerjs{

try{

if(topic === config.CONFIG_PUPSUB_PEER_DATA || config.CONFIG_PUBSUB_PEER_DISCOVERY_WEBPEER.includes(topic) || config.CONFIG_RUN_ON_TRANSIENT_CONNECTION){
this.#lastTimeReceiveData = new Date().getTime()
}

//track last connect to webpeer network
if(config.CONFIG_PUBSUB_PEER_DISCOVERY_WEBPEER.includes(topic)){
const now = new Date().getTime()
Expand All @@ -261,7 +267,7 @@ class webpeerjs{
const metadata = {addrs:address,last:now}
this.#connectedPeers.set(senderPeerId,metadata)
}
else{
else if(this.#lastTimeReceiveData < 10*1000){
//add to connected webpeers
this.#onConnectFnUpdate(senderPeerId)
const address = this.#webPeersAddrs.get(senderPeerId)
Expand Down Expand Up @@ -338,6 +344,8 @@ class webpeerjs{
//detect special webpeer identity
if(prefix === config.CONFIG_PREFIX){

this.#lastTimeReceiveData = new Date().getTime()

//add to webpeers id
if(!this.#webPeersId.includes(id))this.#webPeersId.push(id)

Expand Down

0 comments on commit e33beae

Please sign in to comment.