Socket IO Broadcast Driver for Masonite
Project description
SocketIO Driver
It's an extra broadcast driver support for SocketIO in masonite 4, it extends default masonite broadcast driver to support SocketIO.
Masonite Broadcast Server and Client Library
Setup
Install package using pip:
pip install masonite-socketio-driver
Add provider inside config/providers.py.
from socketio_driver.providers import SocketProvider
PROVIDERS = [
...,
# Application Providers
SocketProvider,
]
Driver Config
Add following configuration inside config/broadcast.py after "pusher": {...},
"pusher": {...},
"socketio": {
"driver": "socketio",
"host": env("BROADCAST_HOST", "localhost"),
"port": env("BROADCAST_PORT", "6379")
},
Add following keys in .env
.
BROADCAST_HOST=
BROADCAST_PORT=
Update the broadcast driver value to socketio
in .env
BROADCAST_DRIVER=socketio
Example
# broadcast to given channels
from masonite.controllers import Controller
from masonite.broadcasting import Broadcast
class YourController(Controller):
def your_function(self, broadcast: Broadcast):
broadcast_data = {
"message": "Hello World"
}
broadcast.channel(["channel-name"], "event-name", broadcast_data)
# broadcast to selected users/clients
from masonite.controllers import Controller
from masonite.broadcasting import Broadcast
from socketio_driver.facades import Communicator
class YourController(Controller):
def your_function(self, broadcast: Broadcast):
broadcast_data = {
"message": "Hello World"
}
clients = Communicator.clients()
ids = [client.socketID for client in clients]
broadcast.channel(ids, "event-name", broadcast_data)
def or_another_function(self, broadcast: Broadcast):
broadcast_data = {
"message": "Hello World"
}
clients = Communicator.clients()
broadcast.driver("socketio").user(clients[0]).send("event-name", broadcast_data)
Helpers
Facade helpers...
from socketio_driver.facades import Communicator
# List all clients:
Communicator.clients()
# Get client by sessionID
Communicator.client(id='client-session-id')
# Delete all clients
Communicator.delete_all_clients()
# Delete client by SocketClient instance
Communicator.delete(client)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file masonite-socketio-driver-2.1.0.tar.gz
.
File metadata
- Download URL: masonite-socketio-driver-2.1.0.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8f326d65e405b93bae8eddb9acd9886742a820815c8e6961898da5e019dd824 |
|
MD5 | 560728a0f7fef2a9c890480858310f89 |
|
BLAKE2b-256 | 68e3a462eb0b3f0c498983f43c989f5d5f4085547f0d23d0b77f3b37e650768b |
File details
Details for the file masonite_socketio_driver-2.1.0-py3-none-any.whl
.
File metadata
- Download URL: masonite_socketio_driver-2.1.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ace4674cb285de3596114d3e01e9039d53daed57099434cb1010c615df873e18 |
|
MD5 | 882bc0fdab1390575ee3b86527582d0c |
|
BLAKE2b-256 | 9cd14521ccd161dc1b579ff3dc6c8fe21f514f4426905a706cf12bb552c55b9f |