»HyBridge: an open-source framework for QGIS desktop - Web Application interoperability.«
2019-06-25, 17:00–17:15, Room 2

We implemented a web-socket server into QGIS, creating fully asynchronous and stateful bidirectional communication channel between QGIS plugins and web applications, therefore making it possible to drive QGIS functionalities from web applications and vice versa when available.

QGIS uses the QtWebKit widget to allow plugins to integrate with remote web applications, however this approach has some drawbacks: in particular the QtWebKit widget cannot be updated by the user and can be rapidly become rather outdated compared with the latest versions of popular browsers. This makes it difficult to use the most recent versions of some JavaScript frameworks. In order to address this problem, we have developed a framework to open a bidirectional communication channel between an external web browser and QGIS, thus allowing us to enhance a standard web-application with QGIS-related functionalities. The web application is able to detect the availability of a QGIS instance using client-side JavaScript code and also server-side via a custom HTTP header. In this way, a web-application can provide additional features for QGIS-enhanced browsers that would not be visible otherwise. To be able to provide the same level of integration compared to the QtWebKit approach we decided, as a first step, to develop a Chrome extension to manage browser windows and tabs. The Chrome extension allows QGIS Plugin Python code to identify and reuse existing instances of web-pages associated with a QGIS scope. It also allows JavaScript code running in web pages to communicate with QGIS. The Chrome extension provides also a way to route messages for different QGIS scopes via a single channel to QGIS, centralizing QGIS detection and connection retries when necessary. For example, GEM has used this solution to integrate a web application IPT, that assists the user in the preparation of input files for the OpenQuake engine with the GEM IRMT plugin. Using HyBridge the IPT can send the input files directly to the engine rather than having the use save the file to a local disk and then upload it to the engine manually. The framework leverages a Python websocket server inside GEM’s IRMT QGIS plugin that uses signals to interface with the rest of QGIS to provide a fully asynchronous and bidirectional API with support for multiple responses to a single command, allowing long-running operations to provide intermediate results and/or progress update notifications. Each QGIS scope can extend the API independently. We intend to continue development of this framework, in particular we plan to remove the dependency on a browser-specific extension while still providing the same functionality. The software components are available under the terms of an open-source licence. QGIS plugin including HyBridge extension: