forked from StreamMachine/StreamMachine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpc_proxy.js
51 lines (45 loc) · 1.46 KB
/
rpc_proxy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
var RPCProxy,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
module.exports = RPCProxy = (function(_super) {
__extends(RPCProxy, _super);
function RPCProxy(a, b) {
this.a = a;
this.b = b;
this.messages = [];
this._aFunc = (function(_this) {
return function(msg, handle) {
_this.messages.push({
sender: "a",
msg: msg,
handle: handle != null
});
_this.b.send(msg, handle);
if (msg.err) {
return _this.emit("error", msg);
}
};
})(this);
this._bFunc = (function(_this) {
return function(msg, handle) {
_this.messages.push({
sender: "b",
msg: msg,
handle: handle != null
});
_this.a.send(msg, handle);
if (msg.err) {
return _this.emit("error", msg);
}
};
})(this);
this.a.on("message", this._aFunc);
this.b.on("message", this._bFunc);
}
RPCProxy.prototype.disconnect = function() {
this.a.removeListener("message", this._aFunc);
return this.b.removeListener("message", this._bFunc);
};
return RPCProxy;
})(require("events").EventEmitter);
//# sourceMappingURL=rpc_proxy.js.map