Search code examples
javascriptwebrtcpeerjs

PeerJS prompt with name of caller?


Background info to issue : I am using PeerJS and I have a div I am show on the call event which serves as a modal for accepting or declining a call.

Question : Is there a way that I can send a username along with the call request (aside from the ID of the peer, I am using UUID's for that) so that I can have the div say "Username" is calling?

Thankyou in advance!


Solution

  • In the PeerJS documentation it says that you can attach metadata to a peer.connect call, like this:

    var conn = peer.connect(peerID, { metadata: { userName: 'name goes here' } });
    

    Then you can access the metadata like this:

    peer.on('connection', function(conn) {
        var userName = conn.metadata.userName;
    });