2.0.3 • Published 1 year ago

@primafuture/remote-async-call v2.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

@primafuture/remote-async-call

Installation

npm install @primafuture/remote-async-call

Package can be used directly in the browser without the use of package managers/bundlers as well: UMD version from unpkg.com.

Usage

import rac from '@primafuture/remote-async-call';

// create connection
const ws = new websocket.WebSocket("ws://...");
const racProxy = new rac.RACProxy(new rac.WebsocketCommunicationConnection(ws));

// wait for connection
racProxy.onConnected(() => {
	// ...
});

RPC model

// register method
racProxy.register('sum', ([a, b]:[number, number]) => {
	const res = a + b;
	return res;
});

// call method
let result = await racProxy.call('sum', [2, 3]);
console.log(result);

Pub/Sub model

// subscribe event
racProxy.subscribe('event', (args) => {
	console.log('on event', args);
});

// publish event
await racProxy.publish('event', [1, 2, 3]);
2.0.3

1 year ago

2.0.2

1 year ago

2.0.0

1 year ago

1.1.0

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago