Jacek
Websocket topic publish doesn't work until you refresh the page
Judging by the API it is trying to facilitate P2P (user to user) communications. The only way server is getting it's messages injected is through
send
. So unless your notifications are meant to originate from specific user action, then publish
is not the correct method to use. In this model only the actual "peer-user" is allowed to broadcast while server needs to send each message individually. It is all implemented already in the demo and seems to work just fine.16 replies
Websocket topic publish doesn't work until you refresh the page
I am not sure why you insist on
.publish
over .send
. When user is posting in the chat he means to broadcast ("publish") a message. When your server notifies each connected user and holds reference to its connection (peer
variable in watch callback closure), then it makes sense to use "send" and push single message.16 replies
Websocket topic publish doesn't work until you refresh the page
I tried to upgrade to the latest Nuxt, but all it really changed is using GUID instead of regular numbers to identify members (i.e.
peer.toString()
produces GUID now). The behavior stays the same.16 replies
Websocket topic publish doesn't work until you refresh the page
It is a bit weird. Code looks OK at first glance and "something" works, but also not as we would intuitively expect.
I tested it a bit and I found the following:
- every time you refresh or open new tab (simulating additional chat member),
open()
calls .watch(...)
subscribing to the external event bus
- refreshing multiple times or adding more members result in sending duplicated messages
- but the "first" subscription does not really send.. function it is executed, but the browser get's nothing in the WS messages queue
BWT. It can get even worse. On one of the browsers I have refreshed couple times too fast, triggered some connection error and it cannot even get to open()
.. tried server restart, nuxt cleanup, full cache/storage reload and disabled cache.. this client is busted (whole browser had to be killed)16 replies
How to build an SPA + Nitro for server with Nuxt
Preset value is actually
node_server
(not node-server
) and you don't need to put it in the config as it is the default.
Build the project into a Docker container or configure your hosting to run server/index.mjs
and you should be good to go.
Also consider alternative runtimes - Bun if you want to handle more users or Deno for built-in security.4 replies
Nuxt dev server from code server
Apologies, I through the error is related to your own use of WebSockets.
In case of HMR.. it should be there already. Maybe devServer » https could help force Vite to realize it is loaded with with TLS and switch to
wss://
.20 replies