![]() |
Qore ServerSentEventHandler Module Reference 1.0
|
the main web socket handler class More...
#include <ServerSentEventHandler.qc.dox.h>
Public Member Functions | |
constructor (*HttpServer::AbstractAuthenticator auth, *hash< auto > opts) | |
Create the object optionally with the given AbstractAuthenticator. | |
constructor (hash< auto > opts) | |
Create the object optionally with the given optiond. | |
deregisterConnectionImpl (ServerSentEventConnection conn) | |
called when the connection terminates; the default implementation does nothing | |
ServerSentEventConnection | doNewConnection (Socket sock, hash< auto > cx, hash< auto > hdr, string cid) |
Called when a connection is established; registers the new connection internally. | |
string | encodeMessage (hash< SseMessageInfo > msg) |
Encode a message for sending. | |
bool | flushIo (ServerSentEventConnection conn, Socket sock) |
Flushes I/O in the connection queue. | |
*list< string > | getConnectionIds () |
get list of socket connection ids | |
ServerSentEventConnection | getConnectionImpl (Socket sock, hash< auto > cx, hash< auto > hdr, string cid) |
Called when a connection is established; the default implementation creates a ServerSentEventConnection object. | |
int | getHeartbeat () |
returns the connection heartbeat interval as a number of seconds | |
hash< auto > | handleRequest (hash< auto > cx, hash< auto > hdr, *data b) |
called by the HTTP server to handle incoming HTTP requests | |
logDebug (string fmt,...) | |
Log to the logger. | |
logError (string fmt,...) | |
Log to the logger. | |
logInfo (string fmt,...) | |
Log to the logger. | |
logWarn (string fmt,...) | |
Log to the logger. | |
sendAll (hash< SseMessageInfo > msg) | |
sends a message to all connected clients | |
sendOne (softstring id, hash< SseMessageInfo > msg) | |
sends a message to the given connection ID | |
setHeartbeat (date seconds) | |
sets the heartbeat interval as a number of seconds | |
setHeartbeat (softint seconds) | |
sets the heartbeat interval as a number of seconds | |
bool | startImpl (softstring lid, hash< auto > cx, hash< auto > hdr, Qore::Socket sock) |
Called from the HTTP server after the handleRequest() method indicates that a dedicated connection should be established. | |
stopOne (softstring id) | |
stop given connection ID | |
Static Public Member Functions | |
static string | serializeDefault (auto v) |
Default value serialization. | |
static string | serializeJson (auto v) |
JSON value serialization. | |
Protected Member Functions | |
constructorInit (*hash< auto > opts) | |
Common constructor initialization. | |
replayEventsSince (ServerSentEventConnection conn, auto id) | |
Resend all events since the given event. | |
RWLock | rwl () |
connection read-write lock | |
Protected Attributes | |
hash< string, ServerSentEventConnection > | ch |
connection hash | |
int | heartbeat = DefaultHeartbeatInterval |
heartbeat interval in seconds | |
string | heartbeat_msg = DefaultHeartbeatMsg |
heartbeat message | |
string | serialization |
The value of the serialization option. | |
code | serializer |
Value serialization code. | |
Private Attributes | |
string | tlk = get_random_string(50) |
Thread-local key for I/O check. | |
the main web socket handler class
connections are represented by object descended from ServerSentEventConnection. ServerSentEventHandler::ServerSentEventHandler::getConnectionImpl() returns a suitable object for each connection, this method can be overridden in subclasses to return a custom object for each connection if required.
ServerSentEvent connections are identified by their HTTP connection ID as passed in ServerSentEventHandler::handleRequest() in the "cx.id"
argument when the connection is first established.
ServerSentEventHandler::ServerSentEventHandler::constructor | ( | *HttpServer::AbstractAuthenticator | auth, |
*hash< auto > | opts ) |
Create the object optionally with the given AbstractAuthenticator.
auth | the authentication object to use to authenticate connections (see AbstractAuthenticator); if no AbstractAuthenticator object is passed, then by default no authentication will be required |
opts | options for the object with the following optional keys:
|
SERVERSENTEVENTHANDLER-OPTION-ERROR | unknown or invalid option |
bool ServerSentEventHandler::ServerSentEventHandler::flushIo | ( | ServerSentEventConnection | conn, |
Socket | sock ) |
Flushes I/O in the connection queue.
int ServerSentEventHandler::ServerSentEventHandler::getHeartbeat | ( | ) |
returns the connection heartbeat interval as a number of seconds
hash< auto > ServerSentEventHandler::ServerSentEventHandler::handleRequest | ( | hash< auto > | cx, |
hash< auto > | hdr, | ||
*data | b ) |
called by the HTTP server to handle incoming HTTP requests
To accept a dedicated connection; make sure the return value hash's "code"
key is 101 (i.e. "Switching Protocols"
) and the "close"
key is not False
cx | call context hash; this hash will have the following keys:
|
hdr | incoming header hash; all keys will be converted to lower-case, additionally the following keys will be present:
|
b | message body, if any |
"code"
is 101 (ie "Switching Protocols"
) or the Content-Type
headers is set to text/event-stream
, and the "close"
key is not False:"code"
: the HTTP return code (see HttpServer::HttpCodes) (101 "Switching Protocols"
to accept the dedicated connection, in which case the start() method will be called)"body"
: the message body to return in the response"hdr"
: (optional) set this key to a hash of extra header information to be returned with the responseServerSentEvent connections are identified by their HTTP connection ID as passed in "cx.id"
ServerSentEventHandler::ServerSentEventHandler::sendAll | ( | hash< SseMessageInfo > | msg | ) |
sends a message to all connected clients
d | the data to send |
Messages are automatically encoded with ServerSentEventUtil::ws_encode_message() before sending
ServerSentEventHandler::ServerSentEventHandler::sendOne | ( | softstring | id, |
hash< SseMessageInfo > | msg ) |
sends a message to the given connection ID
ServerSentEvent connections are identified by their HTTP connection ID as passed in ServerSentEventHandler::handleRequest() in the "cx.id"
argument when the connection is first established.
Messages are automatically encoded with ServerSentEventUtil::ws_encode_message() before sending
ServerSentEventHandler::ServerSentEventHandler::setHeartbeat | ( | date | seconds | ) |
sets the heartbeat interval as a number of seconds
seconds | the heartbeat interval as a number of seconds |
ServerSentEventHandler::ServerSentEventHandler::setHeartbeat | ( | softint | seconds | ) |
sets the heartbeat interval as a number of seconds
seconds | the heartbeat interval as a number of seconds |
bool ServerSentEventHandler::ServerSentEventHandler::startImpl | ( | softstring | lid, |
hash< auto > | cx, | ||
hash< auto > | hdr, | ||
Qore::Socket | sock ) |
Called from the HTTP server after the handleRequest() method indicates that a dedicated connection should be established.
This method should not return until the connection is closed or the stop() method is called
lid | the unique HTTP listener ID |
cx | call context hash; this hash will have the following keys:
|
hdr | a hash of headers in the request |
sock | the Socket object for the dedicated connection to the client |