Jacek
Jacek
NNuxt
Created by Jawa-the-Hutt on 2/6/2025 in #❓・help
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
NNuxt
Created by Jawa-the-Hutt on 2/6/2025 in #❓・help
Websocket topic publish doesn't work until you refresh the page
I guess .publish prevents echo-ing the message user types and posts in the chat room. If you adopt this perspective it is a feature, not a bug.
16 replies
NNuxt
Created by Jawa-the-Hutt on 2/6/2025 in #❓・help
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
NNuxt
Created by Jawa-the-Hutt on 2/6/2025 in #❓・help
Websocket topic publish doesn't work until you refresh the page
Replacing peer.publish with peer.send seems to fix the primary problem. You should also keep track of chat members and unsubscribe from .watch(...). Demo
16 replies
NNuxt
Created by Jawa-the-Hutt on 2/6/2025 in #❓・help
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
NNuxt
Created by Jawa-the-Hutt on 2/6/2025 in #❓・help
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
NNuxt
Created by Ilya Belov on 10/28/2024 in #❓・help
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
NNuxt
Created by Imran on 10/14/2024 in #❓・help
Nuxt dev server from code server
It might be the same. Have you tried suggestion from #16377 yet?
20 replies
NNuxt
Created by Imran on 10/14/2024 in #❓・help
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
NNuxt
Created by Imran on 10/14/2024 in #❓・help
Nuxt dev server from code server
Examples showing WS usage usually include protocol adjustment
const isSecure = location.protocol === "https:";
const url = (isSecure ? "wss://" : "ws://") + location.host + "/_ws";
const isSecure = location.protocol === "https:";
const url = (isSecure ? "wss://" : "ws://") + location.host + "/_ws";
let me know if it helps 🙂
20 replies
NNuxt
Created by Quei on 10/14/2024 in #❓・help
Reusable websocket component
Because you won't open ws connection straight to client browser - he does not have any URL to point to.
49 replies
NNuxt
Created by Quei on 10/14/2024 in #❓・help
Reusable websocket component
Is the browser involved in it? or is it service-to-service?
49 replies
NNuxt
Created by Quei on 10/14/2024 in #❓・help
Reusable websocket component
Oh.. I may have misunderstood the whole idea. You want to send from client to backend, not the other way around.
49 replies
NNuxt
Created by Quei on 10/14/2024 in #❓・help
Reusable websocket component
If I read it correctly... anytime you open a new connection you close previous one. So you actually support single user for the whole backend instance. Is it meant to run on edge and spin up worker for every user?
49 replies
NNuxt
Created by Quei on 10/14/2024 in #❓・help
Reusable websocket component
It refers to nuxtServerInit from Nuxt 2. Regardless, if you decide to use some "magic" global, beware it won't scale. You can only broadcast to people connected to specific backend instance.
49 replies
NNuxt
Created by Quei on 10/14/2024 in #❓・help
Reusable websocket component
If I read the page correctly, socket lives on the client, so emit just sends message from the browser to the server. I am curious if you can figure out how to utilize it on the backend.
49 replies
NNuxt
Created by Quei on 10/14/2024 in #❓・help
Reusable websocket component
If you can use it to replace unstorage from the last demo on Stackblitz, I would gladly fork it for later 😉
49 replies
NNuxt
Created by Quei on 10/14/2024 in #❓・help
Reusable websocket component
If you think socket.io has dedicated methods that would make your source code more clearly state the intent (readable, maintainable), then I see no reason to seek other solutions 🙂
49 replies
NNuxt
Created by Quei on 10/14/2024 in #❓・help
Reusable websocket component
The only problem is that it is not a solution that clearly speaks "I am dedicated for chat app".
49 replies
NNuxt
Created by Quei on 10/14/2024 in #❓・help
Reusable websocket component
So you said you worry about .clear() before .set(). I wouldn't. It means you use storage as signal bus. It does not matter if it contains an item or not.
49 replies