dmotz / trystero

✨🤝✨ Build instant multiplayer webapps, no server required — Magic WebRTC matchmaking over BitTorrent, Nostr, MQTT, IPFS, Supabase, and Firebase
https://oxism.com/trystero
MIT License
1.33k stars 92 forks source link

Connection Failure in joinRoom() at 'wss://tracker.files.fm:7073/announce'. #78

Closed chopin closed 4 months ago

chopin commented 4 months ago

Hi,

Thanks for sharing a wonderful library. I am trying to integrate Trystero for the first time, and I encountered connection failure in joinRoom(). Following is my code.

importing in html:

<script>
import {joinRoom} from './trystero/v0.19.0/trystero-torrent.min.js';
</script>

joinRoom() in Python (translated to javascript by Transcrypt):

configTrystero= {'appId':'testApp'}
room= joinRoom(configTrystero, 'test_room_x_0_y_0')

result: connection failure at 'wss://tracker.files.fm:7073/announce'.

trystero-torrent.min.js:1 WebSocket connection to 'wss://tracker.files.fm:7073/announce' failed: Error in connection establishment: net::ERR_CONNECTION_TIMED_OUT`

The code is so simple. What did I do wrong? Do I have to have a torrent id and register the appId in torrent?

chopin commented 4 months ago

I tested after switching to nostr, and encountered a similar error as following:

trystero-nostr.min.js:1 WebSocket connection to 'wss://relay.exit.pub/' failed: Error in connection establishment: net::ERR_CONNECTION_TIMED_OUT

Tested ipfs. Error:

trystero-ipfs.min.js:1 WebSocket connection to 'wss://node-01.ac-cn-hongkong-c.wakuv2.prod.status.im:8000/p2p/16Uiu2HAm4v86W3bmT1BiH6oSPzcsSr24iDQpSN5Qa992BCjjwgrD' failed: Error in connection establishment: net::ERR_NAME_NOT_RESOLVED

Tested mqtt. Error:

trystero-mqtt.min.js:1 WebSocket connection to 'wss://public.mqtthq.com:8084/mqtt' failed: Connection closed before receiving a handshake response
dmotz commented 4 months ago

Hey @chopin — those errors look concerning but are totally normal and expected. Since Trystero piggybacks on open public networks, it's inevitable some of them will occasionally go down or deny connections to certain users. For that reason, the library uses redundancy: connecting to multiple relays at once, but only requiring one to work to achieve peer connections. Redundancy has default values depending on which strategy you use, but you can also customize the number by setting relayRedundancy in the config passed to joinRoom().

It's not possible to catch socket connection errors in the browser, so you'll usually see failed relay connections in the console. Assuming other relays work, these errors shouldn't affect peer connection and your users won't see them unless they open the console. I might add a note to the docs explaining that these warnings are expected.

chopin commented 4 months ago

Thanks for your response. I checked that Trystero was working fine.

Coluld you please print such errors as warnings? Programmers are sensitive at any error message. I saw that the error messages repeated as time goes getting my attention. They bothers me because I have to look at all error messages for development.

There must be a way to catch websocket connection errors. There are a lot of web pages about it:

https://www.google.com/search?q=websocket+how+to+catch+connection+timeout+error

dmotz commented 4 months ago

Trystero doesn't throw those warnings, they're part of default browser behavior when connections fail and can't be suppressed with a catch statement (see this explanation for details). It's an annoyance but you can hide it by setting a console filter in the browser dev tools.