Project description
What is Broadcast-SocketIO-Driver?
It's an extra broadcast driver for masonite. It adds support for socketio.
Setup
Install package using pip:
pip install socket-io-driver
Add provider inside config/providers.py.
from socket_io_driver.SocketioBroadcastProvider import SocketioBroadcastProvider
PROVIDERS = [
...,
# Application Providers
SocketioBroadcastProvider,
]
Storage Config
Add following configuration inside config/broadcast.py.
"socketio": {
"host": env("SOCKET_HOST", "http://localhost"),
"port": env("SOCKET_PORT", "3000"),
},
Add following keys in .env
.
SOCKET_HOST=
SOCKET_PORT=
And finally update your broadcast driver in .env
.
BROADCAST_DRIVER=socketio
Example
from masonite.request import Request
from masonite import Broadcast
def your_function(request: Request, broadcast: Broadcast):
channels = ['admin', 'chat'] # can be single or multiple channels
broadcast.channel(channels, {
'message': "Hello SocketIo!", # your data
}, 'message') # event-name
Enjoy ;)