如何在 PeerJs peer.call(id, stream, [options]) 函数中设置元数据?

How do I set metadata in the PeerJs peer.call(id, stream, [options]) function?

我试图在对等连接中发送两个呼叫,我想通过 meta_data 区分它们,但是当我检查 meta_data 时我得到的是空值。如何在拨打电话时添加 meta_data? 这是我当前的代码。

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

这是文档 link peercall

存在语法问题。您需要执行此操作以使用流

发送元数据
let cameracall = peer.call(conn.peer, ourcamera, {
    metadata: { "type": "camera" }
});
let screencall = peer.call(conn.peer, ourscreen, {
    metadata: { "type": "help" }
});

然后在对端,你可以得到这样的元数据

peer.on("call", connection => {
  connection.answer();
  connection.on("stream", stream => {
    console.log(connection.metadata);
  });
});

为了在没有元数据的情况下以正常方式调用远程对等点,我们有:

peer.call(remotePeerId, ourLocalStream);

用于调用远程节点 + 将一些元数据附加到调用中:

options = {metadata: {"type":"screensharing"}};
peer.call(remotePeerId, ourLocalStream, options);

在远程对端,用于检查收到的呼叫中的元数据:

 peer.on('call', call => {
    console.log(call.metadata.type);
    call.answer();
    call.on('stream', stream => {
       // somthing to do
    });
 });

请注意其他可能没有为其定义任何元数据的调用,call.metadata.type 没有任何意义。