Home / Class/ MediaEvents Class — react Architecture

MediaEvents Class — react Architecture

Architecture documentation for the MediaEvents class in index.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  17fec3ba_276a_1297_1e4a_0db6ba58a1a9["MediaEvents"]
  25ef52bb_f0a9_64ed_5864_285651c93cc8["index.js"]
  17fec3ba_276a_1297_1e4a_0db6ba58a1a9 -->|defined in| 25ef52bb_f0a9_64ed_5864_285651c93cc8
  18750f37_3eca_5477_6d90_b038b1622a7c["eventDidFire()"]
  17fec3ba_276a_1297_1e4a_0db6ba58a1a9 -->|method| 18750f37_3eca_5477_6d90_b038b1622a7c
  8c50caa7_bd69_1119_16e6_12e3c2576c4d["getProgress()"]
  17fec3ba_276a_1297_1e4a_0db6ba58a1a9 -->|method| 8c50caa7_bd69_1119_16e6_12e3c2576c4d
  633b4ecd_b74f_99cf_a61c_f58be345283a["render()"]
  17fec3ba_276a_1297_1e4a_0db6ba58a1a9 -->|method| 633b4ecd_b74f_99cf_a61c_f58be345283a
  94b7dcad_952e_317a_3b4f_cacd942a7b70["renderOutcome()"]
  17fec3ba_276a_1297_1e4a_0db6ba58a1a9 -->|method| 94b7dcad_952e_317a_3b4f_cacd942a7b70

Relationship Graph

Source Code

fixtures/dom/src/components/fixtures/media-events/index.js lines 6–122

export default class MediaEvents extends React.Component {
  state = {
    playbackRate: 2,
    events: {
      onCanPlay: false,
      onCanPlayThrough: false,
      onDurationChange: false,
      onEmptied: false,
      onEnded: false,
      onError: false,
      onLoadedData: false,
      onLoadedMetadata: false,
      onLoadStart: false,
      onPause: false,
      onPlay: false,
      onPlaying: false,
      onProgress: false,
      onRateChange: false,
      onResize: false,
      onSeeked: false,
      onSeeking: false,
      onSuspend: false,
      onTimeUpdate: false,
      onVolumeChange: false,
      onWaiting: false,
    },
  };

  updatePlaybackRate = () => {
    this.video.playbackRate = 2;
  };

  setVideo = el => {
    this.video = el;
  };

  eventDidFire(event) {
    this.setState({
      events: Object.assign({}, this.state.events, {[event]: true}),
    });
  }

  getProgress() {
    const events = Object.keys(this.state.events);
    const total = events.length;
    const fired = events.filter(type => this.state.events[type]).length;

    return fired / total;
  }

  render() {
    const events = Object.keys(this.state.events);
    const handlers = events.reduce((events, event) => {
      events[event] = this.eventDidFire.bind(this, event);
      return events;
    }, {});

    return (
      <FixtureSet title="Media Events">
        <TestCase
          title="Event bubbling"
          description="Media events should synthetically bubble">
          <TestCase.Steps>
            <li>Play the loaded video</li>
            <li>Pause the loaded video</li>
            <li>Play the failing video</li>
            <li>Drag the track bar</li>
            <li>Toggle the volume button</li>
            <li>
              <button onClick={this.updatePlaybackRate}>
                Click this button to increase playback rate
              </button>
            </li>
          </TestCase.Steps>

          <p className="footnote">
            Note: This test does not confirm <code>onStalled</code>,{' '}
            <code>onAbort</code>, or <code>onEncrypted</code>
          </p>

          <TestCase.ExpectedResult>

Domain

Frequently Asked Questions

What is the MediaEvents class?
MediaEvents is a class in the react codebase, defined in fixtures/dom/src/components/fixtures/media-events/index.js.
Where is MediaEvents defined?
MediaEvents is defined in fixtures/dom/src/components/fixtures/media-events/index.js at line 6.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free