wasp icon indicating copy to clipboard operation
wasp copied to clipboard

Enable using the Websocket server inside of server-side code outside of the Websocket init function

Open infomiho opened this issue 1 year ago • 1 comments

Right now, the initialized server is not exposed or documented for the user to use.

For example, when somebody likes a post, it might trigger something and a notification is sent over the socket.

infomiho avatar Jun 24 '23 13:06 infomiho

Relevant Discord convo, we had user asking for this: https://discord.com/channels/686873244791210014/1208036265308586034/1208060190856056932 .

Martinsos avatar Feb 19 '24 15:02 Martinsos

@Martinsos Any update on this? What would be the best way to have the server send web socket events to update the client, on download status for example, outside of the webSocket fn? (Also the Discord link has expired and can't join discord :(( )

GavPierce avatar Mar 11 '24 22:03 GavPierce

@Martinsos Any update on this? What would be the best way to have the server send web socket events to update the client, on download status for example, outside of the webSocket fn? (Also the Discord link has expired and can't join discord :(( )

@infomiho knows the best about websockets in Wasp so will be able to provide some clarity!

This is our perma-invite, it works for me and should work well: https://discord.gg/rzdnErX !

Martinsos avatar Mar 12 '24 10:03 Martinsos

Small update here, for visibility:

The current work around is to:

  • Create a global function, that is initialized and defined in your webSocketFn
  • Export this global function (ie, ioInstance)
  • Import the ioInstance in other places in your backend server where you need access to the instance.

I believe they are working on making it more built in to the Wasp Experience :)

GavPierce avatar Mar 12 '24 12:03 GavPierce