1.0.0 • Published 10 years ago
ws-telegraph v1.0.0
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
10 years ago
3.0.1
10 years ago
3.0.0
10 years ago
2.0.1
10 years ago
2.0.1-beta.4
10 years ago
2.0.1-beta.3
10 years ago
2.0.1-beta.2
10 years ago
2.0.1-beta.1
10 years ago
2.0.1-beta.0
10 years ago
1.0.1
10 years ago
1.0.0
10 years ago