Embed with an iframe

Put an Eagle 3D Streaming stream in an iframe on your page. The Control Panel gives you the script; you paste it in and talk to the frame with messages.

The examples here are plain HTML, and the approach is identical in React, Angular, Vue or anything else — an iframe is an iframe.

Embed it

  1. Copy the iframe script from the Control Panel

    Choose the app, choose a configuration, and copy the streaming iframe script. It already contains the URL for that app and configuration, so there is nothing to assemble by hand.

  2. Paste it into your page

    <html>
      <head><title>Demo</title></head>
      <body>
        <div>
          <!-- the copied iframe script goes here -->
        </div>
      </body>
    </html>

    The copied script already gives the iframe id="iframe_1", which everything else on this page uses to address the frame, and allowfullscreen, without which fullscreen does not work at all.

    If your app uses the microphone, add allow="microphone" to the tag yourself — the copied script does not include it, and without it the browser never offers the microphone to the frame. See choose the microphone.

You will know it worked when

Your page shows the stream, and pressing play starts the app.

What the frame tells your page

The frame tells your page how far along the session is, which is what lets you build your own loading experience instead of the default one. Each step arrives as a message whose type you can switch on:

window.addEventListener("message", function (e) {
  // only listen to the stream itself: compare e.origin with your streaming domain
  switch (e.data && e.data.type) {
    case "session.queued":   /* your loading screen; e.data.queuePosition */ break;
    case "stream.playing":   /* hide it */ break;
    case "session.ending":   /* your ending screen; e.data.message */ break;
  }
});
Message typeWhat has happened
session.queuedThe viewer is waiting for a machine. Carries queuePosition, their place in the queue.
session.hostFound, then session.hostReservedA machine was found and held for the viewer. Sent together - treat them as one moment.
build.acquiring, build.preparingYour app is being copied, then prepared. Carry percent.
stream.readyReady to play; the browser may be waiting for a click before it starts video.
build.listeningYour app can receive data from your page.
stream.playingThe video is playing.
session.endingThe session is ending, for any reason; message says which.

Every event, its fields and its order - including the queue position as it changes, progress, and how to tell a crash from a timeout - is on Your own loading and ending screens. A Web SDK page receives the very same events.

Password-protected configurations

When the configuration has a start password, the stream shows its own password box before session.queued. If your page covers the iframe with a loading screen, the viewer would never see that box, so the iframe tells your page about it:

MessageWhat has happenedWhat your page should do
passwordRequestedThe password box is on screen, waiting for the viewer.Hide your loading screen (or move it aside) so the box can be seen.
passwordAcceptedThe password was right; the stream continues with session.queued.Bring your loading screen back if you want.

A configuration without a password never sends these two messages.

Talking to the app

Messages go to the frame with postMessage, and a message to your Unreal app must carry cmd: "sendMessageToStreamingBuild" or the frame will not forward it. See sending and receiving data for both directions, and controlling the stream for quality, resolution and fullscreen.

In this section

Related

Last updated