2.0.1 • Published 4 years ago

soct v2.0.1

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

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();
2.0.1

4 years ago

1.1.2

4 years ago

1.1.1

5 years ago

1.0.5

5 years ago

1.1.0

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago