0

我正在尝试使用简单对等方打开数据通道。我使用 Firebase 发送信号,并且能够启动 on connect 功能。

const [thisPeer, setThisPeer] = useState();
const [connectionStatus, setConnectionStatus] = useState(false);

// in a function
var thisPeerT = new Peer({
    initiator: false,
    config: {
        iceServers: iceServers,
    },
});

// signaling code

thisPeerT.on("connect", function (data) {
    console.log("onconnect");
    console.log(data);
    setConnectionStatus(true);
});

setThisPeer(thisPeerT);

在 on connect 中,我设置了一个状态挂钩来触发我创建 on 数据的使用效果。

useEffect(
    function () {
        console.log("here");
        console.log(roomID);
        console.log(thisPeer);
        console.log(connectionStatus);

        if (roomID && thisPeer && connectionStatus) {
            console.log("here2");
            thisPeer.on("data", function (data) {
                console.log(data);
            });
        }
    },
    [roomID, thisPeer, connectionStatus]
);

但是,当我尝试使用 thisPeer.on("data"...

here
XXYDCgqle4XvZDZ6gm6
Peer {_readableState: ReadableState, readable: true, _events: {…}, _eventsCount: 4, _maxListeners: undefined, …}
true
here2

Uncaught ReferenceError: process is not defined
at resume (_stream_readable.js:905:1)
at Peer.Readable.resume (_stream_readable.js:895:1)
at Peer.Readable.on (_stream_readable.js:813:1)
at ConnectionContext.js:142:1
at invokePassiveEffectCreate (react-dom.development.js:23487:1)
at HTMLUnknownElement.callCallback (react-dom.development.js:3945:1)
at Object.invokeGuardedCallbackDev (react-dom.development.js:3994:1)
at invokeGuardedCallback (react-dom.development.js:4056:1)
at flushPassiveEffectsImpl (react-dom.development.js:23574:1)
at unstable_runWithPriority (scheduler.development.js:468:1)

我尝试将 on 数据放置在整个代码中的各个位置,并且无论位置如何,似乎都会发生此错误。如果我在另一个对等方上调用 peer.send(),它还会在接收到数据的对等方上给出一个进程未定义错误。有谁知道我如何解决错误或我应该在哪里打开数据通道?

4

0 回答 0