Errors when using with @libp2p/webrtc-star
julienmalard opened this issue · 2 comments
I'm trying to use this library with @libp2p/webrtc-star. When running on electron-main, everything works until a webrtc connection comes in, at which point I get the following error:
Uncaught TypeError: this.peerConnection.addEventListener is not a function
at new WebRTCHandshake (file:///Users/julienmalard/atom/constl/ipa/node_modules/.pnpm/@libp2p+webrtc-peer@2.0.2/node_modules/@libp2p/webrtc-peer/dist/src/handshake.js:10:29)
at new WebRTCReceiverHandshake (file:///Users/julienmalard/atom/constl/ipa/node_modules/.pnpm/@libp2p+webrtc-peer@2.0.2/node_modules/@libp2p/webrtc-peer/dist/src/receiver.js:33:9)
at new WebRTCReceiver (file:///Users/julienmalard/atom/constl/ipa/node_modules/.pnpm/@libp2p+webrtc-peer@2.0.2/node_modules/@libp2p/webrtc-peer/dist/src/receiver.js:12:26)
at SigServer._createChannel (file:///Users/julienmalard/atom/constl/ipa/node_modules/.pnpm/@libp2p+webrtc-star@6.0.0/node_modules/@libp2p/webrtc-star/dist/src/listener.js:69:25)
at SigServer.handleWsHandshake (file:///Users/julienmalard/atom/constl/ipa/node_modules/.pnpm/@libp2p+webrtc-star@6.0.0/node_modules/@libp2p/webrtc-star/dist/src/listener.js:148:28)
at Emitter.emit (/Users/julienmalard/atom/constl/ipa/node_modules/.pnpm/@socket.io+component-emitter@3.1.0/node_modules/@socket.io/component-emitter/index.js:143:20)
at Socket.emitEvent (file:///Users/julienmalard/atom/constl/ipa/node_modules/.pnpm/socket.io-client@4.5.4/node_modules/socket.io-client/build/esm-debug/socket.js:379:20)
at Socket.onevent (file:///Users/julienmalard/atom/constl/ipa/node_modules/.pnpm/socket.io-client@4.5.4/node_modules/socket.io-client/build/esm-debug/socket.js:366:18)
at Socket.onpacket (file:///Users/julienmalard/atom/constl/ipa/node_modules/.pnpm/socket.io-client@4.5.4/node_modules/socket.io-client/build/esm-debug/socket.js:334:22)
at Emitter.emit (/Users/julienmalard/atom/constl/ipa/node_modules/.pnpm/@socket.io+component-emitter@3.1.0/node_modules/@socket.io/component-emitter/index.js:143:20)
at file:///Users/julienmalard/atom/constl/ipa/node_modules/.pnpm/socket.io-client@4.5.4/node_modules/socket.io-client/build/esm-debug/manager.js:215:18
at process.processTicksAndRejections (node:internal/process/task_queues:81:21)
On Node, things fail at the init() stage:
TypeError: Cannot read properties of undefined (reading 'on')
at ResourceManager.registerListener (node_modules/.pnpm/@ca9io+electron-webrtc-relay@0.2.0/node_modules/@ca9io/electron-webrtc-relay/lib/ResourceManager.js:70:28)
at new ResourceManager (node_modules/.pnpm/@ca9io+electron-webrtc-relay@0.2.0/node_modules/@ca9io/electron-webrtc-relay/lib/ResourceManager.js:21:14)
at Bridge.init (node_modules/.pnpm/@ca9io+electron-webrtc-relay@0.2.0/node_modules/@ca9io/electron-webrtc-relay/lib/ElectronBridge.js:33:32)
at file:///Users/julienmalard/atom/constl/ipa/dist/src/sfip/config%C3%89lectronPrincipal.js:9:6
at ModuleJob.run (node:internal/modules/esm/module_job:185:25)
at async Promise.all (index 0)
at ESMLoader.import (node:internal/modules/esm/loader:281:24)
at obtConfigPlateforme (file:///Users/julienmalard/atom/constl/ipa/src/sfip/index.ts:16:25)
at initSFIP (file:///Users/julienmalard/atom/constl/ipa/src/sfip/index.ts:39:28)
at Context.<anonymous> (file:///Users/julienmalard/atom/constl/ipa/test/sfip.spec.ts:9:12)
Do you have any idea what I am doing wrong? The original wrtc
package works on Node but abruptly crashes on electron-main.
Thanks!
This package should be a drop in replacement to relay the wrtc interface from the electron frontend to the backend, replacing the outdated wrtc node version (which is also not available for m1 mac, or not working very well at least)
If you do not use electron, this wont work (node case, probably). It does not provide an electron version bundled with it (and set up as relay), you have to provide your own. It is meant for electron applications really. The original problem I had with the electron-webrtc package are the awefully outdated dependencies.
as for the first problem, I do not know the @libp2p/webrtc-star package. If it supports the standard wrtc interface things should work, this package is just the browser wrtc implementation basically.
Let me know in case you solved the problem or need further help 👍🏻
Thanks for the detailed response! Regarding node, I think you are right. For electron-main, @libp2p/webrtc-star does support the standard wrtc package.
Here's the code I used to initialise it:
import { webRTCStar } from "@libp2p/webrtc-star";
const wrtc = webRTC();
wrtc.init();
const webrtc = webRTCStar({
wrtc
});
I added a debugging line to the handshake.js file in the traceback, and see that this.peerConnection is an RTCPeerConnection instance, but that RTCPeerConnection.addEventListener is not defined while RTCPeerConnection.addListener is. Could this be because RTCPeerConnection is an instance of EventEmitter (https://github.com/CA9io/electron-wrtc-relay/blob/main/src/wrtc/RTCPeerConnection.ts#L13), while the WebRTC spec has it as an instance of EventTarger (https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection)?
Thanks!