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

rtc-socket-connector-client

v0.1.9

Published

Connect webRTC connection to socket server

Downloads

10

Readme

rtc-socket-connector-client

rtc-socket-connector-client is a library for WebRTC connection with rtc-socket-connector-server.
Clients send socket messages rtc-socket-connector-client for WebRTC to the server using rtc-socket-connector-server.
These two libraries simplify the process required for WebRTC connection.
Example using this library: rtc-socket-connector-example

How to use

1. Create socket using socket.io

Connect socket server which is added WebRTC connection handlers by rtc-socket-connector-server.

const socket = io("YOUR SERVER URL");

2. Define RTCConnectionHandler

RTCConnectionHandler is handlers related on WebRTC events.

const handler = {
  onRTCPeerConnection: (socketId, rtcPeerConnection) => {
    // Use rtcPeerConnection
  },
  onTrack: (socketId, mediaStream) => {
    // Use mediaStream
  },
  onDataChannel: (socketId, dataChannel) => {
    // Use dataChannel
  }
}

onRTCPeerConnection will be executed when new RTCPeerConnection is created.

onTrack will be executed when a track has been added to the RTCPeerConnection.
this event is sent when a new incoming MediaStreamTrack has been created and associated with an RTCRtpReceiver.
The incoming track to the <video> element which will be used to display the incoming video.

onDataChannel will be executed when RTCDataChannel is added to the connection by the remote peer.
RTCDataChannel can be used for bidirectional peer-to-peer transfers of arbitrary data

3. Create RTCConnectionManager

RTCConnectionManager handles socket messages for WebRTC connection.

Use createRTCConnectionManager to create RTCConnectionManager

Set the socket(step 1. Connect socket.io server) and the defined handler(step 2 Define handlers) as parameters.

import { createRTCConnectionManager } from "rtc-socket-connector-client";

const rtcConnectionManager = createRTCConnectionManager(socket, handler);

4. Set MediaStream (optional)

Set MediaStream which will be transmitted to the other peer.

rtcConnectionManager.setMediaStream(mediaStream)

5. Connect another client

Clients can be identified by Socket ID.
Execute RTCConnectionManager.connect to start process to connect to the target client.

rtcConnecitonManager.connect(targetSocketId, {
  enableMediaStream: true,
  enableDataChannel: true,
})

Set enableMediaStream to true to enable MediaStream. Requires setting mediaStream by using RTCConnectionManager.setMediaStream method before calling RTCConnectionManager.connect to connect MediaStream.

Set enableDataChannel to true to enable DataStream. onDataChannel handlers will be executed.

API

createRTCConnectionManager(socket, handlers, rtcConfiguration)

Create RTCConnectionManager arguments

  • socket(Socket): A socket created to socket server.
  • handlers
    • onRTCPeerConnection((socketId: string, rtcPeerConnection: RTCPeerConnection)): Triggers when RTCPeerConnection is created.
    • onTrack((socketId: string, mediaStream: MediaStream[]) => void): Triggers when a track has been added to the RTCPeerConnection
    • onDataChannel((socketId: string, dataChannel: RTCDataChannel) => void): Triggers when new DataChannel is opened.
  • rtcConfiguration(RTCConfiguration)(optional): An object providing options to configure the new WebRTC connection.

RTCConnectionManager

RTCConnectionManager is a class that provides method to connect to other clients and to set MediaStream to send to other clients.

methods

connect(targetSocketId, option)

Connect another client that has targetSocketId as a socket id.
Arguments

  • answerSocketId(string): Socket id on another client to connect
  • option
    • enableDataChannel(boolean): Set true to enable DataChannel. DataChannel, the label of which is main, will be open. onDataStream handler will be executed.
    • enableMediaStream(boolean): Set true to enable MediaStream. onTrack handler will be executed.

setMediaStream(mediaStream)

Set MediaStream to send to other clients will be connected.
MediaStream should be set before connecting other clients.
Arguments

  • mediaStream(MediaStream): MediaStream which will be transmitted to the other peer.

Resources