1.0.1 • Published 3 years ago

@yesness/netclass v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

netclass

Proxy classes, objects, and functions over a network connection.

Installation

$ npm install @yesness/netclass

Usage

import NetClass from '@yesness/netclass';

// ===== SERVER SIDE =====
class Foo {
    static bar: string = 'hello';

    async getBar() {
        return bar;
    }

    async setBar(bar: string) {
        Foo.bar = bar;
    }
}

const server = NetClass.createServer({ object: Foo });
// On socket connection
server.connect(socket);

// ===== CLIENT SIDE =====
const client = NetClass.createClient(socket);
const ClientFoo = client.getObject();
console.log(await ClientFoo.getBar()); // 'hello'
await ClientFoo.setBar('goodbye');
console.log(await ClientFoo.getBar()); // 'goodbye'

More Examples

See the unit tests for more examples.