During the development process, on my localhost I used the ws:/ip:1234 and everything worked properly.
this.provider = new WebsocketProvider(
'ws:/xx.xxx.xxx.xxx:1234/',
'document.' + this.hash,
this.ydoc,
)
However, once I changed it to ws:/domain.com:1234 connection refused to be established. Same with wss:/domain.com:1234. The reason ws:/ip:1234 is not applicable for me is that my website is running on HTTPS and cannot establish ws:/ connections. This should be the case for many users.
I googled and came upon a solution that involved nginx configuration, however still was not able to implement it, due to the lack of knowledge in this field.
Posting it here, so that once the solution is found - everyone can benefit from it.
Ok, interesting. The nginx config looks good. What I would test next is that
(a) you can reach the site via regular HTTPS, and
(b) you can reach your websocket on the machine at http://localhost:1234.
For (b) you could try a basic connection using telnet (e.g. telnet localhost 1234 should say “Connected to localhost”, then press ctrl-C to leave). Or you could try a more sophisticated tool such as https://github.com/hashrocket/ws or https://github.com/vi/websocat.
It’s also possible there is some kind of firewall activity preventing nginx from talking to localhost:1234 (ufw?).
Excellent! It sounds like it’s a straightforward case of starting the process, or otherwise figuring out why you can’t connect locally. I hope you post back here to let us know if you figure it out
telnet localhost 1234
Trying 127.0.0.1...
Connected to localhost.
So I ended up fixing it, however the WebSocket connection still cannot be established. At this point I have no idea what can be the reason of such a behavior .
I have tried running both HOST=socket.wetype.net PORT=1234 npx y-websocket-server
and HOST=localhost PORT=1234 npx y-websocket-server
In the first case, I am able to create ws://ip:1234 (but not a domain itself or wss)
In the second one nothing works
Hmm, this is strange. I would expect the following:
If you run HOST=socket.wetype.net PORT=1234 npx y-websocket-server you should be able to access it externally, via ws://socket.wetype.net:1234. Something doesn’t add up here. Maybe try HOST=0.0.0.0 PORT=1234 npx y-websocket-server and see if that allows you to access it at ws://socket.wetype.net:1234? I feel like there could be a clue waiting for us here.
If you run HOST=localhost PORT=1234 npx y-websocket-server you should NOT be able to access it externally, via ws://ip:1234 nor via ws://socket.wetype.net:1234. It sounds like that is the case? If so, when you say “nothing works” do you mean that telnet localhost 1234 ALSO does not work? Because I would expect telnet on localhost to work.
telnet localhost 1234 doesn’t work in case I only do HOST=socket.wetype.net PORT=1234 npx y-websocket-server. In this case only ws:/ip:1234 works
When I run HOST=localhost PORT=1234 npx y-websocket-server nothing works except for telnet localhost 1234
When I ran HOST=0.0.0.0 PORT=1234 npx y-websocket-server both ws://ip:1234 and telnet localhost 1234 worked. However wss://socket.wetype.net:1234 and ws://socket.wetype.net:1234 still didn’t work.
Oh good!! I’m glad it finally worked for you. So to be clear, when you say “I ended up doing wss://socket.wetype.net without port” is this on the javascript side, when configuring your connection in the browser? e.g.
this.provider = new WebsocketProvider(
"wss://socket.wetype.net",
"room01",
ydoc
);