0.5.6 • Published 7 months ago

clearthru v0.5.6

Weekly downloads
7
License
MIT
Repository
github
Last release
7 months ago

ClearThru

This is a communication library that provides remote procedure calls (RPC) and events over websocket.

Features:

  • Use Promises
  • Wrap Js Classes (extends clearthru.API) server-side and expose its methods that will be callable from the client.
  • Server Methods can instantiate new clearthru.API Objects that could be returned to the client. This allows scoped APIs in an Object-Oriented pattern.
  • Scalable. Server could be shutted off and the client would keep its state and try to resume connection. On a successful connection, even with a new server instance, the client objects APIs will restore their context and resume normal operation.

Documentation

Server

//require the server
var clearthru = require('clearthru').server

//Define an API
class MyAPI extends clearthru.API {
  method2() {
  }
}
// This register an object
clearthru.register(MyAPI)

class Boot extends clearthru.API {
  method1() {
    return this.create("MyAPI")
  }
}
// This register the bootstrap object 
clearthru.bootstrap(Boot)

...

//Create a http server
var server = http.createServer(app)
//Attach clearthru to the server
clearthru.attach(server, SECRETKEY)

Client

// Require the client
var client = require('clearthru').client

// Connect to the server
var boot = await client.init('ws://localhost:3082')
// boot is now mapped to an instance of Boot on the server

// Call a method as a Promise
var api = await boot.method1()
// In this example, api will map to an instance of MyAPI on the server

await api.method2()

Connect/Express middleware

// Server
var connect = require('connect')
var app = connect()
var clearthru = require("clearthru")
// Allow the browser to download the client script. URL: /clearthru-client
app.use(clearthru.browserClient())
<!--This will provide the 'require()' function-->
<script src="/clearthru-client"></script>
<script>

var client = require('clearthru').client

//...

</script>

Example

Look in the example folder. First, run npm install in the root folder and in example folder.

cd example
node svr.js # This will start a server demo
# Either you browse http://localhost:3082 or you run:
node cli.js # a client demo
0.5.6

7 months ago

0.5.5

10 months ago

0.5.4

3 years ago

0.5.3

3 years ago

0.5.2

4 years ago

0.5.1

4 years ago

0.5.0

4 years ago

0.4.7

5 years ago

0.4.6

5 years ago

0.4.5

5 years ago

0.4.4

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago