rtc.io
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

rtc.io

Inspired by socket.io, rct.io is an easier to use way of dealing with WebRTC. It wraps the logic of creating RTCPeerConnections in easy-to-use callback chaining.

Features

  • Built in TypeScript and is fully typed
  • Works with your custom signal server via an implemented interface
  • Generic typed parameters for custom events listeners and emitters
  • Only one production dependency

Roadmap

  • Finish implementing RTCDataChannel and RTCPeerConnection abstraction

  • Abstract video and audio streams

Usage/Examples

import { rtc } from 'rtc.io'
import signalServer from '../yourSignalServerApi'
import { iceConfig } from '../config/yourIceConfig';

interface IMyCustomEvent {
    message: (message: string) => void;
}

const p2p = rtc<IMyCustomEvent>(signalServer, iceConfig);

p2p.on('connection' (peer) => {

    // Fully typed event injects the parameter type into the callback
    peer.on('message', (msg) => {
        console.log(msg);
    })

    // Some already built in events ready to use
    peer.on('close', () => {
        console.log(`Peer ${peer.id} closed the connection`);
    })

    // You can overload your callbacks to have more than 1 fire
    // when an event is received.
    peer.on('message' (msg) => {
        console.log("2nd callback!");
    })
});

p2p.connect('roomName');

Package Sidebar

Install

npm i rtc.io

Weekly Downloads

0

Version

0.1.1

License

MIT

Unpacked Size

38.6 kB

Total Files

15

Last publish

Collaborators

  • dbidwell94