SporfieSporfie
    Pricing
    Contact
    SporfieSporfie

    The complete video platform for sports.

    • Facebook
    • Instagram
    • X
    • YouTube

    Platform

    • Features
    • Pricing
    • Shop
    • Blog
    • API

    Legal

    • Terms of Use
    • Privacy Policy
    • Community Guidelines

    Get in touch

    • +1 480 584 0197
    • contact@sporfie.com
    • Contact
    • Service Status
    • Support

    © 2026 Sporfie. All rights reserved.

    Pricing
    Contact
    Documentation
    Embed
    • Configuration
    • Messaging API
    • Classic EmbedDeprecated
    Sporfie API documentation

    Embed Player Messaging API

    The Sporfie player embedded in an iframe and the page around it talk to each other with the postMessage() API. Two messages exist:

    • sporfie:request-absolute-timestamp: your page asks the player for the absolute timestamp of the content it is playing.
    • sporfie:playback-ended: the player tells your page that the video is over, so you can show a countdown, change page or load the next video.

    Absolute timestamp

    Your page sends a request to the iframe, and the player replies with the absolute timestamp of the content on screen.

    Type Definitions

    ts
    type TimestampRequest = {  version: 1;  type: "sporfie:request-absolute-timestamp";  requestId?: string;}; type TimestampResponse = {  version: 1;  type: "sporfie:absolute-timestamp";  requestId?: string;  eventKey: string | null;  absoluteTimestampMs: number | null;  absoluteTimestampIso: string | null;  error?: "not-ready" | "unresolved";  emittedAtMs: number;};

    Implementation Example

    ts
    const iframe = document.querySelector("iframe");const sporfieOrigin = "https://www.sporfie.com"; // requestId is optional – set it if you have multiple embeds, repeated requests.const requestId = `request-${Date.now()}`; const request = {  version: 1,  type: "sporfie:request-absolute-timestamp",  requestId,}; iframe?.contentWindow?.postMessage(request, sporfieOrigin); window.addEventListener("message", (event) => {  if (event.origin !== sporfieOrigin) return;   const data = event.data as TimestampResponse;  if (data.type !== "sporfie:absolute-timestamp") return;   // Only check requestId if you sent one.  if (request.requestId && data.requestId !== request.requestId) return;   console.log("Timestamp ms:", data.absoluteTimestampMs);  console.log("Timestamp ISO:", data.absoluteTimestampIso);  console.log("Error:", data.error ?? null);});

    Playback ended

    The player posts this message to the page that hosts the iframe when the video reaches its end and nothing else is about to play. There is nothing to request and nothing to subscribe to: a message listener is the whole callback.

    Type Definition

    ts
    type PlaybackEndedEvent = {  version: 1;  type: "sporfie:playback-ended";  eventKey: string | null;  item: string | null;  emittedAtMs: number;};

    item says what ended, with the values of the item URL option: a clip key, highlights or a highlight reel key. null is the event itself (its replay).

    Countdown Example

    A countdown shown by your page when the video ends, followed by the next video, as on a playlist page:

    ts
    const iframe = document.querySelector("iframe");const upNext = document.querySelector("#up-next");const sporfieOrigin = "https://www.sporfie.com"; // What plays next is your decision: any embed URL, or a page of your site.const nextEmbedUrl =  "https://www.sporfie.com/embed/-Oab1cD2eF?item=<clipKey>&autoplay=true"; window.addEventListener("message", (event) => {  if (event.origin !== sporfieOrigin) return;  if (event.source !== iframe.contentWindow) return;   const data = event.data as PlaybackEndedEvent;  if (data.type !== "sporfie:playback-ended") return;   let secondsLeft = 5;  upNext.textContent = `Next video in ${secondsLeft}`;  upNext.hidden = false;   const timer = setInterval(() => {    secondsLeft -= 1;    upNext.textContent = `Next video in ${secondsLeft}`;    if (secondsLeft > 0) return;     clearInterval(timer);    upNext.hidden = true;    // Load the next video in the same iframe...    iframe.src = nextEmbedUrl;    // ...or change page: window.location.href = nextPageUrl;  }, 1000);});

    When It Is Sent

    • At the end of a replay: its last recording played to the end.
    • At the end of a clip or of the highlights reel, when nothing follows it. That is the default for an item opened on an /embed/ URL, which plays alone.
    • Not while the player carries on by itself: with loop=true, between the rates of a speed list (the message follows the last one), when autoplayNextClip moves on to the next clip, or when the replay resumes behind a clip the viewer opened.
    • Not at the end of a sponsor ad, and not when a live stream stops.
    • Once per play-through: a viewer who plays the video again gets a new message at its end.

    Implementation Notes

    • Use an explicit Sporfie origin in postMessage, never "*", and check event.origin on every message you receive. It is the origin of your iframe's src
    • The iframe replies to a timestamp request only on event.source, using event.origin
    • requestId is optional, but useful for matching responses
    • error: "not-ready" means the player is not ready yet
    • error: "unresolved" means the player cannot safely map the current playback position to a real absolute time
    • With several players on one page, event.source tells which iframe a message comes from
    • For the next video to start by itself, add autoplay=true to its URL
    • The classic player (/event/:eventKey/embed/classic, retiring at the end of 2026) answers timestamp requests but does not send sporfie:playback-ended

    Embed player messaging demo

    Load an embedded player, request its current absolute timestamp via postMessage, and watch the playback-ended message arrive when the video finishes.

    Embed URL
    Enter an event key to load the iframe.
    Load an event to render the embed iframe.

    Event log

    0
    No messages yet.