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
| Parameter | Description |
|---|---|
deeplinksApp | Package name of the Android app to stream (e.g., com.example.mygame). |
deeplinksURI | Launch 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
| Parameter | Description |
|---|---|
userId / clientId | Your 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. |
locale | System language in Android locale format (e.g., en, zh, fr). Defaults to en. See the full Android locale reference. |
timestamp | Session URL expiration time, as seconds since epoch. Requests made after this time are rejected. |
duration | Maximum session length in seconds. The session is forcibly closed when this limit is reached. N2I can also enforce a maximum value server-side. |
inactivityDisconnectDelay | Inactivity 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. |
invisibilityDisconnectDelay | Invisibility 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. |
autofitOnConnect | No value required. Scales the app to fit the iframe/WebView dimensions at launch. Recommended when you cannot guarantee orientation matching. |
signature | HMAC-SHA1 request signature for server-side verification (see Signing requests below). |
graph | No 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 exceptsignature, 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×tamp=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×tamp=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 code0. - Open the URL
n2i://closeusingIntentorApplication.OpenURL().
Session Events
| Event | When it fires |
|---|---|
n2i_connected | The session has been allocated and the stream is connecting. |
n2i_ready | Streaming is active and the first frame is ready to display. |
n2i_disconnected | The session has ended (includes the reason and WebSocket close code). |
See Events and API for how to listen to these events.