Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/socketsomeone/cent.js
👀 Javascript library to communicate with Centrifugo HTTP API
https://github.com/socketsomeone/cent.js
centrifugal centrifuge centrifugo nodejs websocket websockets ws
Last synced: 3 months ago
JSON representation
👀 Javascript library to communicate with Centrifugo HTTP API
- Host: GitHub
- URL: https://github.com/socketsomeone/cent.js
- Owner: SocketSomeone
- License: mit
- Created: 2022-02-08T22:11:07.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-10-29T10:39:36.000Z (3 months ago)
- Last Synced: 2024-10-29T12:37:33.614Z (3 months ago)
- Topics: centrifugal, centrifuge, centrifugo, nodejs, websocket, websockets, ws
- Language: TypeScript
- Homepage: https://npmjs.com/package/cent.js
- Size: 2.14 MB
- Stars: 16
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# cent.js
Javascript library to communicate with Centrifugo HTTP API.
## Installation
```bash
$ npm i cent.js
```## Usage
First see [available API methods in documentation](https://centrifugal.dev/docs/server/server_api).
This library contains `CentClient` class to send messages to Centrifugo from your node-powered backend:
```javascript
const {CentClient} = require('cent.js');// Initialize client instance.
const client = new CentClient({
url: 'http://localhost:8000/api',
apiKey: 'XXX'
});// Publish data into channel
const publishRes = await client.publish({
channel: 'public:chat',
data: {input: "test"}
}).catch(err => handleError()); // We throw error in case of unsuccessful
// response from Centrifugo or some other
// internal errors.// Other available methods
await client.unsubscribe({user: 'user_id', channel: 'channel'});
await client.disconnect({user: 'user_id'})
await client.getHistory({channel: 'channel'})
await client.getPresence({channel: 'channel'})
await client.getChannels()
await client.getInfo()
await client.removeHistory({channel: 'channel'})
```## Stay in touch
* Author - [Alexey Filippov](https://t.me/socketsomeone)
* Twitter - [@SocketSomeone](https://twitter.com/SocketSomeone)## License
[MIT](https://github.com/SocketSomeone/necord/blob/master/LICENSE) © [Alexey Filippov](https://github.com/SocketSomeone)