Cloud Synchronization Process: Step by Step

At a high level, the Cloud synchronization process involves the following steps:

  1. The client is launched on the device.
  2. The client connects to the server over TCP.
  3. The client receives the initial screen from the server.
  4. The client is initialized and is in a usable state.

This topic provides more detail on the synchronization process. See also Cloud Client and Server Synchronization Overview.

End-to-end process

The following steps describe the end-to-end process in a Cloud app that results in a change of the client screen.

1. A client event is sent to the server

The end-to-end process begins with an event occurring within the client:

  • An event occurs on the client device, such as a key press on the remote control unit or a video playback event.
  • The client decides whether the event can be handled within the client code on the device, and one of the following occurs:
    • The process ends.
    • The event is forwarded to the server for processing.

2. The event is processed on the server

  • The server receives the event from the client and notifies the You.i Roku Cloud app about the event.
  • The You.i Roku Cloud app processes the event as if it were initiated locally.
  • The You.i Roku Cloud app may make structural changes to the SceneTree, make property changes to nodes in the SceneTree, or execute custom code that corresponds to a custom event.
  • When the Cloud SDK detects a structural change to the current SceneTree, it determines the minimal number of changes that must be communicated to the client.
  • When the Cloud SDK detects property changes to nodes in the current SceneTree, it determines the node property changes that must be communicated to the client.

3. The server response is created

The Cloud SDK creates a JSON object containing the serialized representation of one of the following:

  • A top-level node, containing other nodes to add or remove from the client screen
  • A collection of nodes that require property updates on the client screen

4. The server response is sent to the client

The completed JSON object is sent to the client via TCP.

5. The client processes the server response

The client receives the JSON object and:

  • Transforms the JSON object into a local BrightScript object.
  • Updates the local SceneGraph object using actions defined in the new BrightScript object.
  • Displays the resulting screen, based on the updated SceneGraph object.

Events on the client that trigger synchronization

The following are examples of client events that trigger synchronization on the server.

Structural changes

  • Screen navigation
  • Creation or deletion of a modal component (a popup dialog box)
  • Addition of list items as they’re scrolled into view
  • Removal of list items as they’re scrolled out of view

Property updates

  • Component color or font change
  • Button animation, when pressed or released

Efficient synchronization

The Cloud app must update screens on the client very efficiently. There can be overhead due to network delay during synchronization, and low-end client devices may have limited CPU and memory resources.

The Cloud SDK handles the transformation of SceneTree nodes into serialized JSON representations of client nodes.

  • For addition and removal of nodes within the SceneTree, the Cloud SDK:
    • Determines the highest-level node in the You.i Platform SceneTree that encompasses the add/remove actions for all affected SceneTree nodes.
    • Creates a JSON object with a top-level node that contains all the other affected nodes and their associated actions.
  • For property updates to nodes within the SceneTree, the Cloud SDK:
    • Creates a JSON object containing a collection of individual nodes with property updates.
    • Adds an equivalent node to the JSON object, using the specific node ID, for each SceneNode that requires property updates.