This document explains how the Controller application leverages RCWeb technology to send real-time JavaScript instructions to a Viewer.
The Control app (c) is the "Sender" in the Asymmetric (Sender/Viewer) pattern.
It provides a UI (buttons, textareas, file inputs) for humans to interact with, and converts those
interactions into JavaScript strings that actuate change in the Viewer app (v).
rc.send(js, "v"). The
"v" target ensures that only clients running the viewer app in the same room receive and
execute the payload.rc.onViewUpdateSuccess
and rc.onViewUpdateError to receive confirmation from the viewer that a command was
handled.The controller features a raw JavaScript editor that allows sending arbitrary code directly to the viewer:
function sendJavaScriptArea() {
rc.send(document.getElementById("js").value, "v");
}
The controller demonstrates two ways to share files with the viewer via the createDynamicFileUrl
helper:
/x-file/...) and sent to the viewer. When the viewer's browser tries to load
this URL, the server requests chunks from the controller via rc.sendFileChunk, which are
uploaded via PUT requests.The controller can "switch" the entire room to a different dedicated RCWeb application (like Spacewar or Drums) by sending a redirect command to all non-controller clients:
function showApp(viewerApp, controlsApp) {
var viewerAppUrl = "/" + viewerApp + "/?r=" + rc.room;
var js = "document.location.href='" + viewerAppUrl + "';";
// Send to all clients except other controllers
rc.send(js, "!c");
// Redirect local controller too
window.location.href = "/" + controlsApp + "/?r=" + rc.room;
}
The Controller app is a powerful example of how RCWeb can turn a mobile device into a versatile remote for digital signage, games, or collaborative workspaces. By focusing on intent-based messaging (sending JavaScript) rather than state synchronization, it keeps the logic simple and the interaction immediate.