<commit_before>## Information

<table>
<tr>
<td>Package</td><td>vein</td>
</tr>
<tr>
<td>Description</td>
<td>WebSocket RPC</td>
</tr>
<tr>
<td>Node Version</td>
<td>>= 0.4</td>
</tr>
</table>

## Example

### Server

```javascript
var Vein = require('vein');
var server = http.createServer().listen(8080);
var rpc = new Vein(server);

rpc.add('greetings', function (send, socket, first, last){
  send("Hey there " + first + " " + last!");
});
```

### Client

```javascript
var vein = new Vein();
vein.ready(function (){
  vein.greetings("John", "Foobar", function (res){
     // res === "Hey there <NAME>!"
    console.log(res);
  });
});
```

## Usage

Documentation is horrible. Will update later.

### Server
```javascript
var http = require('http');
var Vein = require('vein');
var server = http.createServer().listen(8080);

var vein = new Vein(server, {
  //options go here
});
/*
  Valid options:
  prefix - vein endpoint (default: "vein")
  sessionName - cookie name (default: "VEINSESSID-[prefix]")
  noTrack - disable pubsub for performance (default: false)
  response_limit - reopen socket after this much data (default: 128k)
*/

// A service is a function that gets called every time a client calls it
// The format is function (send, socket, args...)
// args can be any JSON-friendly data sent from the client
// You can pass any JSON-friendly objects as arguments to the send
// and they will be applied to the callback on the client.
vein.add('someService', function (send, socket, name, num) {
  send("Hey there " + name + " I got your number " + num);
});

// The server can assign a session to the client via send.session.
// Any services called will have access to the session value via socket.session
// This session will persist between page loads/connects based on your settings
// send.session is a simple way to set a tracking cookie not a session store
vein.add('login', function (send, socket, username, password) {
  if (username === 'username' && password === '<PASSWORD>') {
    send.session('success! (some unique key)');
    send(); // Call the login callback with no error
  } else {
    send('Invalid username or password');
  }
});

// If you have tracking enabled (noTrack=false) you can use send.all
// to broadcast a message to all currently connected clients that are subscribed to the service
// A hash of clients is available in vein.clients
vein.add('someOtherService', function (send, socket, msg) {
  send.all(msg);
});
```

### Browser Client

```javascript
var vein = new Vein({
  //options go here
});
/*
  Valid options:
  host - server running vein (default: location.origin)
  prefix - vein endpoint (default: "vein")
  sessionName - cookie name (default: "VEINSESSID-[prefix]")
  sessionLength - time before cookie expires (default: session)
  debug - extra information (default: false)
*/

//When the vein is ready this function will be called
vein.ready(function (services) {
  // services is an array of service names available to use
  // Any code using vein should be kicked off here
  // When calling a service the format is vein.<service name>(args..., callback)
  // You can pass any JSON-friendly objects as arguments and they will be applied to the
  // service on the server.
  vein.someService('john', 2, function (err, result) {
    console.log(result);
  });

  // Prefixing a service with .subscribe allows the server to send unsolicited messages
  // to the client. Subscribing to a service does not communicate to the server in any way.
  vein.subscribe.someOtherService(function (message) {
    console.log(message);
  });

  // When the server assigns a session it is saved as a cookie with the client preferences.
  // Make sure the client and server cookie preferences match.
  // Session data can be accessed via .getSession() and .clearSession()
  vein.login('username', 'pass123', function (err) {
    if (err) {
      alert(err);
    } else {
      console.log(vein.getSession());
      console.log(vein.clearSession());
    }
  });
});

//If the vein is closed this function will be called
vein.close(function () {
  console.log("Connection lost!");
});
```
<commit_msg>readme update<commit_after>## Information

<table>
<tr>
<td>Package</td><td>vein</td>
</tr>
<tr>
<td>Description</td>
<td>RPC/PubSub via WebSockets</td>
</tr>
<tr>
<td>Node Version</td>
<td>>= 0.4</td>
</tr>
</table>

## Example

### Server

##### With server

```javascript
var Vein = require('vein');
var server = http.createServer().listen(8080);
var vein = new Vein(server);

vein.add('greetings', function (res, first, last){
  res.send("Hey there " + first + " " + last!");
});
```

##### Without server

```javascript
var Vein = require('vein');
var vein = new Vein(8080);

vein.add('greetings', function (res, first, last){
  res.send("Hey there " + first + " " + last!");
});
```

### Client

```javascript
var vein = new Vein();
vein.ready(function (){
  vein.greetings("John", "Foobar", function (res){
    // res === "Hey there <NAME>!"
  });
});
```

## Usage

### Server
```javascript
var Vein = require('vein');

var vein = new Vein(8080, {
/*
  Valid options:
  path - prefix path (default: "/vein")
  resource - change to allow multiple servers for one endpoint (default: "default")
*/
});

// A service is a function that gets called every time a client calls it
// The format is function (send, socket, args...)
// args can be any JSON-friendly data sent from the client
// You can pass any JSON-friendly objects as arguments to the send
// and they will be applied to the callback on the client.
vein.add('someService', function (res, name, num) {
  res.send("Hey there " + name + " I got your number " + num);
});

// The server can assign and access cookies to the client via res.cookie().
vein.add('login', function (res, username, password) {
  if (res.cookie('login')) {
    res.send('You already logged in!');
  } else if (username === 'username' && password === '<PASSWORD>') {
    res.cookie('login', 'success!');
    res.send();
  } else {
    res.send('Invalid username or password');
  }
});

// You can use res.publish to send a message to everyone subscribing to a service
vein.add('someOtherService', function (res, msg) {
  res.publish(msg);
});
```

### Browser Client

```javascript
var vein = new Vein({
/*
  Valid options:
  host - server location (default: window.location.hostname)
  port - server port (default: window.location.port)
  secure - use SSL (default: window.location.protocol)
  path - prefix path (default: "/vein")
  resource - change to allow multiple servers for one endpoint (default: "default")
*/
});

//When the vein is ready this function will be called
vein.ready(function (services) {
  // services is an array of service names available to use
  // When calling a service the format is vein.<service name>(args..., callback)
  // You can pass any JSON-friendly objects as arguments.
  vein.someService('john', 2, function (err, result) {
    console.log(result);
  });

  // Prefixing a service with .subscribe allows the server to send unsolicited messages
  // to the client. Subscribing to a service does not communicate to the server in any way.
  vein.subscribe.someOtherService(function (message) {
    console.log(message);
  });

  //The server can assign cookies to the client
  // You can read and write these cookies by using vein.cookie()
  vein.login('username', 'pass123', function (err) {
    if (err) {
      alert(err);
      vein.cookie('login', 'fail'); //write
    } else {
      console.log(vein.cookie('login')); //read
      vein.cookie('login', null); //delete
    }
  });
});

//If the vein is closed this function will be called
vein.close(function () {
  console.log("Connection lost!");
});
```

{'fraction_non_alphanumeric': 0.1473248901524942, 'fraction_numerical': 0.004523132592401137, 'mean_word_length': 3.681790683605566, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 51, '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': '1283901', 'n_tokens_mistral': 2394, 'n_tokens_neox': 2305, 'n_words': 878}