Dynamic path segment for websockets

Friday, 23 June 2023 · 5 messages · last reply 28 Jun 2023
ML
Marco Lettere23 Jun 2023 11:21 #
Dear all, so I just found out that it is not possible to create websockets bound to dynamic paths. If I try a websocket connection to
declare
   %ws:connect('/notification/subject/{$subject}')
function log:subject() {};
I get an error (without significant logs). Whereas declare %ws:connect('/notification/subject/one') function log:subject() {}; works well. Does this have a motivation? Is there another way of meeting the requirement of having dynamic websocket channels? Thanks in advance, Marco.
CG
Christian Grün23 Jun 2023 16:46 #
Hi Marco, As most web applications open only one or a few websockets at the same time, we decided against supporting wildcards. Feel free to share background information on your use case with us, maybe you can convince us to get active ;·) Ciao, Christian
Quoted text · Marco Lettere · 28 lines
On Fri, Jun 23, 2023 at 11:21 AM Marco Lettere <m.lettere at gmail.com> wrote: > > Dear all, > > so I just found out that it is not possible to create websockets bound > to dynamic paths. > > If I try a websocket connection to > > declare > %ws:connect('/notification/subject/{$subject}') > function log:subject() {}; > > I get an error (without significant logs). Whereas > > declare > %ws:connect('/notification/subject/one') > function log:subject() {}; > > works well. > > Does this have a motivation? Is there another way of meeting the > requirement of having dynamic websocket channels? > > Thanks in advance, > > Marco. >
ML
Marco Lettere23 Jun 2023 17:42 #
I'll try to explain my use-case. I have a system that acts remotely. Jobs are requested from a GUI and the logs produced by the jobs have to be streamed back to the GUI via websocket after being treated by a service of mine developed as a RestXQ in BaseX10. In the current solution all the GUIs connect to the same websocket URL. Sending something to that websocket makes everything available to everyone and it's up to the javascript code to filter out what is of interest for the user. Instead it would be nice to have isolated channels end-to-end for instance by using the id of the logged user. Does this make enough sense? Danke schön Christian. M.
Quoted text · Christian Grün · 40 lines
On 23/06/23 16:46, Christian Grün wrote: > Hi Marco, > > As most web applications open only one or a few websockets at the same > time, we decided against supporting wildcards. > > Feel free to share background information on your use case with us, > maybe you can convince us to get active ;·) > > Ciao, > Christian > > > On Fri, Jun 23, 2023 at 11:21 AM Marco Lettere <m.lettere at gmail.com> wrote: >> Dear all, >> >> so I just found out that it is not possible to create websockets bound >> to dynamic paths. >> >> If I try a websocket connection to >> >> declare >> %ws:connect('/notification/subject/{$subject}') >> function log:subject() {}; >> >> I get an error (without significant logs). Whereas >> >> declare >> %ws:connect('/notification/subject/one') >> function log:subject() {}; >> >> works well. >> >> Does this have a motivation? Is there another way of meeting the >> requirement of having dynamic websocket channels? >> >> Thanks in advance, >> >> Marco. >>
ML
Marco Letterein reply to Christian Grün, 23 Jun 2023, 16:4626 Jun 2023 10:54 #
Dear Christian, we are currently thinking of a solution based on adding attributes to the websocket with the dedicated function. Then filtering out the right websocket to send a message to based on the attribute value. as a prerequisite it has to be possible to pass query-parameters to the ws:connect endpoint url? From the JS point of view "ws://myserver.com/path?param=1" is a valid ws url. Is the server side code able to handle this? Thanks a lot, Marco.
Quoted text · Christian Grün · 40 lines
On 23/06/23 16:46, Christian Grün wrote: > Hi Marco, > > As most web applications open only one or a few websockets at the same > time, we decided against supporting wildcards. > > Feel free to share background information on your use case with us, > maybe you can convince us to get active ;·) > > Ciao, > Christian > > > On Fri, Jun 23, 2023 at 11:21 AM Marco Lettere <m.lettere at gmail.com> wrote: >> Dear all, >> >> so I just found out that it is not possible to create websockets bound >> to dynamic paths. >> >> If I try a websocket connection to >> >> declare >> %ws:connect('/notification/subject/{$subject}') >> function log:subject() {}; >> >> I get an error (without significant logs). Whereas >> >> declare >> %ws:connect('/notification/subject/one') >> function log:subject() {}; >> >> works well. >> >> Does this have a motivation? Is there another way of meeting the >> requirement of having dynamic websocket channels? >> >> Thanks in advance, >> >> Marco. >>
CG
Christian Grünin reply to Marco Lettere, 23 Jun 2023, 17:4228 Jun 2023 11:47 #
Hi Marco,
Quoted text · Marco Lettere · 2 lines
> Instead it would be nice to have isolated channels end-to-end for > instance by using the id of the logged user.
I’ll give you some hints to the existing architecture, maybe that’s helpful: • If you create a new websocket connection, a unique ID is created. • With ws:id, you get your own ID, i.e., the ID of the client that created the current connection [1]. • You can use ws:send($message, ws:id()) to send a message to exactly this client. • With ws:set, you can store additional user properties, such as e.g. session data, which you can access later on. I assume you already had a look at our chat application [2]. It allows you to send requests to all users or only specific users. The 'specific user' could also be yourself. Feel free to ask if not self-explanatory (I remember it contains a lot of clever code in just a few lines…). [1] https://docs.basex.org/wiki/WebSocket_Module#ws%3Aid [2] https://github.com/BaseXdb/basex/tree/main/basex-api/src/main/webapp/chat

⚡Generated with XQuery