Application API¶
-
class
jibe.
MainApp
(connection)¶ -
assets_path
= None¶ Set to serve the files in a folder in the file system on a specific URL path. For example:
{'from': 'path/to/files', 'to': 'path/on/url'}
This will make files available in the folder ‘path/to/files’ on the URL ‘path/on/url’.
You can specify multiple pairs in a list:
[ {'to': '...', 'from': '...'}, {'to': '...', 'from': '...'}, etc ]
Note: At this time, the ‘from’ path is relative to the path where the app was started unless it is made absolute by prepending a ‘/’. The ‘to’ path is always absolute, i.e. a ‘/’ is prepended. This behavior may change in the future.
-
deliver
(message: Dict)¶ Delivers a message to the browser. If self.wshandler.connection is None (websocket has not been opened), the messages are queued in self.outbox. All queued messages are delivered once the websocket opens (self.wsopen is called).
- Parameters
message – Message to be delivered.
- Returns
None
-
main_handler_class
¶ This is the server’s handler for http requests made on this app. Used in MainApp.make_tornado_app(). Override and replace to change to change the default behavior.
alias of
MainHandler
-
classmethod
make_tornado_app
() → tornado.web.Application¶ Puts together the websocket handler and http handlers for this app into a tornado.web.Application.
- Returns
A Tornado application that ew can then serve at a specific port.
-
on_message
(message: Dict)¶ Called by the websocket handler’s on_message. Overrides the parent widget’s on_message. Delivers the message to the parent class (super) or to descendent (child).
- Parameters
message – The message from the client.
- Returns
None
-
classmethod
run
(port=8881)¶ Single App quick starter.
- Parameters
port – Port to listen at.
- Returns
None
-
-
class
jibe.
MainHandler
(application: tornado.web.Application, request: tornado.httputil.HTTPServerRequest, **kwargs: Any)¶ Serves the top level html and core elements (javascript) of the application.
-
class
jibe.
WebSocketHandler
(*args, **kwargs)¶ Serves application widgets and handles communications during the life time of the application.
The class is common to all connections. Each connection uses one instance.
-
data_received
(chunk: bytes) → Optional[Awaitable[None]]¶ Implement this method to handle streamed request data.
Requires the .stream_request_body decorator.
May be a coroutine for flow control.
-
on_close
()¶ Called when the connection has been closed (Probably by the client). Clears the class’ connection attribute.
- Returns
None
-
on_message
(message)¶ Handles messages received from the browser. So far, messages are passed directly to the application. They could potentially be intercepted here for “pluggable” processing of messages.
- Parameters
message – A valid JSON string.
- Returns
None
-
open
()¶ Invoked when a new WebSocket is opened.
An instance of self.mainApp is created and saved in self.app.
- Returns
None
-