Skip to content

Commit

Permalink
++
Browse files Browse the repository at this point in the history
  • Loading branch information
prevetal committed Oct 16, 2024
1 parent 8d8f283 commit 090a775
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions js/jetPack.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
// Main JetPack class definition
class JetPack {
// Private params
#userId = ''
// #userId = '808958531'
// #userId = ''
#userId = '808958531'
#peer = null
#peerID = null
#conn = null
Expand Down Expand Up @@ -57,6 +57,8 @@
// Set data
if (userParams) {
this.#userId = userParams.id

document.getElementById('ddd').innerText = this.#userId
}
}
}
Expand Down Expand Up @@ -116,6 +118,7 @@

// Create connection to jetWallet
const intervalId = setInterval(() => {
// Save connection
this.#conn = this.#peer.connect(`jw-${BOT_ID}-${this.#userId}`)

// Successful connection
Expand All @@ -129,24 +132,19 @@

// Processing data receipt
this.#conn.on('data', data => {
try {
// Check the type of received data
if (data.type === 'address') {
// Save data
this.#jwAddress = data.address

// Resolve the promise with true
resolve(true)
} else if (data.type === 'error') {
// Reject promise
reject(`Error received: ${data.message}`)
} else {
// Reject promise
reject('Unknown data type received.')
}
} catch (error) {
// Check the type of received data
if (data.type === 'address') {
// Save data
this.#jwAddress = data.address

// Resolve the promise with true
resolve(true)
} else if (data.type === 'error') {
// Reject promise
reject(`Error received: ${data.message}`)
} else {
// Reject promise
reject('Failed to parse incoming data.')
reject('Unknown data type received.')
}
})

Expand Down

0 comments on commit 090a775

Please sign in to comment.