ws-rmi
Version:
A Remote Method Invocation implementation written in JavaScript utilising the WebSocket protocol
59 lines (58 loc) • 1.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RMIManager = void 0;
const RMIClient_1 = require("./RMIClient");
const RMIRemote_1 = require("./RMIRemote");
const ConsoleLogger_1 = require("./ConsoleLogger");
/**
* The core class for handling RMI connections. This can be used to invoke remote functions or expose functions to
* the remote.
*
* NOTE: As WebSockets are bidirectional, "client" and "remote" are arbitrary. A browser can be both client and remote
* if it both calls functions on a server while also exposing functions to the server.
*/
class RMIManager {
/**
* The WebSocket connection to use to perform RMI tasks.
*
* @private
*/
_ws;
/**
* The configuration to apply to the RMI connections.
*
* @private
*/
_config;
/**
* Constructs a new manager instance.
*
* @param ws The WebSocket connection to use to perform RMI tasks. NOTE: This should be an active connection!
* @param config Configuration to be applied.
*/
constructor(ws, config = { logger: ConsoleLogger_1.ConsoleLogger }) {
this._ws = ws;
this._config = config;
}
get ws() {
return this._ws;
}
get config() {
return this._config;
}
/**
* Constructs a client interface to use to invoke remote functions.
*/
getRemote() {
return (0, RMIClient_1.createRMIClient)(this);
}
/**
* Exposes the given functions to be able to be invoked by the client.
*
* @param functions An object (generally a class) that will be exposed.
*/
exposeFunctions(functions) {
(0, RMIRemote_1.exposeFunctions)(this, functions);
}
}
exports.RMIManager = RMIManager;