Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

308
Views
PeerJs peer.connections deprecated

I am trying to get all peers that are currently connected to me, but it says connections is deprecated.

const peer = new Peer('my_id');
const connections = peer.connections;

Documentation says: We recommend keeping track of connections yourself rather than relying on this hash.

Let's say I keep track of all peers id in array. How should I handle the ids so that I get the same result as with peer.connections ?

Example: peer.connections returns: peer.connections console.log

What method do I need to call to get the same results from peer id in my array?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think you should create a listener when a connection is established. You may achieve this by implementing a wrapper that will unify client usage of peer js

class MyPeer {
  constructor() {
    this.instance = new Peer()
  }

  async connect() {
    return new Promise(resolve => {
      this.connection = peer.connect(new Date().getTime()) // create a unique id for each connection

      this.connection.on('open', () => resolve(this.connection))
    })
  }
}

Assuming you are taking this (very naïve, without proper error handling) implementation, you may keep track of connections like this

const peer = new MyPeer()
   
const connection = await peer.connect()
myConnectionsArray.push(connection)

It worth mentioning that you may remove connections from array when a connection is closed and probably wrap everything in a class (say ConnectionsManagaer or something similar). Besides that, it should satisfy your request

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!