1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
18 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
19 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
20 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
21 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
22 | };
|
23 | Object.defineProperty(exports, "__esModule", { value: true });
|
24 | exports.AbstractConnectionProvider = void 0;
|
25 | const inversify_1 = require("inversify");
|
26 | const event_1 = require("../event");
|
27 | const proxy_factory_1 = require("./proxy-factory");
|
28 | const channel_1 = require("../message-rpc/channel");
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | let AbstractConnectionProvider = class AbstractConnectionProvider {
|
35 | constructor() {
|
36 | this.onIncomingMessageActivityEmitter = new event_1.Emitter();
|
37 |
|
38 |
|
39 | this.reconnectChannelOpeners = [];
|
40 | }
|
41 | |
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | static createProxy(container, path, target) {
|
49 | throw new Error('abstract');
|
50 | }
|
51 | get onIncomingMessageActivity() {
|
52 | return this.onIncomingMessageActivityEmitter.event;
|
53 | }
|
54 | createProxy(path, arg) {
|
55 | const factory = arg instanceof proxy_factory_1.JsonRpcProxyFactory ? arg : new proxy_factory_1.JsonRpcProxyFactory(arg);
|
56 | this.listen({
|
57 | path,
|
58 | onConnection: c => factory.listen(c)
|
59 | });
|
60 | return factory.createProxy();
|
61 | }
|
62 | initializeMultiplexer() {
|
63 | const mainChannel = this.createMainChannel();
|
64 | mainChannel.onMessage(() => this.onIncomingMessageActivityEmitter.fire());
|
65 | this.channelMultiplexer = new channel_1.ChannelMultiplexer(mainChannel);
|
66 | }
|
67 | |
68 |
|
69 |
|
70 | listen(handler, options) {
|
71 | this.openChannel(handler.path, channel => {
|
72 | handler.onConnection(channel);
|
73 | }, options);
|
74 | }
|
75 | async openChannel(path, handler, options) {
|
76 | if (!this.channelMultiplexer) {
|
77 | throw new Error('The channel multiplexer has not been initialized yet!');
|
78 | }
|
79 | const newChannel = await this.channelMultiplexer.open(path);
|
80 | newChannel.onClose(() => {
|
81 | const { reconnecting } = Object.assign({ reconnecting: true }, options);
|
82 | if (reconnecting) {
|
83 | this.reconnectChannelOpeners.push(() => this.openChannel(path, handler, options));
|
84 | }
|
85 | });
|
86 | handler(newChannel);
|
87 | }
|
88 | };
|
89 | AbstractConnectionProvider = __decorate([
|
90 | (0, inversify_1.injectable)()
|
91 | ], AbstractConnectionProvider);
|
92 | exports.AbstractConnectionProvider = AbstractConnectionProvider;
|
93 |
|
\ | No newline at end of file |