# 2D replay viewer (/docs/api/embeds/replay-viewer)

Embed Strave's interactive 2D Rainbow Six Siege replay viewer using short-lived OIDC viewer sessions and @strave/replay-embed.

Strave's hosted 2D replay embed lets your website, match portal, or recap hub
render full Rainbow Six Siege rounds without shipping parser binaries, map
geometry, or raw `.rec` files.

## How it works [#how-it-works]

1. Your server authenticates to Strave Public API v2 with a **short-lived
   OIDC/OAuth 2.1 JWT access token** (Trusted Workload or OAuth 2.1 flow).
   Static `strave_sk_` API keys are rejected on this endpoint.
2. Your server calls `POST /api/v2/replays/{matchId}/{mapIndex}/viewer-sessions`
   with the exact `https://` origin of the page that will frame the viewer.
3. Strave returns a short-lived signed `embedUrl` (`60` to `900` seconds) bound
   to that match map and parent origin.
4. Your frontend mounts the iframe with `@strave/replay-embed`. Inside the
   iframe, Strave loads compressed `.stv` viewer files from Strave storage,
   enforces any live match playback delay, and displays the required
   **Powered by Strave** badge.

Viewer sessions need an Application owned by an organisation on the
Professional or Enterprise plan. This applies to Strave tournament matches and
esports matches. Other owners get `403 entitlement_required`. Use
[Sandbox mode](#test-for-free-in-sandbox-mode) to build and test without a
paid plan.

## Mint a viewer session on your backend [#mint-a-viewer-session-on-your-backend]

```ts
import { createStraveClient } from "@strave/sdk";
import { getVercelOidcToken } from "@vercel/oidc";

const strave = createStraveClient({
	oidcWorkload: {
		clientId: process.env.STRAVE_CLIENT_ID!,
		getAssertion: () =>
			getVercelOidcToken({ audience: "https://strave.gg/api/auth" }),
		scopes: ["event:read"],
	},
});

const { data: session } = await strave.replays.createViewerSession(
	"match_01K4ZN",
	0,
	{
		eventId: "event_01K4ZK",
		origin: "https://tournaments.example.com",
		ttlSeconds: 300,
		initialRound: 1,
	},
);
```

For official esports matches (`ubisoft-*`), omit `eventId`, request the
`esports:read` scope, and pass your active `installationId`.

## Mount and control the viewer in the browser [#mount-and-control-the-viewer-in-the-browser]

Install the thin controller package:

```bash
bun add @strave/replay-embed
```

### Plain TypeScript [#plain-typescript]

```ts
import { mountStraveReplayEmbed } from "@strave/replay-embed";

const player = mountStraveReplayEmbed({
	container: document.getElementById("replay")!,
	embedUrl: session.embedUrl,
	onEvent: (event) => {
		if (event.type === "ready") {
			player.setRound(1);
			player.setViewSettings({ playerPath: "trail", playerNames: "show" });
			player.play();
		}
	},
});
```

### React [#react]

```tsx
import { StraveReplayEmbed } from "@strave/replay-embed/react";

export function MatchReplay({ embedUrl }: { embedUrl: string }) {
	return (
		<div className="aspect-video w-full overflow-hidden rounded-xl border">
			<StraveReplayEmbed
				embedUrl={embedUrl}
				onEvent={(event) => {
					if (event.type === "roundChange") {
						console.log("Now showing round", event.round);
					}
				}}
			/>
		</div>
	);
}
```

## Supported commands and events [#supported-commands-and-events]

| Direction      | Name                          | Payload                                                                                                   |
| -------------- | ----------------------------- | --------------------------------------------------------------------------------------------------------- |
| Host to iframe | `play`, `pause`, `togglePlay` | None                                                                                                      |
| Host to iframe | `setRound`                    | `{ round: number }`                                                                                       |
| Host to iframe | `seekTick` / `seekSeconds`    | `{ tick: number }` or `{ seconds: number }`                                                               |
| Host to iframe | `setSpeed`                    | `{ speed: 0.5 \| 1 \| 2 \| 4 }`                                                                           |
| Host to iframe | `setViewSettings`             | `playerNames`, `heatmap`, `playerPath`, `gadgetVisibility`, `dronePath`, `roundEndBanner`, `followPlayer` |
| Host to iframe | `selectEntity`                | `{ entityId: string \| null }`                                                                            |
| Iframe to host | `ready`                       | `matchId`, `mapIndex`, `mode`, `mapName`, `rounds`, `protocolVersion`                                     |
| Iframe to host | `state`                       | `currentRound`, `tick`, `seconds`, `durationSec`, `playing`, `speed`, `live`, `selectedEntity`            |
| Iframe to host | `roundChange`                 | `round`, `tickMin`, `tickMax`, `durationSec`, `activeBombSite`                                            |
| Iframe to host | `timeUpdate`                  | `round`, `tick`, `seconds`, `durationSec`, `playing`                                                      |

## Test for free in Sandbox mode [#test-for-free-in-sandbox-mode]

Mint a Sandbox 2D replay session with no paid plan and no credentials. Sandbox
sessions accept `http://localhost:*` origins. Every Sandbox session plays all 12
rounds of one recorded map from a real Strave match inside `/embed/replay`,
whatever match ID you send:

```ts
import { createStraveClient } from "@strave/sdk";

const sandbox = createStraveClient({ sandbox: true });
const { data: session } = await sandbox.replays.createViewerSession(
	"match_sbx_llh_vs_camaron",
	0,
	{ origin: "http://localhost:3000" },
);
```