Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/py-package/masonite-broadcast-client
- Owner: py-package
- License: mit
- Created: 2022-01-09T17:35:59.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-03-22T10:46:31.000Z (10 months ago)
- Last Synced: 2024-12-20T03:49:35.131Z (about 1 month ago)
- Topics: masonite-framework, masonite-package, nodejs, realtime, socket-io, websocket
- Language: TypeScript
- Homepage:
- Size: 162 KB
- Stars: 11
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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)**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);
});
```