Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

167
Vistas
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?

7 months ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

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

7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos