Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/py-package/masonite-broadcast-client

This is a library providing client side support for the Masonite SocketIO Broadcast driver.
https://github.com/py-package/masonite-broadcast-client

masonite-framework masonite-package nodejs realtime socket-io websocket

Last synced: 29 days ago
JSON representation

This is a library providing client side support for the Masonite SocketIO Broadcast driver.

Awesome Lists containing this project

README

        

# Masonite Broadcast Client (WIP)



> This is a library providing client side support for the Masonite broadcast driver.

**Masonite Broadcast Server and Client Library**
- [x] [Broadcast Driver - Backend](https://github.com/py-package/masonite-socketio-driver)
- [x] [Broadcast Server](https://github.com/py-package/masonite-broadcast-server)


Version
Issues
GitHub release (latest by date including pre-releases)
License
star
downloads

**Installation**

```sh
$ npm install masonite-broadcast-client socket.io-client
$ yarn add masonite-broadcast-client socket.io-client
```

**Example**

```js
/** Connection */

window.io = require("socket.io-client");
const MasoniteBroadcastClient = require("masonite-broadcast-client");

const broadcast = new MasoniteBroadcastClient({
url: "http://localhost:3000",
broadcastUrl: "http://localhost:8000/broadcast/auth" // optional
});

broadcast.onUserConnected(user => {
console.log(`${user.userID} connected`);
});
```
```js
/** You can add an extra value in session */

broadcast.setExtra("value", (user) => { // value here must not be complex data types
console.log(user);
})
```
```js
/** Subscribe to channel */

const subscription = broadcast.subscribe("chat");
```
```js
/** Broadcast to all */

subscription.emit("your-event", your_data_here)
```
```js
/** Broadcast to all except the sender */

subscription.broadcast("your-event", your_data_here);
```
```js
/** Listen for events */

subscription.listen('message', (data) => {
console.log(data);
}).listen('your-event', (data) => {
console.log(data);
});
```