1.1.6 • Published 3 months ago

socketcluster-wrapper-client v1.1.6

Weekly downloads
194
License
MIT
Repository
-
Last release
3 months ago

Socketcluster Client Wrapper

Usages

Web

// for browser
import 'socketcluster-wrapper-client/dist';

// for react or other import module
import SocketClient from 'socketcluster-wrapper-client';
const options = {
  secure: true,
  authType: 'ws'
}
// options.secure to use https
// options.authType: using authentication via http or ws.

// apiKey: indentity client request can generate from dashboard
const client = new SocketClient(apiKey, options)
const socket = await client.connect()

// other usage can follow https://github.com/SocketCluster/socketcluster-client#transmit-data

React Native

import SocketClient from 'socketcluster-wrapper-client';
import AuthEngine from 'socketcluster-wrapper-client/authEngine';

const options = {
  secure: true,
  authType: 'ws',
  authEngine: new AuthEngine()
}
// options.secure to use https
// options.authType: using authentication via http or ws.

// apiKey: indentity client request can generate from dashboard 
const client = new SocketClient(apiKey, options)
const socket = await client.connect()

// Connect with channel and listen stream data
// using for await (let data of channel) is not working with React Native
const channel = socket.subscribe('realtime');

const iterator = channel[Symbol.asyncIterator]();
const result = [];
while (result.length < Infinity) {
    const { value, done } = await iterator.next();
    if (done) break;
    console.log(value);
}

// other usage can follow https://github.com/SocketCluster/socketcluster-client#transmit-data

Additional to support es6 async iterable

  yarn add --dev @babel/plugin-proposal-async-generator-functions
  npm install --save-dev @babel/plugin-proposal-async-generator-functions

Add Line bellow to babel.config.js

  "plugins": ["@babel/plugin-proposal-async-generator-functions"]

Socket Listener

const channel = socket.subscribe('realtime');
for await (let data of channel) {
  console.log(data);
}

NOTE Additional installation AsyncStorage

1.1.6

3 months ago

1.1.5

3 months ago

1.1.4

3 months ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.9

3 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago