@tdxvolt/volt-client-grpc 0.14.58 → 0.14.61
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.
- package/lib/index.cjs +122 -105
- package/package.json +2 -2
- package/src/volt-client-internal.js +3 -3
- package/src/volt-client.js +4 -4
- package/src/volt-connection.js +106 -98
- package/src/volt-credential.js +9 -0
package/lib/index.cjs
CHANGED
|
@@ -523,6 +523,14 @@ class VoltCredential {
|
|
|
523
523
|
return this._cryptoCache;
|
|
524
524
|
}
|
|
525
525
|
|
|
526
|
+
get clientId() {
|
|
527
|
+
return this._cryptoCache.client_id;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
get publicKey() {
|
|
531
|
+
return pki$1.publicKeyToPem(this.getKey().publicKey);
|
|
532
|
+
}
|
|
533
|
+
|
|
526
534
|
get voltFingerprint() {
|
|
527
535
|
return this._voltFingerprint;
|
|
528
536
|
}
|
|
@@ -603,6 +611,7 @@ class VoltCredential {
|
|
|
603
611
|
aud: audience,
|
|
604
612
|
iat: Math.floor(Date.now() / 1000) - ttl,
|
|
605
613
|
exp: Math.floor(Date.now() / 1000) + ttl,
|
|
614
|
+
sub: this._cryptoCache.client_id,
|
|
606
615
|
};
|
|
607
616
|
|
|
608
617
|
let sharedKey;
|
|
@@ -1082,50 +1091,55 @@ class GRPCCall extends EventEmitter__default["default"] {
|
|
|
1082
1091
|
const log$2 = debug__default["default"]("volt-client-grpc:volt-connection");
|
|
1083
1092
|
|
|
1084
1093
|
function _cleanUp(immediateReconnect) {
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1094
|
+
this._connectionId = "";
|
|
1095
|
+
|
|
1096
|
+
if (this._pingTimer) {
|
|
1097
|
+
clearTimeout(this._pingTimer);
|
|
1098
|
+
this._pingTimer = 0;
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
if (this._pingTimeoutTimer) {
|
|
1102
|
+
clearTimeout(this._pingTimeoutTimer);
|
|
1103
|
+
this._pingTimeoutTimer = 0;
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
if (
|
|
1107
|
+
!this._dying &&
|
|
1108
|
+
(immediateReconnect || (this._autoRetry && !this._reconnectTimer))
|
|
1109
|
+
) {
|
|
1110
|
+
this._reconnectTimer = setTimeout(
|
|
1111
|
+
() => {
|
|
1112
|
+
this._reconnectTimer = 0;
|
|
1113
|
+
_doConnect.call(this, this._helloPayload);
|
|
1114
|
+
},
|
|
1115
|
+
immediateReconnect ? 0 : this._reconnectInterval,
|
|
1116
|
+
);
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
if (this.call?.writable) {
|
|
1120
|
+
this.call.end();
|
|
1121
|
+
}
|
|
1113
1122
|
}
|
|
1114
1123
|
|
|
1115
1124
|
function _connectionTimeoutHandler() {
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1125
|
+
log$2("server timed out");
|
|
1126
|
+
this.emit("connected", false);
|
|
1127
|
+
_cleanUp.call(this);
|
|
1119
1128
|
}
|
|
1120
1129
|
|
|
1121
|
-
function _doConnect() {
|
|
1122
|
-
|
|
1130
|
+
function _doConnect(connectHello) {
|
|
1131
|
+
this.call = new GRPCCall(this._voltClient, "Connect", "METHOD_TYPE_BIDI");
|
|
1132
|
+
|
|
1133
|
+
const grpcClient = this._voltClient.getVoltAPIClient();
|
|
1134
|
+
|
|
1135
|
+
let helloPayload = connectHello;
|
|
1136
|
+
if (!connectHello) {
|
|
1137
|
+
log$2("defaulting hello payload");
|
|
1138
|
+
helloPayload = {
|
|
1139
|
+
hello: {},
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
1123
1142
|
|
|
1124
|
-
const grpcClient = this._voltClient.getVoltAPIClient();
|
|
1125
|
-
const helloPayload = {
|
|
1126
|
-
hello: {},
|
|
1127
|
-
};
|
|
1128
|
-
|
|
1129
1143
|
this.call.on("error", (err) => {
|
|
1130
1144
|
log$2("error on connection stream [%s]", err.message);
|
|
1131
1145
|
_cleanUp.call(this);
|
|
@@ -1146,10 +1160,11 @@ function _doConnect() {
|
|
|
1146
1160
|
_startPingTimer.call(this);
|
|
1147
1161
|
break;
|
|
1148
1162
|
}
|
|
1149
|
-
case "
|
|
1150
|
-
if (!this.
|
|
1151
|
-
this.
|
|
1152
|
-
|
|
1163
|
+
case "acknowledge": {
|
|
1164
|
+
if (!this._connectionId) {
|
|
1165
|
+
this._connectionId = response.acknowledge.connection_id;
|
|
1166
|
+
log$2("connection id is %s", this._connectionId);
|
|
1167
|
+
this.emit("connected", this._connectionId);
|
|
1153
1168
|
}
|
|
1154
1169
|
break;
|
|
1155
1170
|
}
|
|
@@ -1165,74 +1180,76 @@ function _doConnect() {
|
|
|
1165
1180
|
});
|
|
1166
1181
|
|
|
1167
1182
|
this.call.on("end", () => {
|
|
1168
|
-
if (this.
|
|
1183
|
+
if (this._connectionId) {
|
|
1169
1184
|
this.emit("connected", false);
|
|
1170
1185
|
}
|
|
1171
1186
|
_cleanUp.call(this);
|
|
1172
1187
|
});
|
|
1173
1188
|
|
|
1174
|
-
|
|
1189
|
+
this.call.start(grpcClient, helloPayload);
|
|
1175
1190
|
|
|
1176
|
-
|
|
1191
|
+
_startPingTimer.call(this);
|
|
1177
1192
|
}
|
|
1178
1193
|
|
|
1179
1194
|
function _startPingTimer() {
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1195
|
+
if (this._pingTimer) {
|
|
1196
|
+
log$2("ping timer running");
|
|
1197
|
+
return;
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
this._pingTimer = setTimeout(() => {
|
|
1201
|
+
// Send next ping to server.
|
|
1202
|
+
const request = { ping: { timestamp: Date.now() } };
|
|
1203
|
+
|
|
1204
|
+
log$2("pinging Volt");
|
|
1205
|
+
this.call.write(request);
|
|
1206
|
+
|
|
1207
|
+
this._pingTimer = 0;
|
|
1208
|
+
|
|
1209
|
+
// Schedule a timeout if we don't hear back from the server.
|
|
1210
|
+
if (this._pingTimeoutTimer) {
|
|
1211
|
+
clearTimeout(this._pingTimeoutTimer);
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
this._pingTimeoutTimer = setTimeout(
|
|
1215
|
+
_connectionTimeoutHandler.bind(this),
|
|
1216
|
+
this._timeoutInterval,
|
|
1217
|
+
);
|
|
1218
|
+
}, this._pingInterval);
|
|
1204
1219
|
}
|
|
1205
1220
|
|
|
1206
1221
|
class VoltConnection extends EventEmitter__default["default"] {
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1222
|
+
constructor(voltClient, grpc) {
|
|
1223
|
+
super();
|
|
1224
|
+
|
|
1225
|
+
const config = voltClient.config;
|
|
1226
|
+
this._grpc = grpc;
|
|
1227
|
+
this._autoRetry =
|
|
1228
|
+
config.autoReconnect === undefined ? true : !!config.autoReconnect;
|
|
1229
|
+
this._dying = false;
|
|
1230
|
+
this._voltClient = voltClient;
|
|
1231
|
+
this._pingTimer = 0;
|
|
1232
|
+
this._pingTimeoutTimer = 0;
|
|
1233
|
+
this._connectionId = "";
|
|
1234
|
+
this._pingInterval = config.pingInterval || 10000;
|
|
1235
|
+
this._reconnectInterval = config.reconnectInterval || 5000;
|
|
1236
|
+
this._timeoutInterval = config.timeoutInterval || 60000;
|
|
1237
|
+
this._helloPayload = undefined;
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
connect(helloPayload, throwOnFail) {
|
|
1241
|
+
this._helloPayload = helloPayload;
|
|
1242
|
+
if (throwOnFail) {
|
|
1243
|
+
return _doConnect.call(this, this._helloPayload);
|
|
1244
|
+
} else {
|
|
1245
|
+
return Promise.resolve(_cleanUp.call(this, true));
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
disconnect() {
|
|
1250
|
+
this._dying = true;
|
|
1251
|
+
_cleanUp.call(this);
|
|
1252
|
+
}
|
|
1236
1253
|
}
|
|
1237
1254
|
|
|
1238
1255
|
/* eslint-disable no-underscore-dangle */
|
|
@@ -1413,7 +1430,7 @@ async function bindInternal() {
|
|
|
1413
1430
|
}
|
|
1414
1431
|
}
|
|
1415
1432
|
|
|
1416
|
-
function connectInternal() {
|
|
1433
|
+
function connectInternal(helloPayload) {
|
|
1417
1434
|
try {
|
|
1418
1435
|
if (this._voltConnection) {
|
|
1419
1436
|
log$1("connectInternal - Volt connection already exists");
|
|
@@ -1443,7 +1460,7 @@ function connectInternal() {
|
|
|
1443
1460
|
if (!this._connected) {
|
|
1444
1461
|
onDisconnected();
|
|
1445
1462
|
}
|
|
1446
|
-
this.emit("connected",
|
|
1463
|
+
this.emit("connected", session);
|
|
1447
1464
|
});
|
|
1448
1465
|
|
|
1449
1466
|
this._voltConnection.on("error", (err) => {
|
|
@@ -1459,7 +1476,7 @@ function connectInternal() {
|
|
|
1459
1476
|
this.emit("evt", evt);
|
|
1460
1477
|
});
|
|
1461
1478
|
|
|
1462
|
-
return this._voltConnection.connect();
|
|
1479
|
+
return this._voltConnection.connect(helloPayload);
|
|
1463
1480
|
} catch (err) {
|
|
1464
1481
|
log$1("connect - error [%s]", err.message);
|
|
1465
1482
|
throw err;
|
|
@@ -1758,10 +1775,10 @@ class VoltClient extends EventEmitter__default["default"] {
|
|
|
1758
1775
|
}
|
|
1759
1776
|
}
|
|
1760
1777
|
|
|
1761
|
-
initialiseAndConnect(configPath, extras = {}) {
|
|
1778
|
+
initialiseAndConnect(configPath, helloPayload = undefined, extras = {}) {
|
|
1762
1779
|
return this.initialise(configPath, extras)
|
|
1763
1780
|
.then(() => {
|
|
1764
|
-
return connectInternal.call(this);
|
|
1781
|
+
return connectInternal.call(this, helloPayload);
|
|
1765
1782
|
})
|
|
1766
1783
|
.catch((err) => {
|
|
1767
1784
|
log("initialiseAndConnect failure: %s", err.message);
|
|
@@ -1834,8 +1851,8 @@ class VoltClient extends EventEmitter__default["default"] {
|
|
|
1834
1851
|
return this.isRemote && !this._voltConfig?.relay.cloud;
|
|
1835
1852
|
}
|
|
1836
1853
|
|
|
1837
|
-
connect() {
|
|
1838
|
-
return connectInternal.call(this);
|
|
1854
|
+
connect(helloPayload) {
|
|
1855
|
+
return connectInternal.call(this, helloPayload);
|
|
1839
1856
|
}
|
|
1840
1857
|
|
|
1841
1858
|
disconnect() {
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.14.
|
|
6
|
+
"version": "0.14.61",
|
|
7
7
|
"description": "tdx Volt library for nodejs clients",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"exports": {
|
|
@@ -48,4 +48,4 @@
|
|
|
48
48
|
"node-forge": "^0.9.0",
|
|
49
49
|
"uuid": "^8.1.0"
|
|
50
50
|
}
|
|
51
|
-
}
|
|
51
|
+
}
|
|
@@ -187,7 +187,7 @@ export async function bindInternal() {
|
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
-
export function connectInternal() {
|
|
190
|
+
export function connectInternal(helloPayload) {
|
|
191
191
|
try {
|
|
192
192
|
if (this._voltConnection) {
|
|
193
193
|
log("connectInternal - Volt connection already exists");
|
|
@@ -217,7 +217,7 @@ export function connectInternal() {
|
|
|
217
217
|
if (!this._connected) {
|
|
218
218
|
onDisconnected();
|
|
219
219
|
}
|
|
220
|
-
this.emit("connected",
|
|
220
|
+
this.emit("connected", session);
|
|
221
221
|
});
|
|
222
222
|
|
|
223
223
|
this._voltConnection.on("error", (err) => {
|
|
@@ -233,7 +233,7 @@ export function connectInternal() {
|
|
|
233
233
|
this.emit("evt", evt);
|
|
234
234
|
});
|
|
235
235
|
|
|
236
|
-
return this._voltConnection.connect();
|
|
236
|
+
return this._voltConnection.connect(helloPayload);
|
|
237
237
|
} catch (err) {
|
|
238
238
|
log("connect - error [%s]", err.message);
|
|
239
239
|
throw err;
|
package/src/volt-client.js
CHANGED
|
@@ -189,10 +189,10 @@ export class VoltClient extends EventEmitter {
|
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
-
initialiseAndConnect(configPath, extras = {}) {
|
|
192
|
+
initialiseAndConnect(configPath, helloPayload = undefined, extras = {}) {
|
|
193
193
|
return this.initialise(configPath, extras)
|
|
194
194
|
.then(() => {
|
|
195
|
-
return connectInternal.call(this);
|
|
195
|
+
return connectInternal.call(this, helloPayload);
|
|
196
196
|
})
|
|
197
197
|
.catch((err) => {
|
|
198
198
|
log("initialiseAndConnect failure: %s", err.message);
|
|
@@ -265,8 +265,8 @@ export class VoltClient extends EventEmitter {
|
|
|
265
265
|
return this.isRemote && !this._voltConfig?.relay.cloud;
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
-
connect() {
|
|
269
|
-
return connectInternal.call(this);
|
|
268
|
+
connect(helloPayload) {
|
|
269
|
+
return connectInternal.call(this, helloPayload);
|
|
270
270
|
}
|
|
271
271
|
|
|
272
272
|
disconnect() {
|
package/src/volt-connection.js
CHANGED
|
@@ -7,50 +7,55 @@ import GRPCCall from "./grpc-call.js";
|
|
|
7
7
|
const log = debug("volt-client-grpc:volt-connection");
|
|
8
8
|
|
|
9
9
|
function _cleanUp(immediateReconnect) {
|
|
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
|
-
|
|
10
|
+
this._connectionId = "";
|
|
11
|
+
|
|
12
|
+
if (this._pingTimer) {
|
|
13
|
+
clearTimeout(this._pingTimer);
|
|
14
|
+
this._pingTimer = 0;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (this._pingTimeoutTimer) {
|
|
18
|
+
clearTimeout(this._pingTimeoutTimer);
|
|
19
|
+
this._pingTimeoutTimer = 0;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (
|
|
23
|
+
!this._dying &&
|
|
24
|
+
(immediateReconnect || (this._autoRetry && !this._reconnectTimer))
|
|
25
|
+
) {
|
|
26
|
+
this._reconnectTimer = setTimeout(
|
|
27
|
+
() => {
|
|
28
|
+
this._reconnectTimer = 0;
|
|
29
|
+
_doConnect.call(this, this._helloPayload);
|
|
30
|
+
},
|
|
31
|
+
immediateReconnect ? 0 : this._reconnectInterval,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (this.call?.writable) {
|
|
36
|
+
this.call.end();
|
|
37
|
+
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
function _connectionTimeoutHandler() {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
log("server timed out");
|
|
42
|
+
this.emit("connected", false);
|
|
43
|
+
_cleanUp.call(this);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
function _doConnect() {
|
|
47
|
-
|
|
46
|
+
function _doConnect(connectHello) {
|
|
47
|
+
this.call = new GRPCCall(this._voltClient, "Connect", "METHOD_TYPE_BIDI");
|
|
48
|
+
|
|
49
|
+
const grpcClient = this._voltClient.getVoltAPIClient();
|
|
50
|
+
|
|
51
|
+
let helloPayload = connectHello;
|
|
52
|
+
if (!connectHello) {
|
|
53
|
+
log("defaulting hello payload");
|
|
54
|
+
helloPayload = {
|
|
55
|
+
hello: {},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
48
58
|
|
|
49
|
-
const grpcClient = this._voltClient.getVoltAPIClient();
|
|
50
|
-
const helloPayload = {
|
|
51
|
-
hello: {},
|
|
52
|
-
};
|
|
53
|
-
|
|
54
59
|
this.call.on("error", (err) => {
|
|
55
60
|
log("error on connection stream [%s]", err.message);
|
|
56
61
|
_cleanUp.call(this);
|
|
@@ -71,10 +76,11 @@ function _doConnect() {
|
|
|
71
76
|
_startPingTimer.call(this);
|
|
72
77
|
break;
|
|
73
78
|
}
|
|
74
|
-
case "
|
|
75
|
-
if (!this.
|
|
76
|
-
this.
|
|
77
|
-
|
|
79
|
+
case "acknowledge": {
|
|
80
|
+
if (!this._connectionId) {
|
|
81
|
+
this._connectionId = response.acknowledge.connection_id;
|
|
82
|
+
log("connection id is %s", this._connectionId);
|
|
83
|
+
this.emit("connected", this._connectionId);
|
|
78
84
|
}
|
|
79
85
|
break;
|
|
80
86
|
}
|
|
@@ -90,72 +96,74 @@ function _doConnect() {
|
|
|
90
96
|
});
|
|
91
97
|
|
|
92
98
|
this.call.on("end", () => {
|
|
93
|
-
if (this.
|
|
99
|
+
if (this._connectionId) {
|
|
94
100
|
this.emit("connected", false);
|
|
95
101
|
}
|
|
96
102
|
_cleanUp.call(this);
|
|
97
103
|
});
|
|
98
104
|
|
|
99
|
-
|
|
105
|
+
this.call.start(grpcClient, helloPayload);
|
|
100
106
|
|
|
101
|
-
|
|
107
|
+
_startPingTimer.call(this);
|
|
102
108
|
}
|
|
103
109
|
|
|
104
110
|
function _startPingTimer() {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
111
|
+
if (this._pingTimer) {
|
|
112
|
+
log("ping timer running");
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
this._pingTimer = setTimeout(() => {
|
|
117
|
+
// Send next ping to server.
|
|
118
|
+
const request = { ping: { timestamp: Date.now() } };
|
|
119
|
+
|
|
120
|
+
log("pinging Volt");
|
|
121
|
+
this.call.write(request);
|
|
122
|
+
|
|
123
|
+
this._pingTimer = 0;
|
|
124
|
+
|
|
125
|
+
// Schedule a timeout if we don't hear back from the server.
|
|
126
|
+
if (this._pingTimeoutTimer) {
|
|
127
|
+
clearTimeout(this._pingTimeoutTimer);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
this._pingTimeoutTimer = setTimeout(
|
|
131
|
+
_connectionTimeoutHandler.bind(this),
|
|
132
|
+
this._timeoutInterval,
|
|
133
|
+
);
|
|
134
|
+
}, this._pingInterval);
|
|
129
135
|
}
|
|
130
136
|
|
|
131
137
|
export default class VoltConnection extends EventEmitter {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
138
|
+
constructor(voltClient, grpc) {
|
|
139
|
+
super();
|
|
140
|
+
|
|
141
|
+
const config = voltClient.config;
|
|
142
|
+
this._grpc = grpc;
|
|
143
|
+
this._autoRetry =
|
|
144
|
+
config.autoReconnect === undefined ? true : !!config.autoReconnect;
|
|
145
|
+
this._dying = false;
|
|
146
|
+
this._voltClient = voltClient;
|
|
147
|
+
this._pingTimer = 0;
|
|
148
|
+
this._pingTimeoutTimer = 0;
|
|
149
|
+
this._connectionId = "";
|
|
150
|
+
this._pingInterval = config.pingInterval || 10000;
|
|
151
|
+
this._reconnectInterval = config.reconnectInterval || 5000;
|
|
152
|
+
this._timeoutInterval = config.timeoutInterval || 60000;
|
|
153
|
+
this._helloPayload = undefined;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
connect(helloPayload, throwOnFail) {
|
|
157
|
+
this._helloPayload = helloPayload;
|
|
158
|
+
if (throwOnFail) {
|
|
159
|
+
return _doConnect.call(this, this._helloPayload);
|
|
160
|
+
} else {
|
|
161
|
+
return Promise.resolve(_cleanUp.call(this, true));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
disconnect() {
|
|
166
|
+
this._dying = true;
|
|
167
|
+
_cleanUp.call(this);
|
|
168
|
+
}
|
|
161
169
|
}
|
package/src/volt-credential.js
CHANGED
|
@@ -69,6 +69,14 @@ export class VoltCredential {
|
|
|
69
69
|
return this._cryptoCache;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
get clientId() {
|
|
73
|
+
return this._cryptoCache.client_id;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
get publicKey() {
|
|
77
|
+
return pki.publicKeyToPem(this.getKey().publicKey);
|
|
78
|
+
}
|
|
79
|
+
|
|
72
80
|
get voltFingerprint() {
|
|
73
81
|
return this._voltFingerprint;
|
|
74
82
|
}
|
|
@@ -149,6 +157,7 @@ export class VoltCredential {
|
|
|
149
157
|
aud: audience,
|
|
150
158
|
iat: Math.floor(Date.now() / 1000) - ttl,
|
|
151
159
|
exp: Math.floor(Date.now() / 1000) + ttl,
|
|
160
|
+
sub: this._cryptoCache.client_id,
|
|
152
161
|
};
|
|
153
162
|
|
|
154
163
|
let sharedKey;
|