Skip to main content

Socket IO Broadcast Driver for Masonite

Project description

PyPI issues Python Version GitHub release (latest by date including pre-releases) License star downloads Code style: black

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

masonite-socketio-driver-2.1.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file masonite-socketio-driver-2.1.0.tar.gz.

File metadata

File hashes

Hashes for masonite-socketio-driver-2.1.0.tar.gz
Algorithm Hash digest
SHA256 e8f326d65e405b93bae8eddb9acd9886742a820815c8e6961898da5e019dd824
MD5 560728a0f7fef2a9c890480858310f89
BLAKE2b-256 68e3a462eb0b3f0c498983f43c989f5d5f4085547f0d23d0b77f3b37e650768b

See more details on using hashes here.

File details

Details for the file masonite_socketio_driver-2.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for masonite_socketio_driver-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ace4674cb285de3596114d3e01e9039d53daed57099434cb1010c615df873e18
MD5 882bc0fdab1390575ee3b86527582d0c
BLAKE2b-256 9cd14521ccd161dc1b579ff3dc6c8fe21f514f4426905a706cf12bb552c55b9f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page