Changes

Jump to navigation Jump to search
96 bytes removed ,  18:33, 1 December 2023
m
Text replacement - "</syntaxhighlight>" to "</pre>"
<pre lang='xquery'>
declare %ws:connect('/') function local:connect() { };
</syntaxhighlightpre>
You can specify here how to handle your users, e. g. save a name as a WebSocket attribute. Furthermore, you can check header parameters for validity.
<pre lang='xquery'>
declare %ws:message('/', '{$info}') function local:message($info) { };
</syntaxhighlightpre>
The value will be of type <code>xs:string</code> or <code>xs:base64Binary</code>. As there is no fixed message protocol, the client needs to take care of the message syntax.
<pre lang='xquery'>
declare %ws:error('/', '{$error}') function local:error($error) { };
</syntaxhighlightpre>
Usually, errors happen because of bad/malformed incoming packets. The WebSocket connection gets closed after the error handling.
<pre lang='xquery'>
declare %ws:close('/') function local:connect() { };
</syntaxhighlightpre>
The WebSocket is already closed when this annotation is called so there can be no return.
admin:write-log('Connection was closed: ' || $host)
};
</syntaxhighlightpre>
The following parameters are available:
function example:connect() as empty-sequence() {
};
</syntaxhighlightpre>
The connect function is sufficient for creating the persistent client/server connection. In order to something sensible with the connection, you should implement a function annotated with <code>%ws:message("/")</code>:
ws:emit($message)
};
</syntaxhighlightpre>
In the function above, the [[WebSocket Module]] is imported, and the function <code>ws:emit</code> is used for forwarding the message to all connected clients.
ws.send(message);
};
</syntaxhighlightpre>
The <code>send</code> function can be called to pass on a string to the server.
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu