Frontend IntegrationSessions

Sessions

Start and stop N2I streaming sessions using URL parameters, including authentication, timeouts, and request signing.

Starting a Session

Load the following URL in your iframe or WebView to start a streaming session: https://project-xyz.k8s.n2i-cloud.com/?deeplinksApp=<package>&deeplinksURI=<encoded-intent>[&optional-params]

All parameter values must be URL-encoded.


Required Parameters

ParameterDescription
deeplinksAppPackage name of the Android app to stream (e.g., com.example.mygame).
deeplinksURILaunch intent URI. Use null%3A%2F%2F (URL-encoded null://) for a default launch, or a specific deeplink URI to open a particular screen or level.

Optional Parameters

ParameterDescription
userId / clientIdYour system's identifier for the end user. Pass the same value across sessions to persist progress, restore profiles, and link in-game state to your backend. If omitted, N2I creates one automatically using a browser cookie — but this identifier is lost if the user switches device or browser.
localeSystem language in Android locale format (e.g., en, zh, fr). Defaults to en. See the full Android locale reference.
timestampSession URL expiration time, as seconds since epoch. Requests made after this time are rejected.
durationMaximum session length in seconds. The session is forcibly closed when this limit is reached. N2I can also enforce a maximum value server-side.
inactivityDisconnectDelayInactivity timeout in milliseconds. The timer resets on every user input. The session closes when the timer expires. N2I can enforce a maximum value server-side.
invisibilityDisconnectDelayInvisibility timeout in milliseconds. The timer starts when the page becomes hidden (e.g., the user switches tabs). The session closes when the timer expires. N2I can enforce a maximum value server-side.
autofitOnConnectNo value required. Scales the app to fit the iframe/WebView dimensions at launch. Recommended when you cannot guarantee orientation matching.
signatureHMAC-SHA1 request signature for server-side verification (see Signing requests below).
graphNo value required. Displays a real-time network statistics overlay. For testing only — do not use in production.

Signing Requests

Add a signature parameter to prevent session URL tampering. The signature covers all other query parameters, so any modification to the URL invalidates it.

Algorithm:

signature = base64( HMAC_SHA1( sorted_query_string, secret_key ) )
  • sorted_query_string — all query parameters except signature, sorted alphabetically by name, joined with &.
  • secret_key — the signature key provided by N2I for your project.
  • URL-encode the resulting signature value and append it as the last query parameter.

Example

Session URL for Candy Crush, user 00001, expires at timestamp 1714514400, maximum duration 4 hours (14400 s): https://project-xyz.k8s.n2i-cloud.com/?deeplinksApp=com.king.candycrushsaga&deeplinksURI=null%3A%2F%2F&autofitOnConnect&userId=00001&timestamp=1714514400&duration=14400&signature=MSHuvGdVWFRz579e%2BoJoI6y8U%2BI%3D

Signature input (parameters sorted alphabetically, secret key 0123456789abcdef):

base64(HMAC_SHA1(
  "autofitOnConnect&deeplinksApp=com.king.candycrushsaga&deeplinksURI=null%3A%2F%2F&duration=14400&timestamp=1714514400&userId=00001",
  "0123456789abcdef"
))

Keep your signature key secret. Never expose it in client-side code or public repositories.


Stopping a Session

From the client

Navigate the iframe or WebView to a blank page:

// iframe
document.getElementById("n2i-iframe").src = "about:blank";

// Android WebView
myWebView.loadUrl("about:blank");

From the streamed app

The streamed Android app can close its own session in two ways:

  • Call System.exit(0) or finish the main activity with exit code 0.
  • Open the URL n2i://close using Intent or Application.OpenURL().

Session Events

EventWhen it fires
n2i_connectedThe session has been allocated and the stream is connecting.
n2i_readyStreaming is active and the first frame is ready to display.
n2i_disconnectedThe session has ended (includes the reason and WebSocket close code).

See Events and API for how to listen to these events.