UNPKG

react-player

Version:

A React component for playing a variety of URLs, including file paths, YouTube, Facebook, Twitch, SoundCloud, Streamable, Vimeo, Wistia and DailyMotion

109 lines (108 loc) 3.19 kB
var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => { __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); return value; }; import React, { Component } from "react"; import { callPlayer, getSDK } from "../utils.js"; import { canPlay, MATCH_URL_VIDYARD } from "../patterns.js"; const SDK_URL = "https://play.vidyard.com/embed/v4.js"; const SDK_GLOBAL = "VidyardV4"; const SDK_GLOBAL_READY = "onVidyardAPI"; class Vidyard extends Component { constructor() { super(...arguments); __publicField(this, "callPlayer", callPlayer); __publicField(this, "mute", () => { this.setVolume(0); }); __publicField(this, "unmute", () => { if (this.props.volume !== null) { this.setVolume(this.props.volume); } }); __publicField(this, "ref", (container) => { this.container = container; }); } componentDidMount() { this.props.onMount && this.props.onMount(this); } load(url) { const { playing, config, onError, onDuration } = this.props; const id = url && url.match(MATCH_URL_VIDYARD)[1]; if (this.player) { this.stop(); } getSDK(SDK_URL, SDK_GLOBAL, SDK_GLOBAL_READY).then((Vidyard2) => { if (!this.container) return; Vidyard2.api.addReadyListener((data, player) => { if (this.player) { return; } this.player = player; this.player.on("ready", this.props.onReady); this.player.on("play", this.props.onPlay); this.player.on("pause", this.props.onPause); this.player.on("seek", this.props.onSeek); this.player.on("playerComplete", this.props.onEnded); }, id); Vidyard2.api.renderPlayer({ uuid: id, container: this.container, autoplay: playing ? 1 : 0, ...config.options }); Vidyard2.api.getPlayerMetadata(id).then((meta) => { this.duration = meta.length_in_seconds; onDuration(meta.length_in_seconds); }); }, onError); } play() { this.callPlayer("play"); } pause() { this.callPlayer("pause"); } stop() { window.VidyardV4.api.destroyPlayer(this.player); } seekTo(amount, keepPlaying = true) { this.callPlayer("seek", amount); if (!keepPlaying) { this.pause(); } } setVolume(fraction) { this.callPlayer("setVolume", fraction); } setPlaybackRate(rate) { this.callPlayer("setPlaybackSpeed", rate); } getDuration() { return this.duration; } getCurrentTime() { return this.callPlayer("currentTime"); } getSecondsLoaded() { return null; } render() { const { display } = this.props; const style = { width: "100%", height: "100%", display }; return /* @__PURE__ */ React.createElement("div", { style }, /* @__PURE__ */ React.createElement("div", { ref: this.ref })); } } __publicField(Vidyard, "displayName", "Vidyard"); __publicField(Vidyard, "canPlay", canPlay.vidyard); export { Vidyard as default };