New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

stream-rtc

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-rtc

RTCRoomConnectionClient;RTCPeerConnectionClient;RTCPeerConnectionServer: simple usage RTC peer connection to handle only what we need without to enter the details like STUN SDP ICE and so on, also great handler for stream functionality in classes like: Sc

latest
Source
npmnpm
Version
2.0.4
Version published
Maintainers
1
Created
Source

WebRTC PeerConnection Signaling Suite

A robust TypeScript signaling solution for WebRTC applications using Socket.io as the signaling mechanism. The package provides an extensible and simple API for both server-side (signaling server) and client-side (browser/app) logic, enabling fast development of peer-to-peer video, audio, or data channels.

NPM

Features

  • Written in TypeScript for type safety and clarity.
  • Signaling server fully decoupled from client logic.
  • Client helper class for easy WebRTC peer connections and ICE negotiation.
  • Customizable event mapping, STUN server configuration, and media constraints.
  • Extensible for custom events or authentication flows.

Requirements

  • Node.js (>= 14)
  • socket.io - for the signaling server side
  • socket.io-client - for the client app side
  • TypeScript (if using or building from source)

Install dependencies:

for server side

  npm install stream-rtc socket.io

for client side

  npm install stream-rtc socket.io-client

Getting Started

1. Server Example (Signaling Server)

import { Server } from 'socket.io';
import { RTCPeerConnectionServer } from 'stream-rtc';

const io = new Server(3000);

io.on('connection', (socket) => {
  const userId = socket.handshake.auth.userName || socket.id;
  new RTCPeerConnectionServer(socket, userId);
});
  • Instantiate RTCPeerConnectionServer for each new socket.
  • Handles offers, answers, and ICE candidate relay automatically.

2. Client Example of user to user

import { io } from 'socket.io-client';
import { RTCPeerConnectionClient } from 'stream-rtc';

const socket = io('http://localhost:3000');
const rtcClient = new RTCPeerConnectionClient(socket, { userId: 'user-A' });

rtcClient.onOffersReceived((offers)=>{
    const offerOptions = offers;
    offerOptions.forEach(o => {
        o.onClick = () => {
            rtcClient.answerOffer().then(([localStream, remoteStream]) => {
                // Attach localStream and remoteStream to <video> HTML elements as needed, or include them in constructur props
            });
        }
    })
    // render offerOptions options
});


rtcClient.call().then(([localStream, remoteStream]) => {
  // Attach localStream and remoteStream to <video> HTML elements as needed, or include them in constructur props
});

2. Client Example room chat

import { io } from 'socket.io-client';
import { RTCRoomConnectionClient, type RoomInfo } from 'stream-rtc';

const socket = io('http://localhost:3000');
const rtcClient = new RTCRoomConnectionClient(socket, { userId: getUserName(), localVideoElement }, { debugMode: true });

// first user should create room like that 
...
await pc.createRoom(roomName, {
    maxParticipants: 10,
    isPrivate: false,
    constraints: { video: true, audio: true },
});
...

// #################################################

// the rest users should join the room like that:
...
await pc.joinRoom(roomId, { video: true, audio: true });
...

  • Use call() to request media permissions and initiate a connection.
  • Listen and respond to offers with answerOffer().
  • ICE candidate and SDP negotiation is handled for you.

Advanced Usage

  • Custom video/audio constraints: Pass custom constraints to call() or answerOffer().
  • Custom ICE servers: Modify PEER_CONFIGURATION in consts.ts for different STUN/TURN servers.
  • Debugging: Pass { debugMode: true } to the client constructor to enable logging.

how to allow Chrome use camera/min on untrast https localhost certificate

  • go chrome flags click here screenshot Output chrome flags

  • add your specific url like: https://localhost:8181

  • then refresh button will appear click it

  • done! go to your chrome host and use camera! screenshot Output chrome permission

License

MIT License

For full source and documentation, visit the example of working demo directory in the repository.

npm github

Keywords

stream

FAQs

Package last updated on 24 Nov 2025

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