nuxt-directus icon indicating copy to clipboard operation
nuxt-directus copied to clipboard

useDirectusRealtime cannot establish connection to the Websocket

Open Lucas-Gruber opened this issue 1 year ago • 2 comments

Version

nuxt-directus-next v0.0.15 nuxt: v3.12.2

Reproduction Link

https://github.com/Lucas-Gruber/nuxt-directus-reproduction-websocket

Steps to reproduce

  1. Install the packages (yarn install)
  2. Set the Directus link in nuxt.config.ts
  3. Start the dev-server with yarn dev
  4. Look in the browser-console

What is Expected?

The socket should connect and print this in console.

What is actually happening?

An error appears and the connection cannot be established.

Error:

t.globals.WebSocket is not a constructor

at new Promise ()
at connect (https://raw.githubusercontent.com/directus/directus/v10.10.5/sdk/src/realtime/composable.ts:231:28)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async setup (./app.js:15:84)

Lucas-Gruber avatar Jun 21 '24 12:06 Lucas-Gruber

Sorry @Lucas-Gruber for not reaching out earlier, had a busy week.

Yes, indeed it is an SSR related issue (the composable tries to establish a connection while still server-side). I got the fix mostly drafted but I need to investigate if I'm able to hook the id generation from the sdk ws composable (to prevent from sending queued messages and new messages with same ids)

sandros94 avatar Jun 28 '24 09:06 sandros94

No problem! And thank you for your work on this issue!

Lucas-Gruber avatar Jun 28 '24 16:06 Lucas-Gruber

Are there any news on this?

Lucas-Gruber avatar Aug 15 '24 19:08 Lucas-Gruber

Are there any news on this?

Yes, but unfortunately they do require a custom implementation that could easily break with future SDK updates. On this subject I do plan to write a comment in #215 in the upcoming days/week to get some feedback on future plans I have.

Sorry for the delay, but I've also taken a few weeks off from basically everything (actually I'm still on holidays)

sandros94 avatar Aug 17 '24 17:08 sandros94

--> https://github.com/Intevel/nuxt-directus/discussions/271

nuxt-directus-next is EOL

casualmatt avatar Aug 20 '24 15:08 casualmatt