Emmanuel Selase
Emmanuel Selase

Reputation: 1

Uncaught TypeError: Cannot read properties of undefined (reading 'call')

I was following a tutorial by JavaScript Mastery on YouTube on create a video chat app with React. The person used Create React App but I'm using Vite. Every other part has been working except for when im making a call. This is what I get in the browser's console:

Uncaught TypeError: Cannot read properties of undefined (reading 'call')
    at _Peer.Readable (simple-peer.js?v=4d304747:4300:14)
    at new Duplex (simple-peer.js?v=4d304747:3569:16)
    at new _Peer (simple-peer.js?v=4d304747:5309:9)
    at callUser (Context.jsx:61:18)
    at onClick (Options.jsx:45:32)
    at HTMLUnknownElement.callCallback2 (chunk-3GS3N7PG.js?v=5de4bc54:3674:22)
    at Object.invokeGuardedCallbackDev (chunk-3GS3N7PG.js?v=5de4bc54:3699:24)
    at invokeGuardedCallback (chunk-3GS3N7PG.js?v=5de4bc54:3733:39)
    at invokeGuardedCallbackAndCatchFirstError (chunk-3GS3N7PG.js?v=5de4bc54:3736:33)
    at executeDispatch (chunk-3GS3N7PG.js?v=5de4bc54:7016:11) 

The error comes about when I'm trying to create a new Peer object with simple-peer. This is the function to call a user:

 const callUser = (id) => {
    console.log('calling....')
    const peer = new Peer({ initiator: true, trickle: false, stream })
    console.log(peer)

    peer.on('signal', (data) => {
      socket.emit('callUser', { userToCall: id, signalData: data, from: me, name });
    });

    peer.on('stream', (currentStream) => {
      userVideo.current.srcObject = currentStream;
    });

    socket.on('callAccepted', (signal) => {
      setCallAccepted(true);

      peer.signal(signal);
    });

    connectionRef.current = peer;
  }

I checked several forums but did not find any problem related to mine and the one I found recommended me to download vite-plugin-node-polyfills. It did not fix the problem but rather created a new problem.

Upvotes: 0

Views: 161

Answers (0)

Related Questions