Search code examples
node.jswebrtcpeerjs

How is a PeerJS id generated?


How is a PeerJS id generated? Since the Id is new for each session, can we store a generated Id in the database and use it for further connections with the person? Is it possible to set our own Id for video call? I am trying to implement a basic WebRTC video call application but dont want a new Id to be generated each time.


Solution

  • First if you don't provide a Id es randomly generated, Second yes you can store and use for further connections but i don't recommend (answer 3), Third Yes it's possible set your own Id for a video call, audio call or just messages, and that is the reason i don't recommend use the one that peerjs generated, this is how you can set your own id:

    var peer = new Peer([id], [options]);
    

    The '[id]' is where you pass your own id.

    Peerjs recommend don't use the id to identify the peers, you're recommended to set the metadata option to send other identifying information.

    For more info about that https://peerjs.com/docs.html#peerconnect-options