<commit_before>## SimpleRTCData

SimpleRTCData is a tiny JavaScript library which can be used to establish an RTCDataChannel between two peers. It does not handle the signalling stage so you will need to implement your own mechanism for that.

[Working Example](http://lostsource.github.io/SimpleRTCData/)

### Basic Usage

Assuming two peers Bert and Ernie in which Bert is the initiator, Bert needs to first make an 'offer' to Ernie by calling the `getOffer` method:

    var BertRTC = new SimpleRTCData;
    BertRTC.getOffer(function(bertsOffer) {
      
    });

At this point the `bertsOffer` needs to be sent to Ernie in any way preferred, WebSockets, E-mail, magic etc.. Once Ernie receives Bert's offer he will need to create an 'answer' by passing it as the first argument to `getAnswer`: 

    var ErnieRTC = new SimpleRTCData;
    ErnieRTC.onChannelEvent('message',function(e) {
       // get ready for messages from Bert 
       console.log(e.data);
    });

    ErnieRTC.getAnswer(bertsOffer,function(erniesAnswer) {
      
    });
    
Using your preferred transport mechanism send `erniesAnswer` to Bert so he can use it for the `setAnswer` method:

    BertRTC.onChannelEvent('open',function(){
       // Bert's ready to send messages
    });
    
    BertRTC.setAnswer(erniesAnswer);<commit_msg>Updated basic usage in readme<commit_after>## SimpleRTCData

SimpleRTCData is a tiny JavaScript library which can be used to establish an RTCDataChannel between two peers. It does not handle the signalling stage so you will need to implement your own mechanism for that.

Note: Visualization of the following example is available on this [GitHub Page](http://lostsource.github.io/SimpleRTCData/)

### Basic Usage

Assume we have two peers Bert and Ernie in which Bert is the initiator. Bert first needs to make an 'offer' to Ernie by calling the `getOffer` method:

    var BertRTC = new SimpleRTCData;
    BertRTC.getOffer(function(bertsOffer) {
      
    });

The callback for `getOffer` returns a single argument `bertsOffer` of type `String` which needs to be sent to Ernie your preferred message exchange mechanism (eg. WebSockets, E-mail, magic etc..) Once Ernie receives Bert's offer he will need to create an 'answer' by passing it as the first argument to `getAnswer`. 

    var ErnieRTC = new SimpleRTCData;
     
    ErnieRTC.getAnswer(bertsOffer,function(erniesAnswer) {
      // erniesAnswer now needs to be sent to Bert
    });
    
He should also register a message handler using the `onChannelEvent` method as to be able to receive messages from Bert: 

    ErnieRTC.onChannelEvent('message',function(e) {
       // get ready for messages from Bert 
       console.log(e.data);
    });
     
    
At last send `erniesAnswer` to Bert so he can use it to call his `setAnswer` method:

    BertRTC.onChannelEvent('open',function(){
       // Bert's ready to send messages
       this.send('Hey Ernie!');
    });
     
    BertRTC.setAnswer(erniesAnswer);
{'fraction_non_alphanumeric': 0.07550335570469799, 'fraction_numerical': 0.0, 'mean_word_length': 3.565084226646248, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '432116', 'n_tokens_mistral': 881, 'n_tokens_neox': 809, 'n_words': 353}