kagtcprlib.webinterface¶
Module webinterface provides a web interface to show the status of each KAG server connected. To run it, you must provide a config .toml file containing the details of each server you wish to connect to.
Example
$ python -m kagtcprlib.webinterface example_config_file.toml
Now navigate to http://localhost:8000 and you should be able to see the interface.
Functions
get_client_by_name (nickname) |
Returns the client identified by nickname from CLIENT_LIST. |
get_client_description (client) |
Returns useful info about the given Client. |
get_client_descriptions () |
Returns the descriptions of each Client in CLIENT_LIST. |
handle_incoming_message (msg) |
Handles an incoming SocketMsg from a client. |
sync_clients () |
Works out whether the description of any clients has changed, and if so broadcasts the change to all connected websockets. |
sync_clients_worker () |
Classes
KagClientInfoSocket (server, sock, address) |
Extension of WebSocket used to handle the connection to the browser. |
MyWebSocketServer (host, port, websocketclass) |
Extension of SimpleWebSocketServer which allows for broadcasting a SocketMsg to all connected sockets. |
SocketMsg (type, data) |
A message to be sent over the WebSocket to browsers. |
WebSocketBroadcastHandler |
This handler, whenever it receives a line, will broadcast it to all connected WebSockets. |
-
class
kagtcprlib.webinterface.
KagClientInfoSocket
(server, sock, address)[source]¶ Bases:
SimpleWebSocketServer.SimpleWebSocketServer.WebSocket
Extension of WebSocket used to handle the connection to the browser.
-
close
(status=1000, reason='')¶ Send Close frame to the client. The underlying socket is only closed when the client acknowledges the Close frame.
status is the closing identifier. reason is the reason for the close.
-
handleClose
()¶ Called when a websocket server gets a Close frame from a client.
-
handleMessage
()[source]¶ Called when websocket frame is received. To access the frame data call self.data.
If the frame is Text then self.data is a unicode object. If the frame is Binary then self.data is a bytearray object.
-
sendFragment
(data)¶ see sendFragmentStart()
If data is a unicode object then the frame is sent as Text. If the data is a bytearray object then the frame is sent as Binary.
-
sendFragmentEnd
(data)¶ see sendFragmentEnd()
If data is a unicode object then the frame is sent as Text. If the data is a bytearray object then the frame is sent as Binary.
-
sendFragmentStart
(data)¶ Send the start of a data fragment stream to a websocket client. Subsequent data should be sent using sendFragment(). A fragment stream is completed when sendFragmentEnd() is called.
If data is a unicode object then the frame is sent as Text. If the data is a bytearray object then the frame is sent as Binary.
-
sendMessage
(data)¶ Send websocket data frame to the client.
If data is a unicode object then the frame is sent as Text. If the data is a bytearray object then the frame is sent as Binary.
-
-
class
kagtcprlib.webinterface.
MyWebSocketServer
(host, port, websocketclass, selectInterval=0.1)[source]¶ Bases:
SimpleWebSocketServer.SimpleWebSocketServer.SimpleWebSocketServer
Extension of SimpleWebSocketServer which allows for broadcasting a SocketMsg to all connected sockets.
-
class
kagtcprlib.webinterface.
SocketMsg
(type, data)[source]¶ Bases:
object
A message to be sent over the WebSocket to browsers.
Parameters: - type (str) – The type of the message. This identifies what kind of message this is, and what the data will be.
- data (any) – The message’s data. This could be any type which is JSON serializable.
-
class
kagtcprlib.webinterface.
WebSocketBroadcastHandler
[source]¶ Bases:
kagtcprlib.handlers.BaseHandler
This handler, whenever it receives a line, will broadcast it to all connected WebSockets.
-
kagtcprlib.webinterface.
get_client_by_name
(nickname)[source]¶ Returns the client identified by nickname from CLIENT_LIST.
Parameters: nickname (str) – The nickname of the client
-
kagtcprlib.webinterface.
get_client_description
(client)[source]¶ Returns useful info about the given Client.
Parameters: client (Client) – The client Returns: The description Return type: dict
-
kagtcprlib.webinterface.
get_client_descriptions
()[source]¶ Returns the descriptions of each Client in CLIENT_LIST.
Returns: The descriptions Return type: list(dict)