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

light-webrtc

v0.0.2

Published

As you know, webrtc protocol itself does not define signaling interaction protocol, and users need to implement sdp+icecandidate exchange logic by themselves. Therefore, webrtc does not have a standard player, so it needs to use js or native sdk to implem

Downloads

4

Readme

Light WebRTC

As you know, webrtc protocol itself does not define signaling interaction protocol, and users need to implement sdp+icecandidate exchange logic by themselves. Therefore, webrtc does not have a standard player, so it needs to use js or native sdk to implement playback.

I wanted to implement a webrtc player to interface with ZLMediaKit, but I still wanted it to support more platforms, so I wrote this library to implement basic signaling interaction and disconnected reconnection.

How to use

Install

cdn

<script src="https://unpkg.com/light-webrtc@latest/dist/index.iife.js"></script>

npm

npm i --save light-webrtc

yarn

yarn add --save light-webrtc

pnpm

pnpm add light-webrtc

Demo

This is a demo using ZLMediaKit as a pull-through platform.

ESM

import LightWebRTC from 'light-webrtc'

Base

const lightWebRTC = new LightWebRTC({
    media: document.getElementById('video'),
    autoLoad: true,
    getRemoteSdp: (sdp) =>
        fetch(
            "http://127.0.0.1:8080/index/api/webrtc?app=live&stream=test&type=play",
            {
                method: "post",
                body: sdp,
                headers: {
                    "Content-Type": "text/plain;charset=utf-8",
                },
            }
        )
            .then((res) => res.json())
            .then((d) => d.sdp),
})

Use autoLoad, video will load when construct.

if you want load video at another appropriate time, use method lightWebRTC.load() and set autoLoad to false.

Reconnect

When iceConnectionState become disconnected, Light WebRTC will reconnect 3 times automatically.

You can change the number of reconnections by setting retryTime.

const lightWebRTC = new LightWebRTC({
    media: document.getElementById('video'),
    autoLoad: true,
    retryTime: 5, // Auto reconnect 5 times.
    getRemoteSdp: (sdp) =>
        fetch(
            "http://127.0.0.1:8080/index/api/webrtc?app=live&stream=test&type=play",
            {
                method: "post",
                body: sdp,
                headers: {
                    "Content-Type": "text/plain;charset=utf-8",
                },
            }
        )
            .then((res) => res.json())
            .then((d) => d.sdp)
})

When status is failed, you can run lightWebRTC.reload() to reconnect.

Other stream platform

If you want to use this library with other stream platform, you should write getRemoteSdp by yourself.

For example with SRS, you should convert webrtc://localhost/live/livestream to http(s) request by yourself and write code in getRemoteSdp method.

Options

media

type: HTMLMediaElement

Your video element

autoLoad

type: boolean

Load source when construct

retryTime

type: number

default: 3

Retry time when disconnected

connectionConfig

type: RTCConfiguration

PeerConnection configuration

getRemoteSdp

required

type: (localSdp: string) => Promise<string>

Send offer and get answer

Methods

load

type: () => Promise<void>

Send offer and setRemoteDescription with answer.

reload

type: () => Promise<void>

Create new RTCPeerConnection to load.

destroy

type: () => void

Close connection and clear events.

Events

Add event listener

lightWebRTC.on('event name', callback)
// or
lightWebRTC.addEventListener('event name', callback)

Remove event listener

lightWebRTC.removeEventListener('event name')

Event name

status

This event will fire when status change.

lightWebRTC.on('status', status => {
    console.log('status', status);
})

error

lightWebRTC.on('error', error => {
    console.log('error', error);
})

Status

export enum Status {
  connecting = "connecting",
  connected = "connected",
  reconnecting = "reconnecting",
  failed = "failed",
  disconnected = "disconnected",
  closed = "closed",
}

License

light-webrtc is released under the MIT license.