# @dschoon/react-waves

> React component wrapper for wavesurfer.js

Latest version **4.0.3** (published 2020-11-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install @dschoon/react-waves
pnpm add @dschoon/react-waves
yarn add @dschoon/react-waves
bun add @dschoon/react-waves
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.3 |
| Published | 2020-11-30 |
| First published | 2018-12-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=8 |
| Dependencies | 6 |
| Unpacked size | 1.7 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 73 |
| Author | dschoon |
| Maintainers | dschoon |
| Keywords | react, reactjs, wavesurfer, audio, react-component, component |

## Links

- npm: https://www.npmjs.com/package/@dschoon/react-waves
- Repository: https://github.com/dschoon/react-waves
- Homepage: https://dschoon.github.io/react-waves
- Issues: https://github.com/dschoon/react-waves/issues
- npm.io page: https://npm.io/package/@dschoon/react-waves

## Dependencies (6)

- [typescript](https://npm.io/package/typescript.md) ^4.0.5
- [@types/jest](https://npm.io/package/@types/jest.md) ^26.0.15
- [@types/node](https://npm.io/package/@types/node.md) ^14.14.7
- [@types/react](https://npm.io/package/@types/react.md) ^16.9.56
- [wavesurfer.js](https://npm.io/package/wavesurfer.js.md) ^4.1.1
- [@types/react-dom](https://npm.io/package/@types/react-dom.md) ^16.9.9

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 4.0.3 (latest) — 2020-11-30
- 4.0.2 — 2020-11-12
- 4.0.1 — 2020-11-12
- 4.0.0 — 2020-11-12
- 3.0.3 — 2020-04-26
- 3.0.2 — 2020-04-26
- 3.0.1 — 2019-12-01
- 3.0.0 — 2019-11-11
- 2.0.0 — 2019-11-11
- 1.0.15 — 2019-06-16
- 1.0.14 — 2019-05-23
- 1.0.13 — 2019-05-23
- 1.0.12 — 2019-05-23
- 1.0.11 — 2019-05-23
- 1.0.10 — 2019-05-13
- … 10 more at https://npm.io/package/@dschoon/react-waves/versions

## README

# ReactWaves

React component wrapper for [Wavesurfer.js](http://wavesurfer-js.org)

[![NPM](https://img.shields.io/npm/v/@dschoon/react-waves.svg)](https://www.npmjs.com/package/@dschoon/react-waves) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) [![CircleCI](https://circleci.com/gh/dschoon/react-waves.svg?style=svg)](https://circleci.com/gh/dschoon/react-waves)

#### Background

This component was originally based off of the work done in [react-wavesurfer](https://github.com/mspae/react-wavesurfer) by [@mspae](https://github.com/mspae) (and [others](<(https://github.com/mspae/react-wavesurfer/graphs/contributors)>)). After wavesurfer-js released version 2, and the react-wavesurfer projected became unmaintained, I decided that it was safer to start my own version that I had better control over.

#### Version 4.x

To align this component nicer with the base [wavesurfer.js](https://github.com/katspaugh/wavesurfer.js) project, I decided to skip version 2 and go straight to version 3. With wavesurfer now on version 4, we have made the necessary updates and are now also on v4.

#### Issues

Please report any [issues](https://github.com/dschoon/react-waves/issues) you encounter and I will try my best to get them fixed.

---

## Examples

![ReactWaves](example/public/react-waves.jpg)

Here's a basic demo and the example code include in this repo:

- **[Demo](https://dschoon.github.io/react-waves/)**
- **[Basic Example](https://github.com/dschoon/react-waves/blob/master/example/src/components/BasicExample.js)**
- **[Microphone Plugin Example](https://github.com/dschoon/react-waves/blob/master/example/src/components/MicrophoneExample.js)**
- **[Regions Plugin Example](https://github.com/dschoon/react-waves/blob/master/example/src/components/RegionsExample.js)**
- **[Timeline Example](https://github.com/dschoon/react-waves/blob/master/example/src/components/TimelineExample.js)**
- **[Large File Example](https://github.com/dschoon/react-waves/blob/master/example/src/components/LargeFilePeaksExample.js)**
- **[Generate PCM Data Example](https://github.com/dschoon/react-waves/blob/master/example/src/components/GetPeaksExample.js)**
- **[Spectrogram Example](https://github.com/dschoon/react-waves/blob/master/example/src/components/SpectrogramExample.js)**

Here's an example of the personal project where I'm using this code:

- **[Casts.co](https://pod.casts.co)** (formerly Clipps)
- **[Clipps Player (Demo)](https://dschoon.github.io/clipp-player)**

## Install

```bash
npm install @dschoon/react-waves
```

or

```bash
yarn add @dschoon/react-waves
```

## Basic Example

```jsx
import React from "react";
import ReactWaves from "@dschoon/react-waves";

import africa from "../audio/africa.mp3";

export default class BasicExample extends React.Component {
  state = {
    playing: false,
  };

  render() {
    return (
      <div className={"container example"}>
        <div
          className="play button"
          onClick={() => {
            this.setState({ playing: !this.state.playing });
          }}
        >
          {!this.state.playing ? "▶" : "■"}
        </div>
        <ReactWaves
          audioFile={africa}
          className={"react-waves"}
          options={{
            barHeight: 2,
            cursorWidth: 0,
            height: 200,
            hideScrollbar: true,
            progressColor: "#EC407A",
            responsive: true,
            waveColor: "#D1D6DA",
          }}
          volume={1}
          zoom={1}
          playing={this.state.playing}
        />
      </div>
    );
  }
}
```

## Available Props

```jsx
props = {
  playing: PropTypes.bool,
  pos: PropTypes.number,
  audioFile: (props, propName, componentName) => {
    const prop = props[propName];
    if (
      prop &&
      typeof prop !== "string" &&
      !(prop instanceof window.Blob) &&
      !(prop instanceof window.File)
    ) {
      return new Error(`Invalid ${propName} supplied to ${componentName}
        expected either string or file/blob`);
    }

    return null;
  },

  mediaElt: PropTypes.oneOfType([
    PropTypes.string,
    PropTypes.instanceOf(window.HTMLElement),
  ]),
  audioPeaks: PropTypes.array,
  volume: PropTypes.number,
  zoom: PropTypes.number,
  onPosChange: PropTypes.func,
  children: PropTypes.oneOfType([PropTypes.element, PropTypes.array]),
  options: PropTypes.shape({
    audioRate: PropTypes.number,
    audioContext: PropTypes.object,
    audioScriptProcessor: PropTypes.object,
    autoCenter: PropTypes.bool,
    backend: PropTypes.oneOf([
      "WebAudio",
      "MediaElement",
      "MediaElementWebAudio",
    ]),
    barGap: positiveIntegerProptype,
    barHeight: positiveIntegerProptype,
    barRadius: positiveIntegerProptype,
    barWidth: (props, propName, componentName) => {
      const prop = props[propName];
      if (prop !== undefined && typeof prop !== "number") {
        return new Error(`Invalid ${propName} supplied to ${componentName}
          expected either undefined or number`);
      }

      return null;
    },
    closeAudioContext: PropTypes.bool,
    cursorColor: PropTypes.string,
    cursorWidth: positiveIntegerProptype,
    fillParent: PropTypes.bool,
    forceDecode: PropTypes.bool,
    height: positiveIntegerProptype,
    hideScrollbar: PropTypes.bool,
    interact: PropTypes.bool,
    loopSelection: PropTypes.bool,
    maxCanvasWidth: positiveIntegerProptype,
    mediaControls: PropTypes.bool,
    mediaType: PropTypes.oneOf(["audio", "video"]),
    minPxPerSec: positiveIntegerProptype,
    normalize: PropTypes.bool,
    partialRender: PropTypes.bool,
    pixelRatio: PropTypes.number,
    progressColor: PropTypes.string,
    removeMediaElementOnDestroy: PropTypes.bool,
    renderer: PropTypes.object,
    responsive: PropTypes.bool,
    scrollParent: PropTypes.bool,
    skipLength: PropTypes.number,
    splitChannels: PropTypes.bool,
    waveColor: PropTypes.oneOfType([
      PropTypes.string,
      PropTypes.instanceOf(window.CanvasGradient),
    ]),
    xhr: PropTypes.object,
  }),
  spectrogramOptions: PropTypes.object,
  timelineOptions: PropTypes.object,
};
```

## License

MIT © [Dan Schoonmaker](https://schoon.me) [(github)](https://github.com/dschoon)

_Last Updated: November 11th, 2020_

---
_Source: https://npm.io/package/@dschoon/react-waves · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
