ForgeComponents
en

Components

j-WebSocket

jComponent 20 · jcomponent@20 component

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 absolute
  • reconnect {Number} can contain only a number (milliseconds, default: 3000)
  • encoder {Boolean} performs encode/decode messages via URI (default: false)
  • NEW: statsinterval {Number} stats interval in milliseconds (default: 1000)
  • NEW: stats {String} a link to method function({ received: Number, sent: Number }) or path to a variable (measured in bytes)

Methods:

  • component.send(obj) - sends JSON serialized object to the server
  • component.close() - closes connection
  • component.connect() - opens connection
  • component.idletime(is) - NEW can cancel/reopen connection

Events:

  • ON('message', function(data) {}) - received data
  • ON('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.