@sequenia/socket-action-cable

library for rails action cable

Usage no npm install needed!

<script type="module">
  import sequeniaSocketActionCable from 'https://cdn.skypack.dev/@sequenia/socket-action-cable';
</script>

README

@sequenia/socket-action-cable

library for rails action cable

NPM JavaScript Style Guide

Install

npm install --save @sequenia/socket-action-cable

Usage

import ActionCable from '@sequenia/socket-action-cable'

/* create socket connection */
const url = "wss://url-path-to-somewhere";
const ActionCableInstance = new ActionCable(url)

/* subscribe to channel: channell name, params and onMessage channel callback function */
ActionCableInstance.subscribe("ExampleChannel", {foo: "bar", bar: "buzz"}, message => message)

/* unsubscribe */
ActionCableInstance.unsubscribe("ExampleChannel")

/* get readyState of socket connection */
const readyState = ActionCableInstance.readyState

/* get buffered amount of socket connection */
const bufferedAmount = ActionCableInstance.bufferedAmount

/* close connection */
ActionCableInstance.close()

/* onError socket connection callback */
ActionCableInstance.onErrorCallback((event) => { ... })

/* onClose socket connection callback */
ActionCableInstance.onClose((event) => { ... })

License

MIT © sequenia