-
Notifications
You must be signed in to change notification settings - Fork 258
Document frontend library usage and examples #131
Comments
Most of it seems to be there with the old docs. Some things to consider however:
|
When we get round to this. Here are some preliminary notes from the SPS team that may be relevant with some cleanup. OverviewUnderstanding the frontend architecture and event lifecycleThe process of communicating with the Scalable Pixel Streaming backend server components to initiate a streaming session and then establish a WebRTC connection between the frontend and a Pixel Streaming application instance is relatively complex, and follows a series of distinct phases that typically occur one after another in a linear sequence. The frontend library abstracts away the underlying details of this process within the The delegate implementation is responsible for responding to these lifecycle events and managing the UI state of the webpage to reflect the current state of the streaming session. This includes displaying information or errors to the user, registering event handlers for user input events, and invoking methods of the player controller to trigger parts of the lifecycle that are dependent on user input. Control flow is managed by the player controller during all lifecycle phases except for the initial Setup Phase, during which control flow briefly becomes the responsibility of the delegate. The diagram below depicts all of the lifecycle events that the delegate can respond to, along with the control flow between the player controller and the delegate: {% include figure.html A high-level overview of the core logic for each phase, along with the corresponding lifecycle events, are described in the sections below. Setup Phase
WebRTC Connection Phase{% include alerts/info.html content="For a detailed explanation of the process of establishing a WebRTC connection, see the section Establishing a Peer-to-Peer Connection in the WebRTC chapter of the excellent textbook High Performance Browser Networking by Ilya Grigorik, which is freely available online and is licensed under a Creative Commons license." %}
Streaming Phase
Disconnect Phase
Understanding overlaysOverlay controllers are the entities in the frontend library which are responsible for creating, displaying and hiding the various types of overlays supported by the frontend. The frontend library ships with default implementations for all of the supported overlay controllers, each of which can be extended or replaced by developers in order to customise overlay appearance and behaviour. Overlay controllers also have their own interfaces, through which both delegates and the player controller can manipulate overlay UI elements. Public properties that reference each type of overlay controller interface form part of the API contract for the delegate interface. The relationship between delegates and their overlay controllers is depicted in the diagram below: {% include figure.html Every delegate must contain an instance of each of the three supported types of overlay controllers. The constructor of the [DelegateBase]({{ site.data.links.frontend.github }}/blob/v{{ site.data.versions.frontend }}/library/src/Delegate/DelegateBase.ts) base class instantiates the default implementations for each of the overlay controllers, and delegate implementations that extend the base class may choose to replace one or more of these with instances of custom overlay controller implementations. Delegate implementations that implement the [IDelegate]({{ site.data.links.frontend.github }}/blob/v{{ site.data.versions.frontend }}/library/src/Delegate/IDelegate.ts) interface directly are responsible for instantiating all three overlay controller objects, irrespective of whether the defaults are used or custom implementations are provided. (Note that it is strongly recommended that delegate implementations extend the base class rather than implementing the interface directly. See the Getting started writing a delegate implementation section below for a discussion of the benefits provided by the base class.) The frontend supports a variety of different overlays that are used throughout the event lifecycle. Rather than representing every individual type of overlay with a corresponding controller, overlays are grouped into three controller classes, each of which is discussed in turn below. Overlay ControllerThe main overlay controller (known simply as "the overlay controller") provides the core functionality for creating, hiding and showing overlays that is used by both itself and the other two overlay controllers. This controller is responsible for managing all of the standard overlays that are used throughout the event lifecycle, including:
(TODO: why do we require two separate user interactions when one should theoretically be sufficient to meet the criteria for playing media streams? If the connect overlay is an optional step in scenarios where the play overlay is used, should we have a configuration option to disable it that is separate from the autoplay option?) AFK Overlay ControllerThe AFK overlay controller is responsible for displaying the AFK overlay, which is displayed when user inactivity detection is enabled and the user remains idle for the configured number of seconds, as discussed in the section Configuring library behaviour. (TODO: why does the AFK overlay controller contain the actual business logic of the AFK functionality (i.e. the detection timers) in addition to the logic for presenting the overlay UI? These concerns should be separated and the business logic should be moved to the player controller or its internal components. Once the business logic has been removed, the question then becomes whether the UI code could simply be merged into the main overlay controller?) Freeze Frame Overlay ControllerPixel Streaming applications can be configured to support an optional feature known as freeze frames, whereby rendering is temporarily paused and the video stream is replaced with a static image. When interacting with a Pixel Streaming application that supports freeze frames, the freeze frame overlay controller is responsible for displaying these static images. (TODO: the freeze frame overlay controller also combines business logic with UI code. Should this be refactored in the same manner as the AFK overlay controller, or are there unique characteristics of this class that mean the refactor should be handled in a different manner?) Getting started writing a delegate implementationWhen writing a new delegate implementation, it is strongly recommended that you extend the [DelegateBase]({{ site.data.links.frontend.github }}/blob/v{{ site.data.versions.frontend }}/library/src/Delegate/DelegateBase.ts) base class rather than directly implementing the [IDelegate]({{ site.data.links.frontend.github }}/blob/v{{ site.data.versions.frontend }}/library/src/Delegate/IDelegate.ts) interface. The base class provides the following functionality:
The easiest way to get started is to take a look at one of the [example delegate implementations]({{ site.data.links.frontend.github }}/blob/v{{ site.data.versions.frontend }}/delegates/examples) that are included with the frontend source code on GitHub and then modify the example to suit your needs. The production-ready nature of the DOM API delegate implementation makes it less suited for use as a learning resource or a minimal starting point, but it is still designed to be easily modifiable by developers who simply wish to tweak one or more aspects of its behaviour. (TODO: update the example delegate implementations to reflect the recent refactor and add them to the GitHub repo) |
This PR #132 has some excellent information that we can roll into our update of this page: |
We have added frontend docs in a number of PRs, I will close this uber ticket and we can address any missing docs on a case by case basis. |
We would like to the following for 5.2:
The text was updated successfully, but these errors were encountered: