Lithium

Lithium is a data centric WebSocket library for both Node.js and the Browser.

This project is maintained by BonsaiDen

Lithium

Lithium is a data centric WebSocket library for both Node.js and the Browser.

Installation

Client

<script type="text/javascript" src="lithium.client.js"></script>

Server

npm install lithium

Usage

Below is an example of a simple, JSON based echo server.

Client

var client = lithium.Client(function(client) {

    client.on('message', function(msg) {
        ...
    });

    client.send({
        msg: 'Hello World'
    });

}, JSON.stringify, JSON.parse);

Server

var lithium = require('lithium');

var server = new lithium.Server(function(remote) {

    remote.accept();
    remote.on('message', function(msg) {
        remote.send(msg);
    });

}, JSON.stringify, JSON.parse);

server.listen(8000);

Features

API

Server

A http.Server-like interface for managing web socket connections.

Methods

Events

Remotes

Each remote encapsulate a single web socket connection to a client.

A remote is only recognized as being connected after it was accepted.

Properties

Methods

Events

Client

A thin wrapper around the browser side WebSocket object, providing a interface that is consistent with the lithium server.

Methods

Events

License

Lithium is licensed under MIT.