@pioneer-platform/pioneer-events 8.1.30 → 8.1.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/lib/index.js +199 -118
  2. package/package.json +1 -2
  3. package/tsconfig.json +1 -1
package/lib/index.js CHANGED
@@ -1,14 +1,50 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
2
38
  Object.defineProperty(exports, "__esModule", { value: true });
3
39
  exports.Events = void 0;
4
- const TAG = " | ws-client | ";
5
- const log = require("@pioneer-platform/loggerdog")();
6
- const EventEmitter = require('events');
7
- const io = require('socket.io-client');
8
- const wait = require('wait-promise');
9
- const sleep = wait.sleep;
10
- class Events {
11
- constructor(config) {
40
+ var TAG = " | ws-client | ";
41
+ var log = require("log");
42
+ var EventEmitter = require('events');
43
+ var io = require('socket.io-client');
44
+ var wait = require('wait-promise');
45
+ var sleep = wait.sleep;
46
+ var Events = /** @class */ (function () {
47
+ function Events(config) {
12
48
  this.wss = config.wss;
13
49
  this.isConnected = false;
14
50
  this.isTestnet = false;
@@ -16,127 +52,172 @@ class Events {
16
52
  this.queryKey = config.queryKey;
17
53
  this.isPaired = false;
18
54
  this.events = new EventEmitter();
19
- this.init = async function () {
20
- let tag = TAG + " | init_events | ";
21
- try {
22
- this.socket = io.connect(this.wss, {
23
- reconnect: true,
24
- rejectUnauthorized: false
55
+ this.init = function () {
56
+ return __awaiter(this, void 0, void 0, function () {
57
+ var tag, e_1;
58
+ var _this = this;
59
+ return __generator(this, function (_a) {
60
+ switch (_a.label) {
61
+ case 0:
62
+ tag = TAG + " | init_events | ";
63
+ _a.label = 1;
64
+ case 1:
65
+ _a.trys.push([1, 5, , 6]);
66
+ this.socket = io.connect(this.wss, {
67
+ reconnect: true,
68
+ rejectUnauthorized: false
69
+ });
70
+ //sub
71
+ this.socket.on('connect', function () {
72
+ log.debug(tag, 'Connected to ' + _this.wss);
73
+ _this.isConnected = true;
74
+ //rejoin
75
+ if (_this.username) {
76
+ _this.pair();
77
+ }
78
+ else {
79
+ _this.subscribeToKey();
80
+ }
81
+ });
82
+ this.socket.on('subscribedToUsername', function (event) {
83
+ log.debug(tag, 'subscribed to ' + event.username, " id: " + event.socketId);
84
+ _this.isPaired = true;
85
+ _this.username = event.username;
86
+ });
87
+ this.socket.on('message', function (message) {
88
+ //TODO only emit expected messages?
89
+ //if(message.type === "payment_request"){}
90
+ _this.events.emit('message', message);
91
+ });
92
+ this.socket.on('blocks', function (message) {
93
+ //TODO only emit expected messages?
94
+ //if(message.type === "payment_request"){}
95
+ _this.events.emit('message', message);
96
+ });
97
+ //sub to errors
98
+ this.socket.on('errorMessage', function (message) {
99
+ log.error(tag, "error: ", message);
100
+ if (message.code && message.code === 6)
101
+ throw Error(" Failed to connect!");
102
+ });
103
+ this.socket.on('invocation', function (message) {
104
+ log.debug('invocation: ', message);
105
+ _this.events.emit('message', message);
106
+ });
107
+ _a.label = 2;
108
+ case 2:
109
+ if (!!this.isConnected) return [3 /*break*/, 4];
110
+ return [4 /*yield*/, sleep(300)];
111
+ case 3:
112
+ _a.sent();
113
+ return [3 /*break*/, 2];
114
+ case 4: return [2 /*return*/, true];
115
+ case 5:
116
+ e_1 = _a.sent();
117
+ log.error(tag, e_1);
118
+ throw e_1;
119
+ case 6: return [2 /*return*/];
120
+ }
25
121
  });
26
- //sub
27
- this.socket.on('connect', () => {
28
- log.debug(tag, 'Connected to ' + this.wss);
29
- this.isConnected = true;
30
- //rejoin
31
- if (this.username) {
32
- this.pair();
122
+ });
123
+ };
124
+ this.setUsername = function (username) {
125
+ return __awaiter(this, void 0, void 0, function () {
126
+ var tag;
127
+ return __generator(this, function (_a) {
128
+ tag = TAG + " | startSocket | ";
129
+ try {
130
+ this.username = username;
33
131
  }
34
- else {
35
- this.subscribeToKey();
132
+ catch (e) {
133
+ log.error(tag, "e: ", e);
36
134
  }
135
+ return [2 /*return*/];
37
136
  });
38
- this.socket.on('subscribedToUsername', (event) => {
39
- log.debug(tag, 'subscribed to ' + event.username, " id: " + event.socketId);
40
- this.isPaired = true;
41
- this.username = event.username;
42
- });
43
- this.socket.on('message', (message) => {
44
- //TODO only emit expected messages?
45
- //if(message.type === "payment_request"){}
46
- this.events.emit('message', message);
47
- });
48
- this.socket.on('blocks', (message) => {
49
- //TODO only emit expected messages?
50
- //if(message.type === "payment_request"){}
51
- this.events.emit('blocks', message);
52
- });
53
- //sub to errors
54
- this.socket.on('errorMessage', function (message) {
55
- log.error(tag, "error: ", message);
56
- if (message.code && message.code === 6)
57
- throw Error(" Failed to connect!");
58
- });
59
- this.socket.on('invocations', (message) => {
60
- log.debug('invocation: ', message);
61
- this.events.emit('invocations', message);
62
- });
63
- //dont release to connect
64
- while (!this.isConnected) {
65
- await sleep(300);
66
- }
67
- return true;
68
- }
69
- catch (e) {
70
- log.error(tag, e);
71
- throw e;
72
- }
73
- };
74
- this.setUsername = async function (username) {
75
- let tag = TAG + " | startSocket | ";
76
- try {
77
- this.username = username;
78
- }
79
- catch (e) {
80
- log.error(tag, "e: ", e);
81
- }
137
+ });
82
138
  };
83
- this.subscribeToInvocation = async function (invocationId) {
84
- let tag = TAG + " | subscribeToInvocation | ";
85
- try {
86
- //attempt join
87
- this.socket.emit('join', {
88
- invocationId
139
+ this.subscribeToInvocation = function (invocationId) {
140
+ return __awaiter(this, void 0, void 0, function () {
141
+ var tag;
142
+ return __generator(this, function (_a) {
143
+ tag = TAG + " | subscribeToInvocation | ";
144
+ try {
145
+ //attempt join
146
+ this.socket.emit('join', {
147
+ invocationId: invocationId
148
+ });
149
+ return [2 /*return*/, true];
150
+ }
151
+ catch (e) {
152
+ log.error(tag, "e: ", e);
153
+ throw e;
154
+ }
155
+ return [2 /*return*/];
89
156
  });
90
- return true;
91
- }
92
- catch (e) {
93
- log.error(tag, "e: ", e);
94
- throw e;
95
- }
157
+ });
96
158
  };
97
- this.subscribeToKey = async function () {
98
- let tag = TAG + " | subscribeToKey | ";
99
- try {
100
- //attempt join
101
- this.socket.emit('join', {
102
- queryKey: config.queryKey
159
+ this.subscribeToKey = function () {
160
+ return __awaiter(this, void 0, void 0, function () {
161
+ var tag;
162
+ return __generator(this, function (_a) {
163
+ tag = TAG + " | subscribeToKey | ";
164
+ try {
165
+ //attempt join
166
+ this.socket.emit('join', {
167
+ queryKey: config.queryKey
168
+ });
169
+ return [2 /*return*/, true];
170
+ }
171
+ catch (e) {
172
+ log.error(tag, "e: ", e);
173
+ throw e;
174
+ }
175
+ return [2 /*return*/];
103
176
  });
104
- return true;
105
- }
106
- catch (e) {
107
- log.error(tag, "e: ", e);
108
- throw e;
109
- }
177
+ });
110
178
  };
111
- this.pair = async function (username) {
112
- let tag = TAG + " | startSocket | ";
113
- try {
114
- if (username)
115
- this.username = username;
116
- if (!this.username)
117
- throw Error("103: can not pair without username!");
118
- //attempt join
119
- this.socket.emit('join', {
120
- username: this.username,
121
- queryKey: config.queryKey
179
+ this.pair = function (username) {
180
+ return __awaiter(this, void 0, void 0, function () {
181
+ var tag;
182
+ return __generator(this, function (_a) {
183
+ tag = TAG + " | startSocket | ";
184
+ try {
185
+ if (username)
186
+ this.username = username;
187
+ if (!this.username)
188
+ throw Error("103: can not pair without username!");
189
+ //attempt join
190
+ this.socket.emit('join', {
191
+ username: this.username,
192
+ queryKey: config.queryKey
193
+ });
194
+ //TODO validate paired?
195
+ return [2 /*return*/, true];
196
+ }
197
+ catch (e) {
198
+ log.error(tag, "e: ", e);
199
+ throw e;
200
+ }
201
+ return [2 /*return*/];
122
202
  });
123
- //TODO validate paired?
124
- return true;
125
- }
126
- catch (e) {
127
- log.error(tag, "e: ", e);
128
- throw e;
129
- }
203
+ });
130
204
  };
131
- this.disconnect = async function () {
132
- let tag = TAG + " | disconnect | ";
133
- try {
134
- return this.socket.disconnect();
135
- }
136
- catch (e) {
137
- log.error(tag, "e: ", e);
138
- }
205
+ this.disconnect = function () {
206
+ return __awaiter(this, void 0, void 0, function () {
207
+ var tag;
208
+ return __generator(this, function (_a) {
209
+ tag = TAG + " | disconnect | ";
210
+ try {
211
+ return [2 /*return*/, this.socket.disconnect()];
212
+ }
213
+ catch (e) {
214
+ log.error(tag, "e: ", e);
215
+ }
216
+ return [2 /*return*/];
217
+ });
218
+ });
139
219
  };
140
220
  }
141
- }
221
+ return Events;
222
+ }());
142
223
  exports.Events = Events;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/pioneer-events",
3
- "version": "8.1.30",
3
+ "version": "8.1.31",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/main.d.ts",
6
6
  "scripts": {
@@ -14,7 +14,6 @@
14
14
  "refresh": "rm -rf ./node_modules ./package-lock.json && npm install"
15
15
  },
16
16
  "dependencies": {
17
- "@pioneer-platform/loggerdog": "^8.1.17",
18
17
  "@pioneer-platform/pioneer-types": "^8.1.44",
19
18
  "@types/node": "^13.13.14",
20
19
  "axios": "^0.19.2",
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "es2018",
3
+ "target": "es5",
4
4
  "module": "commonjs",
5
5
  "lib": ["es6", "es2015", "dom"],
6
6
  "declaration": true,