Skip to main content

Working with Native Nodes

Create and control Roku nodes directly using CreateObject("roSGNode", "NodeType"), then observe fields for changes.

Create SG Nodes and Observe Fields

Keyboard dialog setup (excerpt):

this.dialog = CreateObject('roSGNode', 'StandardKeyboardDialog');
// ... configure fields
this.dialog.observeFieldScoped('buttonSelected', this.onKeyboardDialogButtonSelected.bind(this));
this.dialog.observeFieldScoped('wasClosed', this.onDialogClose.bind(this));

Request For Information (RFI) via ChannelStore:

export function showRFIScreen<T>(context = SGRequestForInformationContextType.SignIn, requestedUserData: string = 'email'): HsPromise<T> {
return new HsPromise<T>((resolve) => {
const channelStore = CreateObject<ISGNChannelStore>('roSGNode', 'ChannelStore');
const requestInfo = CreateObject<ISGNContentNode>("roSGNode", "ContentNode")
requestInfo.addFields({ context: context })
channelStore.setFields({ requestedUserDataInfo: requestInfo, requestedUserData });
channelStore.observeFieldScoped('userData', () => resolve(channelStore.userData as T));
channelStore.command = SGNChannelStoreCommands.GetUserData;
})
}

Create Non-SG Nodes

You can also create non-SG objects (e.g., roByteArray) for system tasks:

export function base64UrlEncode(value: any): any {
if (typeof value === 'string') {
const ba: any = CreateObject("roByteArray");
ba.FromAsciiString(value);
const encoded = ba.ToBase64String();
return encoded.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
} else {
return null;
}
}

Platform Global and Scene Access

Use @platformGlobal to access a platform-global variable from anywhere in your class:

@platformGlobal
private __hs_global!: any;

From views and app code, you can access the current scene (implements IHosannaScene) through the app or injected services; in many places it’s available as a field on services and the app to interact with top-level SG state.

Tips

  • Prefer SG nodes for UI and observe fields with observeFieldScoped for lifecycle-safe handlers.
  • For platform services, prefer IoC (AppUtils.resolve) and decorate globals with @platformGlobal sparingly.
  • Always clean up observers when the owning object is disposed.