2.0.1 • Published 8 years ago

ws-telegraph v2.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

WS-Telegraph

This is a simple set of scripts that implement RPC over WebSocket. As communication layer used engine.io library.

User Guide

The package provides two classes: WsTgServer and WsTgClient.

WsTgServer based on Engine.IO and processes requests. WsTgClient provides a way
to invoke methods on the server through websocket and obtains the result of the call.

Old js-style

const WsTgClient = require('ws-telegraph').WsTgClient;
const WsTgServer = require('ws-telegraph').WsTgServer;

class Server extend  WsTgServer {
    onHello(userName){
        return new Promise((resolve)=>{
            return resolve(`Hello, ${userName}`);
        });
    }
}

class Client extent WsTgClient {
    callHello(userName){
        return this.callAndWait('hello', 'Bob'); // Promise with result "Hello, Bob"
    }
}

With Babel

import {WsTgClient, WsTgServer} from 'ws-telegraph';

class Server extend  WsTgServer {
    async onHello(userName){
        return `Hello, ${userName}`;
    }
}

class Client extent WsTgClient {
    async callHello(userName){
        return await this.callAndWait('hello', 'Bob'); 
    }
}

TODO

  • Error handling

Tests

npm run test. The default port of the server is 3000, if not set another by process.env.PORT.

3.0.2

8 years ago

3.0.1

8 years ago

3.0.0

8 years ago

2.0.1

8 years ago

2.0.1-beta.4

8 years ago

2.0.1-beta.3

8 years ago

2.0.1-beta.2

8 years ago

2.0.1-beta.1

8 years ago

2.0.1-beta.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago