p2pt
p2pt copied to clipboard
Unexpected behaviour when bundled by Vite (and likely WebPack and other bundlers)
I'm trying to use this library inside of a Vue project with Vite, however, peer connections get instantly closed in that setup. I also had to add @esbuild-plugins/node-globals-polyfill
and events
packages in order to get P2PT to work in Vite at all, so perhaps it could be related to that. If I include P2PT using a <script>
tag in the same setup it works without a problem.
I have created the following reproduction projects on Stackblitz:
If you open the import
project in 2 separate tabs, you will see something along these lines:
_peerId e3560c413ad577eac4067144ac915ad9ac84fc82
trackerconnect wss://tracker.btorrent.xyz
peerclose a7e07222c5299d33686b64a70e95494a49f181a8
As you can see, the peerclose
event is fired right after the tracker connection is established, where peerconnect
is expected instead.
If you open the script
project, where the only difference is the way P2PT is imported, you will see something along these lines:
_peerId 0e35820543c1491086ff837c80fc7f34aa9dec86
trackerconnect wss://tracker.btorrent.xyz
peerconnect 4bf610b001ff297abe9180a59379e30d462155da
I've also tried something similar on a WebPack project and had the same issue as with Vite, although I did not try to isolate it in a reproducible project. I suspect this issue might occur with other bundlers as well.