Jump to navigation Jump to search
1,531 bytes added ,  09:17, 10 August 2018
no edit summary
This [[Module Library|XQuery Module]] contains functions for accessing specific WebSocket functions and setting attributes on a WebSocket connection. This module is mainly useful in the context of [[WebSockets]].Within the WebSocket module you can access functions in the context of the specific client. You can access the clientid, the clientpath and broadcast a message to all connected clients without the caller/client. If you have to access functions with more rights, like getting the clientids of other connected clients, you should checkout the [[WebSockets Module]]
* All functions and errors are assigned to the <code><nowiki></nowiki></code> namespace. The module must be imported in the query prolog:
<pre class="brush:xquery">
import module namespace websocket = "";
=Usage Tips=
* <code>websocket:id</code> returns your current session id. You can use all [[Session Module]] and [[Sessions Module]] functions within the websocket context.
<pre class="brush:xquery">
module namespace websocketexample = '';
(: Import the WebSocket module :)
import module namespace websocket = "";
function websocketexample:connect(
) {
let $client-id := websocket:id()
let $client-path := websocket:path()
let $response := json:serialize(
<json type="object">
return websocket:broadcast($response)
* First of all: include the websocket module
* The <code>$ws:connect("/")</code> annotation gets called if a client successfully creates a websocket to the path "/"
* Get the <code>client-id</code> and the <code>client-path</code> with <code>websocket:id()</code> and <code>websocket:path()</code>
* Create a json-result
* Broadcast the result to all connected clients without the calling client
administrator, editor


Navigation menu