Assign an R function to service an HTML 5 Websocket event type.
set_callback(id, f, envir)
setCallback(id, f, envir)
The callback name. Presently supported names are
closed
, established
, and receive
.
The callback function. See the details section for required function arguments.
The environment associated with the R websocket context returned by
createContext
.
The set_callback
function is invoked for its side effect of
assigning the function to the variable name in the websocket context
evnironment. NULL is invisible returned.
Define one or more of the callback functions to respond to websocket events
(all of them are optional). A callback function is evaluated whenever
a matching event is serviced by the service
function. There are
three supported callback function names:
established
, receive
, and closed
, that are evaluated
when corresponding events occur for the websocket.
The receive
function must take three arguments:
DATA
A RAW vector that holds any incoming data associated with the
event, for example from broadcast or receive.
WS
The websocket file descriptor.
HEADER
Contains message header information for
newer protocol messages. The vignette describes this parameter in detail. Although
it is a required parameter, it is usually ignored in practice.
The closed
callback is fired whenever a websocket client socket is closed.
The receive
callback occurs when data is received on a client websocket.
The established
callback occurs when a new websocket client socket connection
is successfully negotiated.
The established
and closed
functions must each take one argument:
WS
The websocket file descriptor.
. NOTE THAT THE CALLBACK FUNCTION PARAMETERS HAVE CHANGED AS OF PACKAGE VERSION 1.1.0 AND ARE NOT COMPATIBLE WITH PREVIOUS PACKAGE VERSIONS.
The arguments will be populated by data corresponding to the event.
The WS
socket can be used by the websocket_write
function to write data to the client through the socket.
Non-websocket HTTP requests are serviced by the static
function callback
defined by the webpage
argument described in the create_server
help pages. The static
function may also be redefined with
set_callback
.
# NOT RUN {
# See the detailed example in help('websockets').
# }
Run the code above in your browser using DataLab