Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kanata-php/socket-conveyor-client

A client for the php package kanata-php/socket-conveyor
https://github.com/kanata-php/socket-conveyor-client

Last synced: 7 days ago
JSON representation

A client for the php package kanata-php/socket-conveyor

Awesome Lists containing this project

README

        





Version

> A client for the php package kanata-php/socket-conveyor

### 🏠 [Homepage](https://github.com/kanata-php/socket-conveyor-client#readme)

## Prerequisites

- npm >=5.5.0
- node >=9.3.0

## Install

```sh
npm install socket-conveyor-client
```

## Description

This is a client for the [Socket Conveyor](https://github.com/kanata-php/socket-conveyor) PHP package..

## Usage

To use this package, once it is installed, the following example shows how it works.

```html


Base Action

First Action

Second Action


// if this connection happens on a bundle, use it like this: import Conveyor from 'socket-conveyor-client';
import Conveyor from './node_modules/socket-conveyor-client/index.js';

var connection = new Conveyor({
channel: 'actions-channel',
listen: ['example-first-action'],
onMessage: (e) => {
document.getElementById('output').innerHTML = e;
},
onReady: () => {
connection.send('Welcome!');
},
});

```

With the previous example your html client will try to connect to `ws://127.0.0.1:8000`. This client will connect to the channel `actions-channel`, and will listen to `example-first-action` actions. That said, any message sent to that **channel** and **action**, will be received at the `OnMessage` callback.

## Options

```
protocol: 'ws',
uri: '127.0.0.1',
port: 8000,

// Url query for connection.
query: '',

channel: null,
listen: null,
onOpen: this.onOpen.bind(this),
onReady: () => {},

// Message handler for only the data portion.
onMessage: () => {},

// Message handler for the whole incoming object.
onRawMessage: () => {},

// Callback triggered when closing connection. If overwritten the reconnection feature can be affected.
onClose: () => this.onClose.bind(this),

// Callback for securely do something when connection is closed, without affecting default closing connection behavior.
onCloseCallback: () => {},

// Callback for reconnection feature. Useful if you need to renew a token before attempting again. You might also want to check the method `setOption` for this, so you can change options during this procedure.
onReconnectCallback: () => {},

onError: () => {},

// Settings for reconnection feature.
reconnect: false,
reconnectDelay: 5000,

// Interval for connection verification, so reconnection action can take place if reconnection active.
healthCheckInterval: 3000,

// Interval for connection heartbeat, so connection can be kept alive.
heartBeat: true,
heartBeatInterval: 10000,
```

## Author

👤 **Savio Resende**

* Website: https://savioresende.com.br
* GitHub: [@lotharthesavior](https://github.com/lotharthesavior)

## Show your support

Give a ⭐️ if this project helped you!

## 📝 License

Copyright © 2022 [Savio Resende](https://github.com/lotharthesavior).