npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-voicemail-player

v0.0.10

Published

React component for rendering voice messages in chat-based apps

Downloads

6

Readme

React-Voicemail-Player

The audio player control for React that displays the audio's amplitude peaks. Loads and decodes the audio data in memory, so best suited for small audio files, like voicemail, hence the name. The use case I had in mind is chat-based apps where users can send voice messages. Inspired by audio player in the Telegram messenger.

Note, this is neither a powerful audio visualization library, nor a powerful audio player. If you need rich visualizations, I suggest wavesurfer.js. If you look for a general-purpose audio player, check out react-audio-player-pro.

Check out the demo app.

Installation

Requires react to be already installed in your project. Minimum supported version of React is 18 because this component uses useSyncExternalStore hook. There is a shim for that, so it might be added in the future to support earlier versions of react if needed.

npm i react-voicemail-player

# or

yarn add react-voicemail-player

Usage

First you need to make sure the component's CSS is included on your web page. How you do this depends on your environment. Most probably you can import the stylesheet directly in your JavaScript or your CSS files:

// App.tsx
import 'react-voicemail-player/dist/react-voicemail-player.css';
// styles.css
@import url('react-voicemail-player/dist/react-voicemail-player.css')

Then, you import and render the component as you normally would. It accepts a function as children (render prop) that renders an <audio> element. The function will be called with a RefCallback as an argument that you need to set as ref on the rendered <audio> element.

import VoicemailPlayer from "react-voicemail-player";

function YourComponent() {
  return (
    <VoicemailPlayer>
      {(ref) => <audio ref={ref} src="https://example.com/audio.mp3" />}
    </VoicemailPlayer>
  );
}

Since you have full control over the <audio> element, you can implement whatever functionality is missing from this player yourself by setting attributes/properties or calling methods on the element. Relevant changes to the <audio> element will be automatically reflected in the player's state. See examples setting the mute attribute dynamically and controlling the playback rate in ./example/App.tsx;

API

Currently, the component only accepts two props:

  • children: (ref: React.RefCallback<HTMLAudioElement>) => React.ReactElement - A function that renders the <audio> element and sets its ref prop
  • className: string - A CSS class name to give to the component's root element

See the full API Reference.

Styling

Please consult the component's stylesheet and source code as necessary to determine which classes and properties you need to override.

Development

Install dependencies with yarn:

yarn

Start development server

yarn start

Run tests (with watch mode)

yarn test

E2E Tests

E2E tests are run against the pre-compiled library files, make sure you've run yarn build before running e2e tests locally

Run once:

yarn test:e2e

Run in UI mode:

yarn test:e2e:ui

Update screenshots:

yarn test:e2e --update-snapshots

Update snapshots on Linux (for CI):

docker run --rm --network host -v $(pwd):/work/ -w /work/ -it mcr.microsoft.com/playwright:v1.37.0-jammy /bin/bash
yarn install
yarn test:e2e --update-snapshots