Reputation: 794
I am trying to send two calls in a peer connection and I want to differentiate them through meta_data but I get null when I check meta_data. How can I add meta_data on making calls? This my current code.
let cameracall = peer.call(conn.peer,ourcamera,{
meta_data:JSON.stringify({ "type":"camera" })
});
let screencall = peer.call(conn.peer,ourscreen,{
meta_data:JSON.stringify({"type":"help"})
});
Here is a link to the documentation peercall
Upvotes: 2
Views: 1539
Reputation: 11
peer.on('call', call => {
call.answer(localStream);
call.on('stream', remoteStream => {
console.log(call.metadata.type)
});
});
peer.call(peerId, localStream,
{
metadata: {
"type": "help"
}
}
);
You can get the metadata inside on call.
Upvotes: 1
Reputation: 1210
for calling a remote peer in normal way without metadata we have:
peer.call(remotePeerId, ourLocalStream);
for calling a remote peer + attaching some metadata to the call:
options = {metadata: {"type":"screensharing"}};
peer.call(remotePeerId, ourLocalStream, options);
on remote peer side, for checking metadata in received call:
peer.on('call', call => {
console.log(call.metadata.type);
call.answer();
call.on('stream', stream => {
// somthing to do
});
});
please note for other calls that maybe does not have any metadata defined for them, call.metadata.type
does not make any sense.
Upvotes: 5
Reputation: 3658
There is a syntax issue. You need to do this for sending metadata with a stream
let cameracall = peer.call(conn.peer, ourcamera, {
metadata: { "type": "camera" }
});
let screencall = peer.call(conn.peer, ourscreen, {
metadata: { "type": "help" }
});
And then at the peer end, you can get metadata like this
peer.on("call", connection => {
connection.answer();
connection.on("stream", stream => {
console.log(connection.metadata);
});
});
Upvotes: 0