Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/traviswimer/signalfire.js
RTCPeerConnection signaling library/npm module. It does the signaling and then gets out of your way.
https://github.com/traviswimer/signalfire.js
Last synced: about 2 months ago
JSON representation
RTCPeerConnection signaling library/npm module. It does the signaling and then gets out of your way.
- Host: GitHub
- URL: https://github.com/traviswimer/signalfire.js
- Owner: traviswimer
- License: other
- Created: 2013-05-14T18:09:46.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-08-16T18:55:45.000Z (over 11 years ago)
- Last Synced: 2023-03-25T13:05:35.210Z (almost 2 years ago)
- Language: JavaScript
- Size: 4.03 MB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE.txt
Awesome Lists containing this project
README
# SignalFire.js
An RTCPeerConnection signaling library/npm module. It does the signaling and then gets out of your way.
* [Quick Tutorial](http://signalfirejs.github.io/tutorial.html)
* Twitter: [@SignalFireJS](https://twitter.com/SignalFireJS)## Why do I need this? ##
There are other open-source signaling options, but many create a layer of abstraction around the RTCPeerConnection object. Although this can be useful, it can also be restrictive, especially when the WebRTC specification is still in flux.
The purpose of SignalFire.js is to:
* Only focus on signaling
* Give developer control before signaling
* Return complete control to the developer after signaling## Installation ##
### Server-side ###
1. `npm install signalfire`
3. use `require('signalfire')` in node### Client-side ###
* The main script is `SignalFire.js / client / src / signalfire-client.js`
* `adaptor.js` and `socket.io.js` are necessary dependencies in the same directory## Basic Usage Example ##
SignalFire consists of a client-side script and a node module for signaling. Each is show below:
### Client-side: ###
```js
var options = {
// Server to connect to
server: "http://localhost:3333",// That will be called each time a new peer connection is created
connector: function(startSignaling, isAnswer){
var newConnection = new RTCPeerConnection(
{
"iceServers": [{ "url": "stun:stun.l.google.com:19302" }]
}
);startSignaling(newConnection);
},// Callback function for when the signaling process is complete
onSignalingComplete: function(rtcPeerConnection){
// Do something
}
};var conn = signalfire.connect(options,function(){
conn.emit('askServerForPeer',{
data: someData
});
});
```### Server-side: ###
```js
var signalfire = require('signalfire');var sf=signalfire.listen(3333,function(peer){
peer.socket.on('askServerForPeer', function(data){
peer.connectToPeer(anotherPeer);
});
},function(error){
console.log('something went wrong');
});
```# API Documentation #
## Server-side ##
### Signalfire Object ###
Load module with `require('signalfire')`
### listen( port, successCallback, failCallback ) ###
Tells the server to listen on a certain port for socket connections to be used for peer connections. Returns a socket.io manager object.
* **port** (number) - Server port number to listen on.
* **successCallback** (function) - Callback function to be returned when a
user successful creates a socket connection with the server.
* Returns [peer object](#peer-object---server)
* **failCallback** (function) - Callback function to be returned when a user fails
to create a socket connection with the server.
* Returns an error message (string)### peer object - _server_ ###
#### socket ####
Contains a socket.io object
#### connectToPeer( peer ) ####
Connects the peer calling the method to a specified peer
* **peer** ([peer object](#peer-object---server)) - Peer to connect to.
#### getPeerId() ####
Returns the unique ID for the peer object.
## Client-side ##
### connect( options, successCallback, failCallback ) ###
Creates a socket connection with the specified server. Returns a socket.io manager object.
* **options** (object) - Setup options
* server (string || object) - Required. Specifies the server to connect to. `server: "http://localhost:3333"` or specify an object with a socket-like API (on, emit, ...).
* **connector** ( function(startSignaling, isAnswer) ) - Required. A function that creates a new RTCPeerConnection object. The startSignaling function must be called to initiate signaling.
* startSignaling(peerConnection) - A callback function for that initializes the signaling process. Takes a single parameter that must be an RTCPeerConnection object.
* isAnswer - A boolean value. True if the client is sending an RTCPeerConnection answer. False if the client is sending an RTCPeerConnection offer.
* onSignalingComplete (function) - Callback function for when the signaling process has successfully created a peer connection.
* onSignalingFail (function) - Callback function for when there is an error in the signaling process.
* **successCallback** (function) - Callback function to be returned when a
user successful creates a socket connection with the server.
* Returns [peer object](#peer-object---client)
* **failCallback** (function) - Callback function to be returned when a user fails to create a socket connection with the server.
* Returns an error message (string)### peer object - _client_ ###
#### socket ####
Contains a socket.io object