<commit_before># JavaScript gossiperl client libraries

JavaScript gossiperl client libraries with Node.JS wrappers.

Work in progress

# License

The MIT License (MIT)

Copyright (c) 2015 <NAME> <<EMAIL>>
<commit_msg>Update readme for the JS project. Fixes #4.<commit_after># JavaScript gossiperl client libraries

JavaScript gossiperl client libraries with Node.JS wrappers.

# Using with Node.JS

Add a dependency in your package.json:

    "gossiperl-client-js": "git://github.com/gossiperl/gossiperl-client-js.git"

In your code:

    require('gossiperl-client-js');

# Using with Bower

Add a dependency in your bower.json:

    "gossiperl-client-js": "gossiperl/gossiperl-client-js"

And in your HTML:

    <!-- gossiperl: -->
    <script type="text/javascript" src="/bower_components/gossiperl-client-js/lib/types/chrome/gossiperl_types.js"></script>
    <script type="text/javascript" src="/bower_components/gossiperl-client-js/lib/transport/chrome/transport.js" charset="utf-8"></script>
    <script type="text/javascript" src="/bower_components/gossiperl-client-js/lib/gossiperl.client.js" charset="utf-8"></script>

# Running

    var supervisor = new Gossiperl.Client.Supervisor();

# Connecting to an overlay

    supervisor.connect({
      overlayName:  "gossiper_overlay_remote",
      overlayPort:  6666,
      clientName:   "client-js",
      clientPort:   54321,
      clientSecret: "js-client-secret",
      symmetricKey: "<KEY>"
    });

Connecting with the listener:

    supervisor.connect({
      overlayName:  "gossiper_overlay_remote",
      overlayPort:  6666,
      clientName:   "client-js",
      clientPort:   54321,
      clientSecret: "js-client-secret",
      symmetricKey: "<KEY>"
    }, function( eventData ) {
      console.log( eventData );
    });

# Subscribing / unsubscribing

Subscribing:

    supervisor.subscribe( "gossiper_overlay_remote", ["member_in", "digestForwardableTest"] );

Unsubscribing:

    supervisor.unsubscribe( "gossiper_overlay_remote", ["member_in", "digestForwardableTest"] );

# Disconnecting from an overlay

    supervisor.disconnect( "gossiperl_overlay_remote" );

# Additional operations

## Checking current client state

    supervisor.getCurrentState( "gossiper_overlay_remote" );

## Get the list of current subscriptions

    supervisor.getSubscriptions( "gossiper_overlay_remote" );

## Sending arbitrary digests

    var digestData = [
      { name: 'property1', value: "Some string value", id: 0 },
      { name: 'property_bool', value: true, id: 1 },
      { name: 'and_an_i16', value: 123, id: 2, type_hint: 'i16' } ];

    supervisor.send( "gossiper_overlay_remote", digestData );

Thirft type is automatically read from the type of `value`. Numeric types will be sent as `i32` unless a type_hint is specified. Type hint can be used for the following types:

- `byte`
- `i16`
- `i32`
- `i64`
- `double`

## Reading custom digests

    var expectedDigestType = "...";
    var digestInfo = [
      { name: 'property1', value: "", id: 0 },
      { name: 'property_bool', value: false, id: 1 },
      { name: 'and_an_i16', value: 0, id: 2, type_hint: 'i16' } ];

    supervisor.read( expectedDigestType, binaryDigest, digestInfo );

`binaryDigest` is an envelope digest received as a forwarded message (forwarded event).

# Running tests

## Node.JS:

    nodeunit test/tests.node.js

## Browser

To run the tests for the browser please use the [Gossiperl Chrome client](https://github.com/gossiperl/gossiperl-client-chrome) project.
It's a Chrome extension launching into unit tests of the library.

Tests assume an overlay with the details specified in the test/...js files running.

# License

The MIT License (MIT)

Copyright (c) 2015 <NAME> <<EMAIL>>

{'fraction_non_alphanumeric': 0.12054647736405036, 'fraction_numerical': 0.015269220466113046, 'mean_word_length': 3.8430609597924774, 'pattern_counts': {'":': 2, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 1, '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': '276919', 'n_tokens_mistral': 1253, 'n_tokens_neox': 1180, 'n_words': 325}