Sir, when basex 9.1, please ;-)
Thursday, 18 October 2018 · 6 messages · last reply 24 Oct 2018
MG
Maximilian Gärber18 Oct 2018 18:04 #
CG
Christian Grün18 Oct 2018 18:33 #
Sir, doing our best ;)
We believe that BaseX 9.1 pretty soon (until end of October).
For everyone who is interested in giving us some feedback on the new WebSocket feature… Thank you in advance! 90% of the documentation is finalized:
http://docs.basex.org/wiki/WebSockets
Best,
Christian
ML
Marco Lettere22 Oct 2018 13:21 #
Hi,
I'm just hijacking Maximilian's email here to post the following test I wanted to do for experimenting with BaseX and Websockets.
I wrote the code at [1] with the intent to open a RESTXQ entrypoint that receives a JSON via POST and the broadcastst it to all connecte WS clients. I might be using
ws:broadcast or the naive version as shown but still I get the following error [2] as return to my HTTP POST and, ca va sans dire, nothing on the websocket.
What am I doing wrong?
BTW, even if not stated in the path annotation, an extra /ws needs to be prefixed to the url used for JS' WebSocket constructor. Personally I'd prefer to keep things explicit and put it in the annotation too.
Thanks for your support and thanks Maximilian for the lift.
[1]
module namespace dp = 'urn:nubisware:datarouter';
import module namespace ws = 'http://basex.org/modules/ws';
declare
%rest:path('/dataprovider')
%rest:POST("{$data}")
%output:method('json')
function dp:route($data as node()) {
ws:send(json:serialize($data), ws:ids()[. != ws:id()])
};
declare
%ws:connect('/dataprovider')
function dp:connect() as empty-sequence() {
()
};
declare
%ws:close('/dataprovider')
function dp:close() as empty-sequence() {
()
};
[2]
Stopped at /home/lettere/tmp/basex/webapp/dataprovider/dataprovider.xqm, 11/53:
[basex:ws] WebSocket connection required.Quoted text · Christian Grün · 13 lines
On 18/10/18 18:33, Christian Grün wrote: > Sir, doing our best ;) > > We believe that BaseX 9.1 pretty soon (until end of October). > > For everyone who is interested in giving us some feedback on the new > WebSocket feature… Thank you in advance! 90% of the documentation is > finalized: > > http://docs.basex.org/wiki/WebSockets > > Best, > Christian
CG
Christian Grün22 Oct 2018 13:36 #
Hi Marco,
I’m glad to you are gathering some experience with the WebSocket facility.
Quoted text · Marco Lettere · 2 lines
> I get the following error [2] as return to my HTTP POST and, ca va sans > dire, nothing on the websocket.
The function bound to the "/dataprovider" is a simple RESTXQ function. As such, it isn’t attached to a WebSocket id. One of the reasons is that a client who’s using RESTXQ may not necessarily have a WebSocket connection, or there can also be multiple WebSockets per client.
If you want to send your result to all WebSockets – including the client that called the dataprovider – you can simply use
ws:emit(). If your use case is complex enough to have a WebSocket connection and simultaneous RESTXQ requests in a single browser tab, you could store the WebSocket id(s) of your client as HTTP Session attribute, and access these ids from the RESTXQ code.Quoted text · Marco Lettere · 3 lines
> BTW, even if not stated in the path annotation, an extra /ws needs to be > prefixed to the url used for JS' WebSocket constructor. Personally I'd > prefer to keep things explicit and put it in the annotation too.
I have just revised our documentation, and I hope it’s fairly complete now. In the Annotations Section, you will find a hint to the "ws/" path.
The reason why the path is omitted in XQuery is that the web server takes care of the path resolution. If the default path is changed in the web.xml file, it would need to be changed in all XQuery
applications as well. The same applies to RESTXQ: If a prefix is used in the configuration, there won’t be a need to change your path annotations.
Hope this helps,
Christian
[1] http://docs.basex.org/wiki/WebSockets
Quoted text · Marco Lettere · 48 lines
> > Thanks for your support and thanks Maximilian for the lift. > > [1] > module namespace dp = 'urn:nubisware:datarouter'; > > import module namespace ws = 'http://basex.org/modules/ws'; > > declare > %rest:path('/dataprovider') > %rest:POST("{$data}") > %output:method('json') > function dp:route($data as node()) { > ws:send(json:serialize($data), ws:ids()[. != ws:id()]) > }; > > declare > %ws:connect('/dataprovider') > function dp:connect() as empty-sequence() { > () > }; > > declare > %ws:close('/dataprovider') > function dp:close() as empty-sequence() { > () > }; > > [2] > Stopped at /home/lettere/tmp/basex/webapp/dataprovider/dataprovider.xqm, > 11/53: > [basex:ws] WebSocket connection required. > > On 18/10/18 18:33, Christian Grün wrote: > > Sir, doing our best ;) > > > > We believe that BaseX 9.1 pretty soon (until end of October). > > > > For everyone who is interested in giving us some feedback on the new > > WebSocket feature… Thank you in advance! 90% of the documentation is > > finalized: > > > > http://docs.basex.org/wiki/WebSockets > > > > Best, > > Christian > >
ML
Marco Lettere23 Oct 2018 18:14 #
Yes Christian,
it works with
ws:emit() and I also understand the point now. This embedded support for websockets allows us to reduce our code base in some use cases by several hundreds lines of code.
Not speaking about dependency management and configuration tricks to be documented.
Great job!
M.Quoted text · Christian Grün · 85 lines
On 22/10/18 13:36, Christian Grün wrote: > Hi Marco, > > I’m glad to you are gathering some experience with the WebSocket facility. > >> I get the following error [2] as return to my HTTP POST and, ca va sans >> dire, nothing on the websocket. > The function bound to the "/dataprovider" is a simple RESTXQ function. > As such, it isn’t attached to a WebSocket id. One of the reasons is > that a client who’s using RESTXQ may not necessarily have a WebSocket > connection, or there can also be multiple WebSockets per client. > > If you want to send your result to all WebSockets – including the > client that called the dataprovider – you can simply use ws:emit(). If > your use case is complex enough to have a WebSocket connection and > simultaneous RESTXQ requests in a single browser tab, you could store > the WebSocket id(s) of your client as HTTP Session attribute, and > access these ids from the RESTXQ code. > >> BTW, even if not stated in the path annotation, an extra /ws needs to be >> prefixed to the url used for JS' WebSocket constructor. Personally I'd >> prefer to keep things explicit and put it in the annotation too. > I have just revised our documentation, and I hope it’s fairly complete > now. In the Annotations Section, you will find a hint to the "ws/" > path. > > The reason why the path is omitted in XQuery is that the web server > takes care of the path resolution. If the default path is changed in > the web.xml file, it would need to be changed in all XQuery > applications as well. The same applies to RESTXQ: If a prefix is used > in the configuration, there won’t be a need to change your path > annotations. > > Hope this helps, > Christian > > [1] http://docs.basex.org/wiki/WebSockets > > >> Thanks for your support and thanks Maximilian for the lift. >> >> [1] >> module namespace dp = 'urn:nubisware:datarouter'; >> >> import module namespace ws = 'http://basex.org/modules/ws'; >> >> declare >> %rest:path('/dataprovider') >> %rest:POST("{$data}") >> %output:method('json') >> function dp:route($data as node()) { >> ws:send(json:serialize($data), ws:ids()[. != ws:id()]) >> }; >> >> declare >> %ws:connect('/dataprovider') >> function dp:connect() as empty-sequence() { >> () >> }; >> >> declare >> %ws:close('/dataprovider') >> function dp:close() as empty-sequence() { >> () >> }; >> >> [2] >> Stopped at /home/lettere/tmp/basex/webapp/dataprovider/dataprovider.xqm, >> 11/53: >> [basex:ws] WebSocket connection required. >> >> On 18/10/18 18:33, Christian Grün wrote: >>> Sir, doing our best ;) >>> >>> We believe that BaseX 9.1 pretty soon (until end of October). >>> >>> For everyone who is interested in giving us some feedback on the new >>> WebSocket feature… Thank you in advance! 90% of the documentation is >>> finalized: >>> >>> http://docs.basex.org/wiki/WebSockets >>> >>> Best, >>> Christian >>
CG
Christian Grün24 Oct 2018 16:43 #
I’m glad to hear this!
And thanks again for co-sponsoring this feature.
People like you help us to keep BaseX alive and lively.
Quoted text · Marco Lettere · 10 lines
On Tue, Oct 23, 2018 at 6:14 PM Marco Lettere <m.lettere at gmail.com> wrote: > > Yes Christian, > it works with ws:emit() and I also understand the point now. > This embedded support for websockets allows us to reduce our code base > in some use cases by several hundreds lines of code. > Not speaking about dependency management and configuration tricks to be > documented. > Great job! > M.
Written for BaseX 9.0. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery