Socket
Book a DemoInstallSign in
Socket

webrtc-codec-support

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webrtc-codec-support

Checks if a codec is supported by WebRTC stack in browser

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
111
-35.84%
Maintainers
1
Weekly downloads
 
Created
Source

webrtc-codec-support

Simple browser library to check if WebRTC supports the specified codecs for receiving and publishing.

Inspired by my long troubleshooting session in Firefox with disabled H.264 plugin and Firefox incorrectly reporting it as ICE communication problem.

Install

Install with npm (npm install webrtc-codec-support --save) or download a prebundled package from Releases (webpack umd2 module format, includes the sdp parser library dependencies already).

Usage

Codecs

The library exports a WebrtcCodec class, with static instances for each codec it supports:

Video codecs:
  WebRtcCodec.VP8
  WebRtcCodec.VP9
  WebRtcCodec.H264
Audio codecs:
  WebRtcCodec.OPUS
  WebRtcCodec.ISAC

WebRTC always supports the VP8 and OPUS codecs, these are included for completeness.

Receiving

The isWebrtcReceiveCodecSupportedfunction returns a boolean Promise.

isWebrtcReceiveCodecSupported(WebrtcCodec.H264).then((supported)=>{
  if (supported) console.log("H.264 supported");
});

Publishing

The isWebrtcPublishCodecSupportedfunction takes a pre-acquired MediaStream object returns a boolean Promise. The MediaStream object must contain a video track if checking for video codecs, and an audio track if checking for audio codecs. It can contain both as well.

navigator.mediaDevices.getUserMedia({video:true, audio:true}).then((mediaStream) => {

  isWebrtcPublishCodecSupported(mediaStream, WebrtcCodec.H264).then((supported)=>{
    if (supported) console.log("H.264 supported");
  });

});

How?

When checking if receiving a codec is possible, we build a dummy minimal SDP as if coming from signaling, and ask the browser to create an answer sdp, which we parse and check if the specified codec is present in the answer.

For publishing, a media stream has to be acquired already and we simply analyze the offer SDP created by the WebRTC stack, parsing it for codecs.

License

Unlicense - Human knowledge belongs to the world.

Keywords

webrtc

FAQs

Package last updated on 03 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts