Question

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!

Was it helpful?

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;
});

OTHER TIPS

Use call.peer

USAGE:

//peer1
const peer = new Peer('1')

peer.call('2', stream)
//peer2
const peer = new Peer('2')

peer.on('call', (call)=> {
console.log(call.peer)
})

Above code will Log '1'

you can use
div.innerHTML=call.peer
this shows the id of peer which trying to make you a connection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top