Re: [basex-talk] Dynamic path segment for websockets
Hi Marco, > 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
Re: [basex-talk] Dynamic path segment for websockets
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. 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 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.
Re: [basex-talk] Dynamic path segment for websockets
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. 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 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.
Re: [basex-talk] Dynamic path segment for websockets
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 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. >