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

media-socket

v0.0.2-b

Published

Stream easily UserMedia audio and video over websocket

Downloads

6

Readme

Media-Socket

media-socket is a library for sending user media in real time via websocket. The advantage of this library is that it integrates the recording, sending and client-side display of audio and video.

The library makes use of RecordRTC (https://recordrtc.org/) and WebSocket.

Installation

The library is available for browser as compiled bundle or Node applications as es6 package

Browser (Static Files, CDN, ...)

Import the media-socket bundle as follows:

<script src="https://raw.githubusercontent.com/Lykos94/media-socket/master/examples/client/html/bunde.js">

Node (Vue, React, ...)

To install the library you can use npm or yarn

  npm install media-socket
  # or
  yarn add media-socket

Usage

The library contain two main functions: the Player and the Recorder. The recorder takes the UserMedia as stream and through RecordRTC dynamically creates the BLOB chunks to be delivered via WebSocket. The Player, on the other hand, retrieves from a WebSocket object the BLOBs, turns them into ArrayBuffer and displays the result live in a HTMLVideoElement.

Browser (Static Files, CDN, ...)

Creating a recorder

const recorder = new MediaSocket.Recorder({
  ws,
  recordingOptions: {
    timeSlice: 100,
    media: {
      audio: true,
      video: true,
    },
  },
});

Creating a player

const video = document.getElementById("video");
const player = new MediaSocket.Player({
  playingOptions: {
    element: video,
    media: {
      video: true,
      audio: true,
    },
  },
  ws,
});

In both, ws is the WebSocket object initialized previously. If you want to initialize them on the fly with different parameters, you can also pass the wsUrl instead of the ws parameter.

// Example with wsUrl
const player = new MediaSocket.Player({
  playingOptions: {
    // ...
  },
  wsUrl: "ws://localhost:3000",
});

Node (Vue, React, ...)

The only difference with respect to the browser example is that you need to import the package as follows

import * as MediaSocket from "media-socket";

Configuration Types

Recorder

type RecorderConfiguration = {
  recordingOptions: {
    timeSlice?: number;
    media: {
      audio: boolean;
      video: boolean;
    };
  };
  ws?: WebSocket; // Use existing WebSocket
  wsUrl?: string; // Use this url to create a new WebSocket
};

Player

type PlayerConfiguration = {
  playingOptions: {
    element: HTMLVideoElement | HTMLAudioElement;
    media: {
      audio: boolean;
      video: boolean;
    };
  };
  ws?: WebSocket; // Use existing WebSocket
  wsUrl?: string; // Use this url to create a new WebSocket
};

Running examples

In this repository there are a couple of examples that may be useful during the development. In order to run them:

  • Clone the repository
git clone https://github.com/Lykos94/media-socket
  • Go to the server folder
cd media-socket/examples/server
  • Install all the dependencies
npm i
  • To run the basic HTML vanilla example, you can just open the examples/client/html/index.html file in your browser

License

MIT

Authors