soct

Proxy classes over socket.io.

Usage no npm install needed!

<script type="module">
  import soct from 'https://cdn.skypack.dev/soct';
</script>

README

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