j-WebSocket
The component sends and receives JSON through a reconnecting WebSocket. Configure url, bind a model path to receive messages, and call the send method to transmit objects.
Configuration:
url {String}URL for websocket, it can be relative or absolutereconnect {Number}can contain only a number (milliseconds, default:3000)encoder {Boolean}performs encode/decode messages viaURI(default:false)- NEW:
statsinterval {Number}stats interval in milliseconds (default:1000) - NEW:
stats {String}a link to methodfunction({ received: Number, sent: Number })or path to a variable (measured in bytes)
Methods:
component.send(obj)- sends JSON serialized object to the servercomponent.close()- closes connectioncomponent.connect()- opens connectioncomponent.idletime(is)- NEW can cancel/reopen connection
Events:
ON('message', function(data) {})- received dataON('online', function(isOnline) {})- online/offline
Usage
<ui-component name="websocket" path="updates.latest"
config="url:/updates/"></ui-component>
<script>
function sendUpdate(value) {
SETTER('websocket/send', { type: 'update', value: value });
}
</script>Source: Total.js components. Copyright Peter Širka and contributors. MIT license.