P4JSAPI to P4V-JS Conversion Guide (2020.2)

Overview

The P4JSAPI is built on WebKit, the Web browser engine used by Safari on macOS and iOS. Qt moved off WebKit and adopted the Chromium browser technology, called WebEngine. The new rendering engine is better tuned for multi-processing, uses a smaller memory footprint, and has a larger development community, thus guaranteeing better support for HTML5 and newer JavaScript versions. Because QtWebKit and QtWebEngine are very different, Perforce is adopting a new approach to implementing the API.

Communication in QtWebKit is driven by the WebKit Bridge, a framework that extends WebKit’s JavaScript environment to access Qt Objects published to the bridge. The bridge requires P4V to embed WebPages; it injects JavaScript hooks into these pages. Calling P4JSAPI methods directly invokes methods in P4V. Synchronous function invocation is the default, but asynchronous coding needs to be facilitated.

QtWebEngine does not have a bridge. Instead, P4V embeds an HTTP server (only accepting localhost requests). A JavaScript file serves as the P4VJS API. Because the API is implemented in JavaScript and uses HTTP, you can develop P4VJSpages in your favorite browser, using your favorite development tools. However, because your HTTP server is only available while P4V runs, this strategy does not work for deployment. When you complete development, you are expected need to move these pages to P4V. The communication implements a request/reply model. Every request in the P4VJS API is implemented as a JavaScript Promise. Asynchronous function invocation is the default. A synchronous call can be emulated required, using the async and await keywords.

These different approaches require porting of existing P4JSAPI applications. This guide explains:

  • How to port existing code, in particular the syntax of formatting requests. The P4VJS data sent and returned is fully compatible with the formatting that the P4JSAPI expects.
  • Which P4JSAPI features are not ported to P4VJS. This version of P4VJS does not introduce new features to the API, but it does simplify the hosting of pages and adds more flexibility (for details, see Introduction to P4VJS).