UNPKG

1.76 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const util_1 = require("../util");
4const bsp_1 = require("bsp");
5var RpcEvents;
6(function (RpcEvents) {
7 RpcEvents[RpcEvents["HANDSHAKE"] = 0] = "HANDSHAKE";
8 RpcEvents[RpcEvents["CONNECT"] = 1] = "CONNECT";
9 RpcEvents[RpcEvents["BROADCAST"] = 2] = "BROADCAST";
10 RpcEvents[RpcEvents["INVOKE"] = 3] = "INVOKE";
11 RpcEvents[RpcEvents["RETURN"] = 4] = "RETURN";
12 RpcEvents[RpcEvents["YIELD"] = 5] = "YIELD";
13 RpcEvents[RpcEvents["THROW"] = 6] = "THROW";
14 RpcEvents[RpcEvents["PING"] = 7] = "PING";
15 RpcEvents[RpcEvents["PONG"] = 8] = "PONG";
16})(RpcEvents = exports.RpcEvents || (exports.RpcEvents = {}));
17class RpcChannel {
18 constructor(options, host) {
19 this.host = "0.0.0.0";
20 this.port = 9000;
21 this.path = "";
22 if (typeof options === "object") {
23 Object.assign(this, options);
24 }
25 else if (typeof options === "number") {
26 Object.assign(this, { host, port: options });
27 }
28 else {
29 this.path = util_1.absPath(options);
30 }
31 this.codec || (this.codec = "CLONE");
32 this.bsp = new bsp_1.BSP(util_1.getCodecOptions(this.codec));
33 }
34 get dsn() {
35 let dsn = this.path ? "ipc://" : "rpc://";
36 if (this.path) {
37 dsn += this.path;
38 }
39 else if (this.port) {
40 if (this.host) {
41 dsn += this.host + ":";
42 }
43 dsn += this.port;
44 }
45 return dsn;
46 }
47 onError(handler) {
48 this.errorHandler = handler;
49 }
50 static registerError(ctor) {
51 global[ctor.name] = ctor;
52 }
53}
54exports.RpcChannel = RpcChannel;
55//# sourceMappingURL=channel.js.map
\No newline at end of file