Skip to content

Commit

Permalink
Send peer info less often, fix double peers added to list
Browse files Browse the repository at this point in the history
  • Loading branch information
n9lsjr committed Dec 22, 2024
1 parent a85b780 commit 0ec1123
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/backend/swarm.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const send_voice_channel_status = async (joined, status, update = false) => {
const sig = await signMessage(msg, keychain.getXKRKeypair().privateSpendKey)
const data = JSON.stringify({
address: Hugin.address,
avatar: Hugin.avatar,
signature: sig,
message: msg,
voice: joined,
Expand Down Expand Up @@ -356,7 +357,10 @@ const check_data_message = async (data, connection, topic, peer) => {
con.video = joined.video
con.request = true
active.peers.push(peer.publicKey.toString('hex'))

let uniq = {}
const peers = active.peers.filter((obj) => !uniq[obj] && (uniq[obj] = true))
active.peers = peers
console.log("peers", peers)
const time = parseInt(joined.time)

//If our new connection is also in voice, check who was connected first to decide who creates the offer
Expand Down Expand Up @@ -701,9 +705,16 @@ const get_room_state = async (key) => {
const check_online_state = async (topic) => {
await sleep(10000)
let interval = setInterval(ping, 10 * 1000)
let a = 0
async function ping() {
const active = get_active_topic(topic)
const hashes = await getLatestRoomHashes(active.key)
let peers = []
//Send peer info on the first three pings. Then every 10 times.
if (a < 3 || a % 10 === 0) {
peers = active.peers
a++
}
//TODO ** change from hash list to hash state.
// const state = await get_room_state(active.key)
if (!active) {
Expand All @@ -712,7 +723,7 @@ const check_online_state = async (topic) => {
} else {
active.search = true
let i = 0
const data = {type: 'Ping', peers: active.peers}
const data = {type: 'Ping', peers}
console.log("send data", data)
for (const conn of active.connections) {
if (!conn.joined) continue
Expand Down

0 comments on commit 0ec1123

Please sign in to comment.