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

message-peer-connection

v1.0.3

Published

WebRTC Peer Connection abstraction for messages exchanges.

Downloads

9

Readme

WebRTC Peer connection abstraction for messages exchanges.

Installation

$ yarn add message-peer-connection

or

$ npm i message-peer-connection

Usage

import PeerConnection from 'message-peer-connection'

const onClose = () => console.log('Connecion Closed')
const onCreateOffer = (event, peerConnection) => sendOfferToPeer(peerConnection)
const onOpen = () => console.log('Connection Stablished')
const onSetOffer = (event, peerConnection) => sendAnswerToPeer(peerConnection)

const peerConnection = PeerConnection({
  onOpen,
  onClose,
  onCreateOffer,
  onSetOffer,
})

APIs

PeerConnection

PeerConnection({
    pc,
    onClose,
    onCreateOffer,
    onError,
    onMessage,
    onOpen,
    onSetAnswer,
    onSetOffer,
    ...state,
})

Param | Meaning ---|--- pc | RTCPeerConnection instance, default value is new RTCPeerConnection({ iceServers: [{ urls: 'stun:stun.l.google.com:19302' }] }). onClose | onClose. onCreateOffer | onCreateOffer. onError | onError. onMessage | onMessage. onOpen | onOpen. onSetOffer | onSetOffer. ...state | Any state data.

Function | Meaning | Specification ---|---|--- close | Closes the connection. Close abstraction. | () -> PeerConnection. createOffer | RTCPeerConnection createOffer abstraction | () -> PeerConnection getLocalDescriptionSDP | Retuns the RTCPeerConnection's localDescription's SDP | () -> SDP getState | Returns the PeerConnection state. | () -> Object sendMessage | Adds a title prop to the data object, stringifies it and calls sendPlainTextMessage. | (title: string, data: object) -> PeerConnection sendPlainTextMessage | channel abstraction | message: string -> PeerConnection setAnswer | setRemoteDescription abstraction that sets an RTCSessionDescription answer. | answer: string -> PeerConnection setOffer | setRemoteDescription abstraction that sets an RTCSessionDescription offer and creates an answer. | string -> PeerConnection setPC | Sets the RTCPeerConnection instance that will be used | pc: RTCPeerConnection -> PeerConnection setState | Adds new state values. | newStateValues: object -> PeerConnection updateOnClose | Updates the onClose listener | onClose: function -> PeerConnection updateOnCreateOffer | Updates the onCreateOffer listener | onCreateOffer: function -> PeerConnection updateOnError | Updates the onError listener | onError: function -> PeerConnection updateOnMessage | Updates the onMessage listener | onMessage: function -> PeerConnection updateOnOpen | Updates the onOpen listener | onOpen: function -> PeerConnection updateOnSetOffer | Updates the onSetOffer listener | onSetOffer: function -> PeerConnection

Listeners

onClose

Listener function executed when the connection closes, it receives two arguments oniceconnectionstatechange Event and the PeerConnection instance.

onCreateOffer

Listener function executed when an offer is created, it receives two arguments onicecandidate Event and the PeerConnection instance.

onError

Listener function executed when an error is catch while trying to create or set an offer or set an answer it receives two arguments Event and the PeerConnection instance.

onMessage

Listener function executed when a message is receive, it receives two arguments onmessage Event and the PeerConnection instance.

onOpen

Listener function executed when the connection is stablished, it receives two arguments onopen Event and the PeerConnection instance.

onSetOffer

Listener function executed when an offer is set, it receives two arguments onicecandidate Event and the PeerConnection instance.

TODO

  • [x] Readme
  • [ ] Example folder
  • [ ] Tests

References

https://www.html5rocks.com/en/tutorials/webrtc/infrastructure/