WebSocket Module

This XQuery Module contains functions for accessing specific WebSocket functions. This module is mainly useful in the context of WebSockets.

=Conventions=


 * The module will be available if the basex-api library is found in the classpath. This is the case if you use one of the complete distributions of BaseX (zip, exe, war).
 * All functions and errors are assigned to the  namespace, which is statically bound to the ws prefix.
 * As sessions are side-effecting operations, all functions are flagged as non-deterministic. As a result, some query optimizations will be suppressed.

=General Functions=

ws:close
=Sending Data=

ws:eval
=WebSocket Attributes=

ws:delete
=Examples=

Example 1
 import module namespace ws = "http://basex.org/modules/ws";

declare %ws:connect('/') function local:connect as empty-sequence { let $id := ws:id let $message := json:serialize(map {   'type': 'Connect',    'id': $id  }) return ws:broadcast($message) };

Explanation:


 * The function has a  annotation. It gets called if a client successfully creates a WebSocket connection to the path   (check out WebSockets for further information).
 * A JSON response is generated, which contains the new client id and a  string.
 * This response will be sent to all other connected clients.

Example 2
 import module namespace ws = "http://basex.org/modules/ws";

declare %ws:message('/', '{$message}') function local:message( $message as xs:string ) as empty-sequence { let $message := json:serialize(map { 'message': $message }) return ws:emit($message) };

Explanation:


 * The function has a  annotation. It gets called if a client sends a new message.
 * A JSON response is generated, which contains the message string.
 * This response will be sent to all connected clients (including the calling client).

=Errors=

=Changelog=


 * Version 9.2


 * Added: ws:eval

This module was introduced with Version 9.1.