1.2.15. web_sockets
¶
1.2.15.1. Classes¶
-
class
Event
(event_id, event_type, sources)[source]¶ Bases:
object
An object representing an event which occurred on the server in a way that is ready to be published to client subscribers.
-
class
EventSocket
(handler, manager)[source]¶ Bases:
advancedhttpserver.WebSocketHandler
A socket through which server events are published to subscribers. This socket will automatically add and remove itself from the manager that is initialized with.
-
__init__
(handler, manager)[source]¶ Parameters: - handler (
advancedhttpserver.RequestHandler
) – The request handler that should be used by this socket. - manager (
WebSocketsManager
) – The manager that this event socket should register with.
- handler (
-
is_subscribed
(event_id, event_type)[source]¶ Check if the client is currently subscribed to the specified server event.
Parameters: Returns: Whether or not the client is subscribed to the event.
Return type:
-
publish
(event)[source]¶ Publish the event by sending the relevant information to the client. If the client has not requested to receive the information through a subscription, then no data will be sent.
Parameters: event ( Event
) – The object representing the data to be published.
-
subscribe
(event_id, event_types=None, attributes=None)[source]¶ Subscribe the client to the specified event published by the server. When the event is published the specified attributes of it and it’s corresponding id and type information will be sent to the client.
Parameters:
-
-
class
WebSocketsManager
(config, job_manager)[source]¶ Bases:
object
An object used to manage connected web sockets.
-
__init__
(config, job_manager)[source]¶ Parameters: - config (
smoke_zephyr.configuration.Configuration
) – Configuration to retrieve settings from. - job_manager (
smoke_zephyr.job.JobManager
) – A job manager instance that can be used to schedule tasks.
- config (
-
add
(web_socket)[source]¶ Add a connected web socket to the manager.
Parameters: web_socket ( advancedhttpserver.WebSocketHandler
) – The connected web socket.
-
dispatch
(handler)[source]¶ A method that is suitable for use as a
web_socket_handler
.Parameters: handler ( KingPhisherRequestHandler
) – The current request handler instance.
-
ping_all
()[source]¶ Ping all of the connected web sockets to ensure they stay alive. This method is automatically executed periodically through a job added when the manager is initialized.
-
remove
(web_socket)[source]¶ Remove a connected web socket from those that are currently being managed. If the web socket is not currently being managed, no changes are made.
Parameters: web_socket ( advancedhttpserver.WebSocketHandler
) – The connected web socket.
-