httprouter

The http module contains the API web server. This is a lightweight web server used by remotes to interact with OpenLP. It uses JSON to communicate with the remotes.

Routes:

/
Go to the web interface.
/stage
Show the stage view.
/files/{filename}
Serve a static file.
/stage/api/poll

Poll to see if there are any changes. Returns a JSON-encoded dict of any changes that occurred:

{"results": {"type": "controller"}}

Or, if there were no results, False:

{"results": False}
/api/display/{hide|show}
Blank or unblank the screen.
/api/alert

Sends an alert message to the alerts plugin. This method expects a JSON-encoded dict like this:

{"request": {"text": "<your alert text>"}}
/api/controller/{live|preview}/{action}

Perform {action} on the live or preview controller. Valid actions are:

next
Load the next slide.
previous
Load the previous slide.
set

Set a specific slide. Requires an id return in a JSON-encoded dict like this:

{"request": {"id": 1}}
first
Load the first slide.
last
Load the last slide.
text

Fetches the text of the current song. The output is a JSON-encoded dict which looks like this:

{"result": {"slides": ["...", "..."]}}
/api/service/{action}

Perform {action} on the service manager (e.g. go live). Data is passed as a json-encoded data parameter. Valid actions are:

next
Load the next item in the service.
previous
Load the previews item in the service.
set

Set a specific item in the service. Requires an id returned in a JSON-encoded dict like this:

{"request": {"id": 1}}
list

Request a list of items in the service. Returns a list of items in the current service in a JSON-encoded dict like this:

{"results": {"items": [{...}, {...}]}}
class openlp.plugins.remotes.lib.httprouter.HttpRouter[source]

Bases: openlp.core.common.registryproperties.RegistryProperties

This code is called by the HttpServer upon a request and it processes it based on the routing table. This code is stateless and is created on each request. Some variables may look incorrect but this extends BaseHTTPRequestHandler.

add_to_service(plugin_name)[source]

Add item of type plugin_name to the end of the service.

Parameters:plugin_name – name of plugin to be called
alert()[source]

Send an alert.

call_function(function, *args)[source]

Invoke the route function passing the relevant values

Parameters:
  • function – The function to be called.
  • args – Any passed data.
controller(display_type, action)[source]

Perform an action on the slide controller.

Parameters:
  • display_type – This is the type of slide controller, either preview or live.
  • action – The action to perform.
controller_text(var)[source]

Perform an action on the slide controller.

Parameters:var – variable - not used
display(action)[source]

Hide or show the display screen. This is a cross Thread call and UI is updated so Events need to be used.

Parameters:action – This is the action, either hide or show.
do_authorisation()[source]

Create a needs authorisation http header.

do_http_error()[source]

Create a error http header.

do_http_success()[source]

Create a success http header.

do_json_header()[source]

Create a header for JSON messages

do_not_found()[source]

Create a not found http header.

do_post_processor()[source]

Handle the POST amd GET requests placed on the server.

get_content_type(file_name)[source]

Examines the extension of the file and determines what the content_type should be, defaults to text/plain Returns the extension and the content_type

Parameters:file_name – name of file
go_live(plugin_name)[source]

Go live on an item of type plugin.

Parameters:plugin_name – name of plugin
initialise()[source]

Initialise the router stack and any other variables.

main_image()[source]

Return the latest display image as a byte stream.

main_poll()[source]

Poll OpenLP to determine the current slide count.

plugin_info(action)[source]

Return plugin related information, based on the action.

Parameters:action – The action to perform. If search return a list of plugin names which support search.
poll()[source]

Poll OpenLP to determine the current slide number and item name.

process_http_request(url_path, *args)[source]

Common function to process HTTP requests

Parameters:
  • url_path – The requested URL.
  • args – Any passed data.
search(plugin_name)[source]

Return a list of items that match the search text.

Parameters:plugin_name – The plugin name to search in.
serve_file(file_name=None)[source]

Send a file to the socket. For now, just a subset of file types and must be top level inside the html folder. If subfolders requested return 404, easier for security for the present.

Ultimately for i18n, this could first look for xx/file.html before falling back to file.html. where xx is the language, e.g. ‘en’

serve_thumbnail(controller_name=None, dimensions=None, file_name=None)[source]

Serve an image file. If not found return 404.

Parameters:
  • file_name – file name to be served
  • dimensions – image size
  • controller_name – controller to be called
service(action)[source]

Handles requests for service items in the service manager

Parameters:action – The action to perform.
service_list()[source]

Handles requests for service items in the service manager

set_cache_headers()[source]
stages(url_path, file_name)[source]

Allow Stage view to be delivered with custom views.

Parameters:
  • url_path – base path of the URL. Not used but passed by caller
  • file_name – file name with path
Returns:

translate()[source]

Translate various strings in the mobile app.