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

@formoe/use-webrtc

v1.3.0

Published

The `useWebRTC` hook provides functionality to negotiate and establish WebRTC connections. It implements the [perfect negotiation](https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API/Perfect_negotiation) with a polite and implolite peer.

Downloads

1

Readme

use-webrtc

The useWebRTC hook provides functionality to negotiate and establish WebRTC connections. It implements the perfect negotiation with a polite and implolite peer.

Usage

import { useWebRTC } from "@formoe/use-webrtc"

const connectionConfig = undefined

const onAnswer = (sdp) => {
    // signal to other peer
}

const onOffer = (sdp) => {
    // signal to other peer
}

const onIceCandidate = (candidate) => {
    // signal to other peer
}

const MyWebRTCComponent = ({stream}) => {

    const videoRef = useRef<null | HTMLMediaElement>(null)

    const {
        acceptIncomingOffer,
        acceptIncomingAnswer,
        addIceCandidate,
        rtcPeerConnection,
    } = useWebRTC({
        connectionConfig,
        active: true,
        polite: false,
        view: videoRef.current,
        localStream: stream,
        onOffer,
        onAnswer,
        onIceCandidate,
        initiateOffer: true,
    })

    return <video
            width="100%"
            height="100%"
            ref={videoRef}
            autoPlay
            playsInline
            controls
          >
            Your browser does not support the video tag.
          </video>
}

Params

The hook can be configured via the following params:

  • connectionConfig: A RTCConfiguration object to initialise the connection with.
  • active: A boolean deciding if the connection shall be established. If set to false any existing connection will be closed. If set to true a connection will be created and negotiation commences as needed.
  • polite: A boolean indicating whether this is the polite or impolite client. You always need to have one polite and one impolite client talking to each other. So this should be a static config for each client.
  • view: A HTMLMediaElement to show the incoming (the peers) stream.
  • localStream: A MediaStream object containing the stream to send to the peer. This has to be set WebRTC will start negotiating. Be aware, that you may need tracks for each media kind (video and audio) you want to be transported on the offer creating side. So for example if you only send audio tracks from the offer side but would want to send video from the answering side, you need to warm up with a dummy track. You can consider using @formoe/use-media-stream to acquire streams from the user.
  • onOffer: Function to call if the connection generates an offer. Use this to send the sdp through your signaling channel to the other peer.
  • onAnswer: Function to call if the connection generates an answer. Use this to send the sdp through your signaling channel to the other peer.
  • onIceCandidate: Function to call if the connection generates an RTCIceCandidate. Use this to send the candidate through your signaling channel to the other peer.
  • initiateOffer: At the moment this indicates if we are the side initiating an offer (making the call). This will soon be handled by the polite / impolite connection logic to allow bidirectional calls.

Returned Interface

  • acceptIncomingOffer: A function taking an incoming sdp string to set as offer for the connection.
  • acceptIncomingAnswer: A function taking an incoming sdp string to set as answer for the connection.
  • addIceCandidate: A function taking an incoming RTCIceCandidate to add as candidate for the connection.
  • rtcPeerConnection: The RTCPeerConnection the hook currently handles.