socket-webrtc
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

Socket-WebRTC

WebRTC + Sockets for a lovely P2P

Warning: under heavy development, this will go kaboom 💥

  • Peer roles
  • Rooms support
  • Server-side network configuration and security
  • P2P stream support

Getting started

The following example connects multiple peers and sends a video stream

const io = require('socket.io')(httpServer); // Here goes your express or http server
 
const {SocketWebRTCRoom} = require('socket-webrtc');
 
const socketWebRTCRoom = new SocketWebRTCRoom(io);
 
socketWebRTCRoom.on('connection', (peerCandidate) => {
    socketWebRTCRoom.registerPeer(peerCandidate);
});
 
 
httpServer.listen(3000);

server.js

const stream = await navigator.mediaDevices.getUserMedia({
    audio: false
});
 
const socketWebRTCClient = new SocketWebRTCClient();
 
socketWebRTCClient.connect();
socketWebRTCClient.on('peer-connected', (peer) => {
    console.log("Peer connected");
    peer.stream(stream); // Send stream to connected peer
    peer.on('stream', (peerStream) => {
      // attach remote stream to html video
    });
});

client.js

Check examples folder for more working examples

Roles

Rooms

STUN and TURN

Coturn

Readme

Keywords

Package Sidebar

Install

npm i socket-webrtc

Weekly Downloads

1

Version

0.1.1

License

GPL-3.0

Unpacked Size

56.2 kB

Total Files

20

Last publish

Collaborators

  • angrykoala