espressostreamdocs
On this page

Embedding and oEmbed

Public and unlisted recordings can be shown on other websites. Private recordings can't, not even by their owner.

Embed code

A public recording's page has an Embed panel with code you can copy. The owner also sees this panel on unlisted recordings. The code is an iframe:

<iframe src="https://casts.example.org/e/RECORDING_ID" width="720" height="460"
        title="My recording" loading="lazy" allowfullscreen style="border:0"></iframe>

/e/<id> is a bare page with only the player. The height is worked out from the recording's terminal size, plus room for the controls. Change width and height as you like; the terminal scales to fit.

What the embed page does and doesn't do:

  • It sets no cookies and doesn't know who is watching. This is why private recordings are never embeddable.
  • It has its own Content-Security-Policy. Who may frame it is set by the server's --embed-ancestors (default *, any site). Set it to something like 'self' https://blog.example.org to allow only your own sites.
  • Every other page of the server refuses to be framed.

oEmbed

Sites and tools that support oEmbed only need the recording's link. Recording pages have a discovery link:

<link rel="alternate" type="application/json+oembed"
      href="https://casts.example.org/oembed?url=https%3A%2F%2Fcasts.example.org%2Fr%2FRECORDING_ID">

The endpoint:

GET /oembed?url=<recording URL>[&maxwidth=N][&maxheight=N]

url must be a /r/<id> or /e/<id> URL on this server. The response is a JSON rich type:

{
  "version": "1.0",
  "type": "rich",
  "provider_name": "espressostream",
  "provider_url": "https://casts.example.org/",
  "title": "My recording",
  "author_name": "alice",
  "author_url": "https://casts.example.org/u/alice",
  "html": "<iframe src=\"https://casts.example.org/e/RECORDING_ID\" …></iframe>",
  "width": 720,
  "height": 460
}

maxwidth and maxheight shrink the iframe and keep the terminal's aspect ratio. Errors:

Status When
404 another host, an unknown id, a private recording, or a URL that isn't a recording
501 format=xml (only JSON is supported)

Using the player directly

To host the player on your own pages without an iframe, copy player.js, player-webgl.js, player-image.js and player.css from the server's /static/player/, or build them from player/. Keep the three scripts in the same directory; the player loads the other two only when it needs them.

<link rel="stylesheet" href="/assets/player.css">
<script src="/assets/player.js" defer></script>
<espresso-player src="/casts/demo.cast" theme="auto"></espresso-player>
Attribute Meaning
src URL of the .cast file (fetched with the page's cookies, so serve it from the same site)
speed playback speed, 0.1–16 (default 1)
idle-limit shorten pauses to this many seconds (default: the recording's own setting)
autoplay, loop on/off attributes
poster time in seconds of the frame shown before playback; without it the player shows the first frame that has something on screen
theme auto (follows the system's light/dark setting), dark, light, or recording (the recording's own colours)
trace URL of an exec trace (.trace.jsonl) to show alongside
live WebSocket URL of a live stream (instead of src)
fill the page sets the player's height and the terminal fits into it
no-webgl always use the DOM renderer

JavaScript: play(), pause(), seek(seconds), currentTime, duration, markers. Events: play, pause, seeked, ended, timeupdate, markers.

Keys, when the player has focus: space play/pause, ←/→ 5 seconds back/forward, 0–9 jump to 0–90 %, [/] previous/next chapter, c chapter list, f fullscreen, </> slower/faster.

Watching a live stream, you can pause and go back through what the player has received so far (space, ←, the seek bar). While you're behind, a Live · behind by 12s button replaces the LIVE badge: click it or press L to jump back to the live edge. Playing on catches up by itself at a speed above 1×. The player keeps about the last 2 MB of output for this, so on a very busy stream the oldest part drops off, and if you stay paused long enough for the buffer to fill, it jumps back to live. A reconnect starts over.

The player works under a strict Content-Security-Policy with no inline scripts or styles. Sixel and iTerm2 images need 'wasm-unsafe-eval' in script-src. Without it, recordings play without their images.