All Projects → SocketCluster → Socketcluster Client

SocketCluster / Socketcluster Client

Licence: mit
JavaScript client for SocketCluster

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Socketcluster Client

Wsify
Just a tiny, simple and real-time self-hosted pub/sub messaging service
Stars: ✭ 452 (+80.8%)
Mutual labels:  websockets, realtime
Channelslightscontrol
Demo app with Django Channels to control Lights over websockets. Made for PyStPete meetup(https://www.meetup.com/Saint-Petersburg-Python-Meetup/).
Stars: ✭ 14 (-94.4%)
Mutual labels:  websockets, realtime
Vue Socket.io Extended
✌️⚡️ Socket.io bindings for Vue.js and Vuex (inspired by Vue-Socket.io)
Stars: ✭ 506 (+102.4%)
Mutual labels:  websockets, realtime
Pushpin
Proxy server for adding push to your API
Stars: ✭ 3,050 (+1120%)
Mutual labels:  websockets, realtime
Entangled
Rails in real time
Stars: ✭ 108 (-56.8%)
Mutual labels:  websockets, realtime
Angelo
Sinatra-like DSL for Reel that supports WebSockets and SSE
Stars: ✭ 303 (+21.2%)
Mutual labels:  websockets, realtime
Stl.fusion
Get real-time UI updates in Blazor apps and 10-1000x faster API responses with a novel approach to distributed reactive computing. Fusion brings computed observables and automatic dependency tracking from Knockout.js/MobX/Vue to the next level by enabling a single dependency graph span multiple servers and clients, including Blazor apps running in browser.
Stars: ✭ 858 (+243.2%)
Mutual labels:  websockets, realtime
intrinio-realtime-python-sdk
Intrinio Python SDK for Real-Time Stock Prices
Stars: ✭ 79 (-68.4%)
Mutual labels:  websockets, realtime
Sandstone
PHP microframework designed to build a RestApi working together with a websocket server. Build a real time RestApi!
Stars: ✭ 98 (-60.8%)
Mutual labels:  websockets, realtime
Codeigniter Ratchet Websocket
This library contains the demo of commenting/posting realtime using CodeIgniter+AngularJS+Ratchet PHP Websocket
Stars: ✭ 84 (-66.4%)
Mutual labels:  websockets, realtime
bong-bong
Open public chat service built for the web.
Stars: ✭ 17 (-93.2%)
Mutual labels:  websockets, realtime
Codenames
Stars: ✭ 159 (-36.4%)
Mutual labels:  websockets, realtime
django-rest-live
Subscribe to updates from Django REST Framework over Websockets.
Stars: ✭ 48 (-80.8%)
Mutual labels:  websockets, realtime
Sapphiredb
SapphireDb Server, a self-hosted, easy to use realtime database for Asp.Net Core and EF Core
Stars: ✭ 326 (+30.4%)
Mutual labels:  websockets, realtime
live-cryptocurrency-streaming-flutter
A Flutter app with live cryptocurrency updates, powered by Ably
Stars: ✭ 26 (-89.6%)
Mutual labels:  websockets, realtime
Supabase
The open source Firebase alternative. Follow to stay updated about our public Beta.
Stars: ✭ 25,142 (+9956.8%)
Mutual labels:  websockets, realtime
docs
The official soketi documentation. 📡
Stars: ✭ 55 (-78%)
Mutual labels:  websockets, realtime
soketi
Just another simple, fast, and resilient open-source WebSockets server. 📣
Stars: ✭ 2,202 (+780.8%)
Mutual labels:  websockets, realtime
Socketcluster Server
Minimal server module for SocketCluster
Stars: ✭ 70 (-72%)
Mutual labels:  websockets, realtime
Next Todos
200 lines realtime todos app powered by next.js, preact, jet, redux and now
Stars: ✭ 117 (-53.2%)
Mutual labels:  websockets, realtime

SocketCluster JavaScript client

Client module for SocketCluster.

Setting up

You will need to install both socketcluster-client and socketcluster-server (https://github.com/SocketCluster/socketcluster-server).

To install this module:

npm install socketcluster-client

How to use

The socketcluster-client script is called socketcluster-client.js (located in the main socketcluster-client directory). Embed it in your HTML page like this:

<script type="text/javascript" src="/socketcluster-client.js"></script>

* Note that the src attribute may be different depending on how you setup your HTTP server.

Once you have embedded the client socketcluster-client.js into your page, you will gain access to a global socketClusterClient object. You may also use CommonJS require or ES6 module imports.

Connect to a server

let socket = socketClusterClient.create({
  hostname: 'localhost',
  port: 8000
});

Transmit data

// Transmit some data to the server.
// It does not expect a response from the server.
// From the server socket, it can be handled using either:
// - for await (let data of socket.receiver('foo')) {}
// - let data = await socket.receiver('foo').once()
socket.transmit('foo', 123);

Invoke an RPC

(async () => {

  // Invoke an RPC on the server.
  // It expects a response from the server.
  // From the server socket, it can be handled using either:
  // - for await (let req of socket.procedure('myProc')) {}
  // - let req = await socket.procedure('myProc').once()
  let result = await socket.invoke('myProc', 123);

})();

Subscribe to a channel

(async () => {

  // Subscribe to a channel.
  let myChannel = socket.subscribe('myChannel');

  await myChannel.listener('subscribe').once();
  // myChannel.state is now 'subscribed'.

})();

Get a channel without subscribing

(async () => {

  let myChannel = socket.channel('myChannel');

  // Can subscribe to the channel later as a separate step.
  myChannel.subscribe();
  await myChannel.listener('subscribe').once();
  // myChannel.state is now 'subscribed'.

})();

Publish data to a channel

// Publish data to the channel.
myChannel.transmitPublish('This is a message');

// Publish data to the channel from the socket.
socket.transmitPublish('myChannel', 'This is a message');

(async () => {
  // Publish data to the channel and await for the message
  // to reach the server.
  try {
    await myChannel.invokePublish('This is a message');
  } catch (error) {
    // Handle error.
  }

  // Publish data to the channel from the socket and await for
  // the message to reach the server.
  try {
    await socket.invokePublish('myChannel', 'This is a message');
  } catch (error) {
    // Handle error.
  }
})();

Consume data from a channel

(async () => {

  for await (let data of myChannel) {
    // ...
  }

})();

Connect over HTTPS:

let options = {
  hostname: 'securedomain.com',
  secure: true,
  port: 443,
  rejectUnauthorized: false // Only necessary during debug if using a self-signed certificate
};
// Initiate the connection to the server
let socket = socketClusterClient.create(options);

For more detailed examples of how to use SocketCluster, see test/integration.js. Also, see tests from the socketcluster-server module.

Connect Options

See all available options: https://socketcluster.io/

let options = {
  path: '/socketcluster/',
  port: 8000,
  hostname: '127.0.0.1',
  autoConnect: true,
  secure: false,
  rejectUnauthorized: false,
  connectTimeout: 10000, //milliseconds
  ackTimeout: 10000, //milliseconds
  channelPrefix: null,
  disconnectOnUnload: true,
  autoReconnectOptions: {
    initialDelay: 10000, //milliseconds
    randomness: 10000, //milliseconds
    multiplier: 1.5, //decimal
    maxDelay: 60000 //milliseconds
  },
  authEngine: null,
  codecEngine: null,
  subscriptionRetryOptions: {},
  query: {
    yourparam: 'hello'
  }
};

Running the tests

  • Clone this repo: git clone [email protected]:SocketCluster/socketcluster-client.git
  • Navigate to project directory: cd socketcluster-client
  • Install all dependencies: npm install
  • Run the tests: npm test

Compatibility mode

For compatibility with an existing SocketCluster server, set the protocolVersion to 1 and make sure that the path matches your old server path:

let socket = socketClusterClient.create({
  protocolVersion: 1,
  path: '/socketcluster/'
});

Developing

Install all dependencies

cd socketcluster-client

npm install -g gulp gulp-cli browserify uglify-es

npm install

Building

To build the SocketCluster client:

npm run build

Change log

See the 'releases' section for changes: https://github.com/SocketCluster/socketcluster-client/releases

License

(The MIT License)

Copyright (c) 2013-2019 SocketCluster.io

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].