JavaXT
|
|
WebSocket ClassUsed to communicate with a server using web sockets. Currently, this is a read-only listener designed to get updates and status messages from the server. The listener will automatically reconnect to the server if the network connnection is interrupted.
var ws = new javaxt.dhtml.WebSocket({ url: "/live/stats", onMessage: function(msg){ console.log(msg); } }); var logout = function(){ ws.stop(); //stop listening to events and disconnect from the server }; ConstructorsConfig Optionsurl Relative path the to websocket endpoint (e.g. "/updates"). You do not need to specify a full url with a "ws://" or "wss://" prefix.
keepAlive Interval used to check whether the websocket is still alive and send ping messages. Value is in milliseconds. Default is 15000 (1.5 seconds).
pingMessage Message to send to the server. This message is periodically sent to the server to test whether it is still alive. See keepAlive config.
timeout Max amount of time to wait for the websocket to reconnect with the server after a disconnect. Value is in milliseconds. Default is 300000 (5 minutes).
debugr Class used to debug the websocket. This config is not required to use this class. Implementations must implement an append() method.
EventsonConnect( ) Called whenever a websocket connection is established with the server. Note that this event will be fired whenever a connection is dropped and then restablished. onFailure( code, reason ) Called whenever there is a problem connecting or reconnecting to the server. onTimeout( ) Called when a websocket is disconnected from the server for an extended period of time. See timeout config. Public Methodsstart( ) Used to open a websocket connection to the server and start listening to events. Note that the websocket listener is started automatically when this class is first initialized. This method is only intended to be used after calling stop(). |