soct
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

Node Soct

Proxy classes over socket.io.

Version 2.x.x w/ TypeScript!

Install

npm i -s soct

Getting Started

Class to proxy

// foo.js
 
class Foo {
    constructor() {
        this.state = {
            bar: true,
        };
    }
 
    get bar() {
        return this.state.bar;
    }
    set bar(val) {
        this.state.bar = val;
    }
 
    baz(val) {
        return val * 2;
    }
}
 
module.exports = Foo;

New Foo Service

//service.js
 
const {createSoctServer} = require("soct");
const Foo = require("./foo");
 
createSoctServer(
    new Foo(), // class to proxy; must be an instance of the class
    5000, // port to proxy on
);

Use Foo Proxy

// app.js
 
const {createSoctClient} = require("soct");
const Foo = require("./foo");
 
const foo = createSoctClient(
    Foo, // class definition
    5000, // port to proxy on (matches previous service)
);
 
const run = async () => {
    console.log(await foo.bar); // => true
    foo.bar = false;
    console.log(await foo.bar); // => false
    console.log(await foo.baz(5)); // => 10
};
 
run();

Package Sidebar

Install

npm i soct

Weekly Downloads

2

Version

2.0.1

License

MIT

Unpacked Size

20.4 kB

Total Files

30

Last publish

Collaborators

  • jhenson29