0.0.18 • Published 10 years ago

handshake-webrtc v0.0.18

Weekly downloads
1
License
MIT
Repository
github
Last release
10 years ago

Handshake.js

Simple library to initiate a WebRTC handshake between peers. To exchange the Handshake, some sort of signaling is needed.

Alice

// A create an offer..
var peer = Handshake.createOffer(function(offer){
    // we need to send {offer} to Bob
    ...
});


...
// C apply the others answer..
Handshake.handleAnswer(peer, ANSWER_FROM_BOB);

// API

// get own address
var ownAddress = Handshake.address();

peer.onopen(function(){
    // we can send data now!
    peer.send("Hello World");
    
    // ask the peer for all its current neighbors
    peer.getNeighbors()
        .then(function(neighbors){
            console.log(neighbors); // ["Address1", "Address2", ...]
        })
        .catch(function(){
            // something went wrong.. timeout or so..
        });
 
    ...
    
    // ask the peer to host a connection to another peer it is connected to
    var otherPeer = peer.attemptToConnect("address1");
    
    otherPeer.onopen(function(){
        ...
    });
    
    // gets called when the attempt to connect did not succeed.
    otherPeer.oncannotfindpeer(function(addr){
        ...
    });
});

peer.onmessage(function(msg){
    console.log(msg);
});

...

// callback for connections from within the network
Handshake.onRemoteConnection(function(peer){
    peer.onopen(function(){
        ...
    });
});

Bob

// B answer to the offer..
var peer = Handshake.createAnswer(function(answer){
    // we need to send {answer} back to Alice
    ...
});

// API

peer.onopen(function(){
    // we can send data now!
    peer.send("Hello World back");
});

peer.onmessage(function(msg){
    console.log(msg);
});
0.0.18

10 years ago

0.0.17

10 years ago

0.0.16

10 years ago

0.0.15

10 years ago

0.0.14

10 years ago

0.0.13

10 years ago

0.0.12

10 years ago

0.0.11

10 years ago

0.0.10

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

11 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago