Skip to content

bredele/peer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

peer

Composable and clean webrtc peer connection.

Installation

$ npm install bredele/peer --save

Usage

initialize a local peer connection with an optional list of servers:

var peer = require('peer');
var master = peer();

create peer connection:

master.create();

API

The following API is entirely private and should only be access through plugins or codecs.

Here's a list of available plugins:

  • connect creates local peer-to-peer connection
  • signal creates remote peer-to-peer connection
  • video attach video stream to a peer-to-peer connection

Here's a list of available codecs:

  • rate changes data channel speed/rate limitation
  • opus set opus as preferred audio codec

Related projects:

  • hangout peer-to-peer video through localtunnel

a plugin can add codecs as well

create

create a peer connection

master.create();

offer

create an offer (initialize a master session description) and set local session description.

master.offer();

A master peer connection is a client which shares a media.

anwer

create an answer (initialize a slave session description) and set local session description.

var slave = peer();
slave.answer();

A slave peer connection is a client (remote or local) which reads a shared media.

local

set local session description

master.local(sdp);

remote

set remote session description

master.local(sdp);

ice

set ice (network) candidate

master.ice(candidate);

stream

add peer local stream

master.stream(stream);

message

send a message through the peer connection

master.send('hello')

a message will be sent through a data channel if initialized by constraints

codec

public interface to set codec on the peer session description.

master.codec(function(sdp) {
  // do something on sdp and return result
});

codecs are session descriptions filters so make sure your codec return the session description.

use

public interface to create plugins.

master.use(function(peer) {
  // do something
});

Concepts

plugins

Peer is not a framework, think of it as the minimum amount of glue necessary to create a peer to peer connection. The beauty part is that it provides a mechanism to compose other modules aka plugins. A plugin is trivial and do one thing but do it well. At the end you can compose your webrtc application, reuse some plugins or create your own and get what you really want.

Oh, and it makes developping a webrtc ridiculously simple. For example, with channel and video you can create a skype-like application in 2 lines:

var skype = peer();
skype.use(video('#id'));
skype.use(channel('chat'));

Peer has been developped to let flourish an ecosystem of plugins.

codecs

A session description (SDP) contains all the information needed to initialize a peer connection. It contains for example the types of media to be exchanged (such as audio, video, data), the network topology, the bandwidth information and other metadata.

A codec in peer is a piece of JavaScript which modifies the session description and therfore the parameters of a peer-to-peer communication. You can for example set opus as the preferred type of audio stream or change the speed limitation or a data channel with rate.

License

The MIT License (MIT)

Copyright (c) 2014 Olivier Wietrich

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

WebRTC peer connection made easy

Resources

License

Stars

Watchers

Forks

Packages

No packages published