@tdxvolt/volt-client-grpc 0.18.4 → 0.18.6
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 +222 -221
- package/package.json +1 -2
- package/src/proto-package-definition.js +3 -2
- package/src/proto-utils.js +0 -1
- package/src/volt-client-internal.js +13 -11
package/lib/index.cjs
CHANGED
|
@@ -12,10 +12,9 @@ var path = require('path');
|
|
|
12
12
|
var Protobuf = require('protobufjs');
|
|
13
13
|
var camelCase = require('lodash.camelcase');
|
|
14
14
|
var descriptor = require('protobufjs/ext/descriptor/index.js');
|
|
15
|
-
var IdempotencyLevel = require('@grpc/proto-loader');
|
|
16
15
|
var bent = require('bent');
|
|
17
|
-
var jwt = require('jsonwebtoken');
|
|
18
16
|
var uuid = require('uuid');
|
|
17
|
+
var jwt = require('jsonwebtoken');
|
|
19
18
|
|
|
20
19
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
21
20
|
|
|
@@ -28,7 +27,6 @@ var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
|
28
27
|
var Protobuf__default = /*#__PURE__*/_interopDefaultLegacy(Protobuf);
|
|
29
28
|
var camelCase__default = /*#__PURE__*/_interopDefaultLegacy(camelCase);
|
|
30
29
|
var descriptor__default = /*#__PURE__*/_interopDefaultLegacy(descriptor);
|
|
31
|
-
var IdempotencyLevel__default = /*#__PURE__*/_interopDefaultLegacy(IdempotencyLevel);
|
|
32
30
|
var bent__default = /*#__PURE__*/_interopDefaultLegacy(bent);
|
|
33
31
|
var jwt__default = /*#__PURE__*/_interopDefaultLegacy(jwt);
|
|
34
32
|
|
|
@@ -362,7 +360,7 @@ const {
|
|
|
362
360
|
publicKeyToPem: publicKeyToPem$2
|
|
363
361
|
} = js.voltUtils;
|
|
364
362
|
|
|
365
|
-
const log$
|
|
363
|
+
const log$5 = debug__default["default"]("volt-client-grpc:volt-credential");
|
|
366
364
|
|
|
367
365
|
class VoltCredential {
|
|
368
366
|
constructor(config, configPath) {
|
|
@@ -456,13 +454,13 @@ class VoltCredential {
|
|
|
456
454
|
createKey() {
|
|
457
455
|
if (this._cryptoCache.key) {
|
|
458
456
|
// Already have key data in the cache in pem format => create fully-formed pki instances.
|
|
459
|
-
log$
|
|
457
|
+
log$5("createKey - key already exists");
|
|
460
458
|
return Promise.resolve(this.getKey());
|
|
461
459
|
} else {
|
|
462
|
-
log$
|
|
460
|
+
log$5("creating key");
|
|
463
461
|
this._cryptoCache.key = JSON.parse(createSigningKey()).private_pem;
|
|
464
462
|
const key = keyFromPem$2(this._cryptoCache.key);
|
|
465
|
-
log$
|
|
463
|
+
log$5("successfully created key");
|
|
466
464
|
return Promise.resolve(key);
|
|
467
465
|
}
|
|
468
466
|
}
|
|
@@ -479,7 +477,7 @@ class VoltCredential {
|
|
|
479
477
|
return this._cryptoCache;
|
|
480
478
|
})
|
|
481
479
|
.catch((err) => {
|
|
482
|
-
log$
|
|
480
|
+
log$5("failure initialising crypto [%s]", err.message);
|
|
483
481
|
return Promise.reject(err);
|
|
484
482
|
});
|
|
485
483
|
}
|
|
@@ -544,6 +542,8 @@ class VoltCredential {
|
|
|
544
542
|
*
|
|
545
543
|
*/
|
|
546
544
|
|
|
545
|
+
const IDEMPOTENCY_UNKNOWN = "IDEMPOTENCY_UNKNOWN";
|
|
546
|
+
|
|
547
547
|
const descriptorOptions = {
|
|
548
548
|
longs: String,
|
|
549
549
|
enums: String,
|
|
@@ -619,7 +619,7 @@ function mapMethodOptions(options) {
|
|
|
619
619
|
},
|
|
620
620
|
{
|
|
621
621
|
deprecated: false,
|
|
622
|
-
idempotency_level:
|
|
622
|
+
idempotency_level: IDEMPOTENCY_UNKNOWN,
|
|
623
623
|
uninterpreted_option: []
|
|
624
624
|
}
|
|
625
625
|
);
|
|
@@ -3693,7 +3693,7 @@ message SubscribeWireResponse {
|
|
|
3693
3693
|
`;
|
|
3694
3694
|
const voltProtos = [sqlite, sqlite_database_api, sqlite_server_api, proxy_api, relay_api, sync, discovery_api, file, file_api, remote, spark_api, ssi, ssi_api, status, terminal_api, volt, volt_api, wire_api];
|
|
3695
3695
|
|
|
3696
|
-
|
|
3696
|
+
debug__default["default"]("volt-client-grpc:proto-utils");
|
|
3697
3697
|
|
|
3698
3698
|
const voltServices = [
|
|
3699
3699
|
constants.serviceType.voltAPI,
|
|
@@ -3718,7 +3718,6 @@ function getServiceDescriptors(service) {
|
|
|
3718
3718
|
let root = new Protobuf__default["default"].Root();
|
|
3719
3719
|
for (let protoFile of service.service_description.proto_file) {
|
|
3720
3720
|
Protobuf__default["default"].parse(protoFile.protobuf, root, defaultLoaderOptions);
|
|
3721
|
-
log$5("parsed proto file %s", protoFile.file_path);
|
|
3722
3721
|
}
|
|
3723
3722
|
|
|
3724
3723
|
// Create a package definition from the root object.
|
|
@@ -4251,206 +4250,6 @@ class GRPCCall extends EventEmitter__default["default"] {
|
|
|
4251
4250
|
}
|
|
4252
4251
|
}
|
|
4253
4252
|
|
|
4254
|
-
/* eslint-disable no-use-before-define */
|
|
4255
|
-
|
|
4256
|
-
const log$3 = debug__default["default"]("volt-client-grpc:volt-connection");
|
|
4257
|
-
|
|
4258
|
-
function _cleanUp(immediateReconnect) {
|
|
4259
|
-
this._connectionId = "";
|
|
4260
|
-
|
|
4261
|
-
if (this._pingTimer) {
|
|
4262
|
-
clearTimeout(this._pingTimer);
|
|
4263
|
-
this._pingTimer = 0;
|
|
4264
|
-
}
|
|
4265
|
-
|
|
4266
|
-
if (this._pingTimeoutTimer) {
|
|
4267
|
-
clearTimeout(this._pingTimeoutTimer);
|
|
4268
|
-
this._pingTimeoutTimer = 0;
|
|
4269
|
-
}
|
|
4270
|
-
|
|
4271
|
-
if (this._dying) {
|
|
4272
|
-
clearTimeout(this._reconnectTimer);
|
|
4273
|
-
} else if (immediateReconnect || (this._autoRetry && !this._reconnectTimer)) {
|
|
4274
|
-
this._reconnectTimer = setTimeout(
|
|
4275
|
-
() => {
|
|
4276
|
-
this._reconnectTimer = 0;
|
|
4277
|
-
_doConnect.call(this, this._helloPayload);
|
|
4278
|
-
},
|
|
4279
|
-
immediateReconnect ? 0 : this._reconnectInterval
|
|
4280
|
-
);
|
|
4281
|
-
}
|
|
4282
|
-
|
|
4283
|
-
if (this.call?.writable) {
|
|
4284
|
-
this.call.end();
|
|
4285
|
-
}
|
|
4286
|
-
}
|
|
4287
|
-
|
|
4288
|
-
function _connectionTimeoutHandler() {
|
|
4289
|
-
log$3("server timed out");
|
|
4290
|
-
this.emit("connected", false);
|
|
4291
|
-
_cleanUp.call(this);
|
|
4292
|
-
}
|
|
4293
|
-
|
|
4294
|
-
function _doConnect(connectHello) {
|
|
4295
|
-
this.call = new GRPCCall(this._voltClient, "Connect", "METHOD_TYPE_BIDI");
|
|
4296
|
-
|
|
4297
|
-
const grpcClient = this._voltClient.getVoltAPIClient();
|
|
4298
|
-
|
|
4299
|
-
// Notify the Volt of our ping interval. If the Volt doesn't receive a ping from us
|
|
4300
|
-
// within this time, it will assume the connection is dead.
|
|
4301
|
-
const defaultHello = {
|
|
4302
|
-
ping_interval: this._pingInterval,
|
|
4303
|
-
timestamp: Date.now()
|
|
4304
|
-
};
|
|
4305
|
-
|
|
4306
|
-
const helloPayload = { ...connectHello } || {};
|
|
4307
|
-
|
|
4308
|
-
helloPayload.hello = { ...defaultHello, ...connectHello?.hello };
|
|
4309
|
-
|
|
4310
|
-
log$3("hello is %j", helloPayload);
|
|
4311
|
-
|
|
4312
|
-
this.call.on("error", (err) => {
|
|
4313
|
-
log$3("error on connection stream [%s]", err.message);
|
|
4314
|
-
_cleanUp.call(this);
|
|
4315
|
-
this.emit("error", err);
|
|
4316
|
-
});
|
|
4317
|
-
|
|
4318
|
-
this.call.on("data", (response) => {
|
|
4319
|
-
switch (response.payload) {
|
|
4320
|
-
case "ping": {
|
|
4321
|
-
log$3("pinged");
|
|
4322
|
-
|
|
4323
|
-
// Received ping response from server => clear timeout.
|
|
4324
|
-
if (this._pingTimeoutTimer) {
|
|
4325
|
-
clearTimeout(this._pingTimeoutTimer);
|
|
4326
|
-
}
|
|
4327
|
-
|
|
4328
|
-
this.emit("ping", response.ping.timestamp);
|
|
4329
|
-
break;
|
|
4330
|
-
}
|
|
4331
|
-
case "acknowledge": {
|
|
4332
|
-
if (!this._connectionId) {
|
|
4333
|
-
this._connectionId = response.acknowledge.connection_id;
|
|
4334
|
-
|
|
4335
|
-
// Set the ping timeout interval to the value returned by the Volt. If we don't
|
|
4336
|
-
// hear from the Volt in this time, we'll assume the connection is dead.
|
|
4337
|
-
this._timeoutInterval = response.acknowledge.ping_interval;
|
|
4338
|
-
|
|
4339
|
-
log$3("connection id is %s", this._connectionId);
|
|
4340
|
-
this.emit("connected", this._connectionId);
|
|
4341
|
-
|
|
4342
|
-
// Schedule the next ping.
|
|
4343
|
-
_startPingTimer.call(this);
|
|
4344
|
-
}
|
|
4345
|
-
break;
|
|
4346
|
-
}
|
|
4347
|
-
case "invoke_request": {
|
|
4348
|
-
log$3("received invoke request %s", response.invoke_request.invoke_id);
|
|
4349
|
-
// Pause the call while we process the invoke request to avoid getting
|
|
4350
|
-
// CANCELLED errors from grpc - we should perhaps leave this to the
|
|
4351
|
-
// client to manage as it may be overkill in some cases.
|
|
4352
|
-
this.call.pause();
|
|
4353
|
-
try {
|
|
4354
|
-
this.emit("invoke_request", response.invoke_request);
|
|
4355
|
-
} catch (err) {
|
|
4356
|
-
log$3("error processing invoke request [%s]", err.message);
|
|
4357
|
-
} finally {
|
|
4358
|
-
this.call.resume();
|
|
4359
|
-
}
|
|
4360
|
-
break;
|
|
4361
|
-
}
|
|
4362
|
-
case "evt": {
|
|
4363
|
-
log$3("received event %s", Object.keys(response.evt)[0]);
|
|
4364
|
-
this.emit("evt", response.evt);
|
|
4365
|
-
break;
|
|
4366
|
-
}
|
|
4367
|
-
default:
|
|
4368
|
-
log$3("unimplemented connect response payload: %s", response.payload);
|
|
4369
|
-
break;
|
|
4370
|
-
}
|
|
4371
|
-
});
|
|
4372
|
-
|
|
4373
|
-
this.call.on("end", () => {
|
|
4374
|
-
if (this._connectionId) {
|
|
4375
|
-
this.emit("connected", false);
|
|
4376
|
-
}
|
|
4377
|
-
_cleanUp.call(this);
|
|
4378
|
-
});
|
|
4379
|
-
|
|
4380
|
-
this.call.start(grpcClient, helloPayload);
|
|
4381
|
-
}
|
|
4382
|
-
|
|
4383
|
-
function _startPingTimer() {
|
|
4384
|
-
if (this._pingTimer) {
|
|
4385
|
-
log$3("ping timer running");
|
|
4386
|
-
return;
|
|
4387
|
-
}
|
|
4388
|
-
|
|
4389
|
-
this._pingTimer = setTimeout(() => {
|
|
4390
|
-
// Send next ping to server.
|
|
4391
|
-
const request = { ping: { timestamp: Date.now() } };
|
|
4392
|
-
|
|
4393
|
-
log$3("pinging Volt");
|
|
4394
|
-
this.call.write(request);
|
|
4395
|
-
|
|
4396
|
-
this._pingTimer = 0;
|
|
4397
|
-
|
|
4398
|
-
// Schedule a timeout if we don't hear back from the server.
|
|
4399
|
-
if (this._pingTimeoutTimer) {
|
|
4400
|
-
clearTimeout(this._pingTimeoutTimer);
|
|
4401
|
-
}
|
|
4402
|
-
|
|
4403
|
-
this._pingTimeoutTimer = setTimeout(
|
|
4404
|
-
_connectionTimeoutHandler.bind(this),
|
|
4405
|
-
this._timeoutInterval
|
|
4406
|
-
);
|
|
4407
|
-
|
|
4408
|
-
_startPingTimer.call(this);
|
|
4409
|
-
}, this._pingInterval);
|
|
4410
|
-
}
|
|
4411
|
-
|
|
4412
|
-
class VoltConnection extends EventEmitter__default["default"] {
|
|
4413
|
-
constructor(voltClient, grpc) {
|
|
4414
|
-
super();
|
|
4415
|
-
|
|
4416
|
-
const config = voltClient.config;
|
|
4417
|
-
this._grpc = grpc;
|
|
4418
|
-
this._autoRetry =
|
|
4419
|
-
config.autoReconnect === undefined ? true : !!config.autoReconnect;
|
|
4420
|
-
this._dying = false;
|
|
4421
|
-
this._voltClient = voltClient;
|
|
4422
|
-
this._pingTimer = 0;
|
|
4423
|
-
this._pingTimeoutTimer = 0;
|
|
4424
|
-
this._connectionId = "";
|
|
4425
|
-
this._pingInterval = config.pingInterval || 10000;
|
|
4426
|
-
this._reconnectInterval = config.reconnectInterval || 5000;
|
|
4427
|
-
this._timeoutInterval = config.timeoutInterval || 60000;
|
|
4428
|
-
this._helloPayload = undefined;
|
|
4429
|
-
}
|
|
4430
|
-
|
|
4431
|
-
get connectionId() {
|
|
4432
|
-
return this._connectionId;
|
|
4433
|
-
}
|
|
4434
|
-
|
|
4435
|
-
connect(helloPayload, throwOnFail) {
|
|
4436
|
-
this._helloPayload = helloPayload;
|
|
4437
|
-
if (throwOnFail) {
|
|
4438
|
-
return _doConnect.call(this, this._helloPayload);
|
|
4439
|
-
} else {
|
|
4440
|
-
return Promise.resolve(_cleanUp.call(this, true));
|
|
4441
|
-
}
|
|
4442
|
-
}
|
|
4443
|
-
|
|
4444
|
-
disconnect() {
|
|
4445
|
-
this._dying = true;
|
|
4446
|
-
_cleanUp.call(this);
|
|
4447
|
-
}
|
|
4448
|
-
|
|
4449
|
-
send(request) {
|
|
4450
|
-
this.call.write(request);
|
|
4451
|
-
}
|
|
4452
|
-
}
|
|
4453
|
-
|
|
4454
4253
|
const {
|
|
4455
4254
|
aesDecrypt,
|
|
4456
4255
|
aesEncrypt,
|
|
@@ -4467,7 +4266,7 @@ const {
|
|
|
4467
4266
|
x25519
|
|
4468
4267
|
} = js.voltUtils;
|
|
4469
4268
|
|
|
4470
|
-
const log$
|
|
4269
|
+
const log$3 = debug__default["default"]("volt-client-grpc:rpc-invocation");
|
|
4471
4270
|
|
|
4472
4271
|
class RpcInvocation extends EventEmitter__default["default"] {
|
|
4473
4272
|
#voltClient = null;
|
|
@@ -4521,7 +4320,7 @@ class RpcInvocation extends EventEmitter__default["default"] {
|
|
|
4521
4320
|
this.#payload
|
|
4522
4321
|
);
|
|
4523
4322
|
} else {
|
|
4524
|
-
log$
|
|
4323
|
+
log$3("unexpected: no method descriptor");
|
|
4525
4324
|
throw new Error(
|
|
4526
4325
|
"no method descriptor - set this before accessing payload"
|
|
4527
4326
|
);
|
|
@@ -4548,7 +4347,7 @@ class RpcInvocation extends EventEmitter__default["default"] {
|
|
|
4548
4347
|
this.#token = jwt__default["default"].decode(token);
|
|
4549
4348
|
|
|
4550
4349
|
if (!this.#token) {
|
|
4551
|
-
log$
|
|
4350
|
+
log$3("failed to decode token %s", token || "null");
|
|
4552
4351
|
return Promise.reject(new Error("failed to decode token"));
|
|
4553
4352
|
}
|
|
4554
4353
|
|
|
@@ -4609,7 +4408,7 @@ class RpcInvocation extends EventEmitter__default["default"] {
|
|
|
4609
4408
|
if (!this.#derivedKey) {
|
|
4610
4409
|
// We don't have the derived key yet, so we need to perform the key exchange.
|
|
4611
4410
|
return this.#keyExchange(invoke_request.token).catch((err) => {
|
|
4612
|
-
log$
|
|
4411
|
+
log$3("failure initialising invocation: %s", err.message);
|
|
4613
4412
|
return Promise.reject(err);
|
|
4614
4413
|
});
|
|
4615
4414
|
} else {
|
|
@@ -4694,16 +4493,16 @@ class RpcInvocation extends EventEmitter__default["default"] {
|
|
|
4694
4493
|
);
|
|
4695
4494
|
this.emit("payload", this);
|
|
4696
4495
|
} else if (wrappedPayload.method_end) {
|
|
4697
|
-
log$
|
|
4496
|
+
log$3("method_end received");
|
|
4698
4497
|
if (!this.#endEmitted) {
|
|
4699
4498
|
this.#endEmitted = true;
|
|
4700
4499
|
this.emit("end", this);
|
|
4701
4500
|
} else {
|
|
4702
|
-
log$
|
|
4501
|
+
log$3("method_end: end already emitted");
|
|
4703
4502
|
}
|
|
4704
4503
|
}
|
|
4705
4504
|
} catch (err) {
|
|
4706
|
-
log$
|
|
4505
|
+
log$3("JSON.parse failure parsing json_payload: %s", err.message);
|
|
4707
4506
|
reject(err);
|
|
4708
4507
|
}
|
|
4709
4508
|
|
|
@@ -4713,14 +4512,14 @@ class RpcInvocation extends EventEmitter__default["default"] {
|
|
|
4713
4512
|
this.#endEmitted = true;
|
|
4714
4513
|
this.emit("end", this);
|
|
4715
4514
|
} else {
|
|
4716
|
-
log$
|
|
4515
|
+
log$3("client_end: end already emitted");
|
|
4717
4516
|
}
|
|
4718
4517
|
} else {
|
|
4719
4518
|
// Do we need to support json_payload here?
|
|
4720
4519
|
reject(new Error("No payload in invoke request"));
|
|
4721
4520
|
}
|
|
4722
4521
|
}).catch((err) => {
|
|
4723
|
-
log$
|
|
4522
|
+
log$3("failure parsing payload: %s", err.message);
|
|
4724
4523
|
return Promise.reject(err);
|
|
4725
4524
|
});
|
|
4726
4525
|
}
|
|
@@ -4808,6 +4607,206 @@ class RpcInvocation extends EventEmitter__default["default"] {
|
|
|
4808
4607
|
}
|
|
4809
4608
|
}
|
|
4810
4609
|
|
|
4610
|
+
/* eslint-disable no-use-before-define */
|
|
4611
|
+
|
|
4612
|
+
const log$2 = debug__default["default"]("volt-client-grpc:volt-connection");
|
|
4613
|
+
|
|
4614
|
+
function _cleanUp(immediateReconnect) {
|
|
4615
|
+
this._connectionId = "";
|
|
4616
|
+
|
|
4617
|
+
if (this._pingTimer) {
|
|
4618
|
+
clearTimeout(this._pingTimer);
|
|
4619
|
+
this._pingTimer = 0;
|
|
4620
|
+
}
|
|
4621
|
+
|
|
4622
|
+
if (this._pingTimeoutTimer) {
|
|
4623
|
+
clearTimeout(this._pingTimeoutTimer);
|
|
4624
|
+
this._pingTimeoutTimer = 0;
|
|
4625
|
+
}
|
|
4626
|
+
|
|
4627
|
+
if (this._dying) {
|
|
4628
|
+
clearTimeout(this._reconnectTimer);
|
|
4629
|
+
} else if (immediateReconnect || (this._autoRetry && !this._reconnectTimer)) {
|
|
4630
|
+
this._reconnectTimer = setTimeout(
|
|
4631
|
+
() => {
|
|
4632
|
+
this._reconnectTimer = 0;
|
|
4633
|
+
_doConnect.call(this, this._helloPayload);
|
|
4634
|
+
},
|
|
4635
|
+
immediateReconnect ? 0 : this._reconnectInterval
|
|
4636
|
+
);
|
|
4637
|
+
}
|
|
4638
|
+
|
|
4639
|
+
if (this.call?.writable) {
|
|
4640
|
+
this.call.end();
|
|
4641
|
+
}
|
|
4642
|
+
}
|
|
4643
|
+
|
|
4644
|
+
function _connectionTimeoutHandler() {
|
|
4645
|
+
log$2("server timed out");
|
|
4646
|
+
this.emit("connected", false);
|
|
4647
|
+
_cleanUp.call(this);
|
|
4648
|
+
}
|
|
4649
|
+
|
|
4650
|
+
function _doConnect(connectHello) {
|
|
4651
|
+
this.call = new GRPCCall(this._voltClient, "Connect", "METHOD_TYPE_BIDI");
|
|
4652
|
+
|
|
4653
|
+
const grpcClient = this._voltClient.getVoltAPIClient();
|
|
4654
|
+
|
|
4655
|
+
// Notify the Volt of our ping interval. If the Volt doesn't receive a ping from us
|
|
4656
|
+
// within this time, it will assume the connection is dead.
|
|
4657
|
+
const defaultHello = {
|
|
4658
|
+
ping_interval: this._pingInterval,
|
|
4659
|
+
timestamp: Date.now()
|
|
4660
|
+
};
|
|
4661
|
+
|
|
4662
|
+
const helloPayload = { ...connectHello } || {};
|
|
4663
|
+
|
|
4664
|
+
helloPayload.hello = { ...defaultHello, ...connectHello?.hello };
|
|
4665
|
+
|
|
4666
|
+
log$2("hello is %j", helloPayload);
|
|
4667
|
+
|
|
4668
|
+
this.call.on("error", (err) => {
|
|
4669
|
+
log$2("error on connection stream [%s]", err.message);
|
|
4670
|
+
_cleanUp.call(this);
|
|
4671
|
+
this.emit("error", err);
|
|
4672
|
+
});
|
|
4673
|
+
|
|
4674
|
+
this.call.on("data", (response) => {
|
|
4675
|
+
switch (response.payload) {
|
|
4676
|
+
case "ping": {
|
|
4677
|
+
log$2("pinged");
|
|
4678
|
+
|
|
4679
|
+
// Received ping response from server => clear timeout.
|
|
4680
|
+
if (this._pingTimeoutTimer) {
|
|
4681
|
+
clearTimeout(this._pingTimeoutTimer);
|
|
4682
|
+
}
|
|
4683
|
+
|
|
4684
|
+
this.emit("ping", response.ping.timestamp);
|
|
4685
|
+
break;
|
|
4686
|
+
}
|
|
4687
|
+
case "acknowledge": {
|
|
4688
|
+
if (!this._connectionId) {
|
|
4689
|
+
this._connectionId = response.acknowledge.connection_id;
|
|
4690
|
+
|
|
4691
|
+
// Set the ping timeout interval to the value returned by the Volt. If we don't
|
|
4692
|
+
// hear from the Volt in this time, we'll assume the connection is dead.
|
|
4693
|
+
this._timeoutInterval = response.acknowledge.ping_interval;
|
|
4694
|
+
|
|
4695
|
+
log$2("connection id is %s", this._connectionId);
|
|
4696
|
+
this.emit("connected", this._connectionId);
|
|
4697
|
+
|
|
4698
|
+
// Schedule the next ping.
|
|
4699
|
+
_startPingTimer.call(this);
|
|
4700
|
+
}
|
|
4701
|
+
break;
|
|
4702
|
+
}
|
|
4703
|
+
case "invoke_request": {
|
|
4704
|
+
log$2("received invoke request %s", response.invoke_request.invoke_id);
|
|
4705
|
+
// Pause the call while we process the invoke request to avoid getting
|
|
4706
|
+
// CANCELLED errors from grpc - we should perhaps leave this to the
|
|
4707
|
+
// client to manage as it may be overkill in some cases.
|
|
4708
|
+
this.call.pause();
|
|
4709
|
+
try {
|
|
4710
|
+
this.emit("invoke_request", response.invoke_request);
|
|
4711
|
+
} catch (err) {
|
|
4712
|
+
log$2("error processing invoke request [%s]", err.message);
|
|
4713
|
+
} finally {
|
|
4714
|
+
this.call.resume();
|
|
4715
|
+
}
|
|
4716
|
+
break;
|
|
4717
|
+
}
|
|
4718
|
+
case "evt": {
|
|
4719
|
+
log$2("received event %s", Object.keys(response.evt)[0]);
|
|
4720
|
+
this.emit("evt", response.evt);
|
|
4721
|
+
break;
|
|
4722
|
+
}
|
|
4723
|
+
default:
|
|
4724
|
+
log$2("unimplemented connect response payload: %s", response.payload);
|
|
4725
|
+
break;
|
|
4726
|
+
}
|
|
4727
|
+
});
|
|
4728
|
+
|
|
4729
|
+
this.call.on("end", () => {
|
|
4730
|
+
if (this._connectionId) {
|
|
4731
|
+
this.emit("connected", false);
|
|
4732
|
+
}
|
|
4733
|
+
_cleanUp.call(this);
|
|
4734
|
+
});
|
|
4735
|
+
|
|
4736
|
+
this.call.start(grpcClient, helloPayload);
|
|
4737
|
+
}
|
|
4738
|
+
|
|
4739
|
+
function _startPingTimer() {
|
|
4740
|
+
if (this._pingTimer) {
|
|
4741
|
+
log$2("ping timer running");
|
|
4742
|
+
return;
|
|
4743
|
+
}
|
|
4744
|
+
|
|
4745
|
+
this._pingTimer = setTimeout(() => {
|
|
4746
|
+
// Send next ping to server.
|
|
4747
|
+
const request = { ping: { timestamp: Date.now() } };
|
|
4748
|
+
|
|
4749
|
+
log$2("pinging Volt");
|
|
4750
|
+
this.call.write(request);
|
|
4751
|
+
|
|
4752
|
+
this._pingTimer = 0;
|
|
4753
|
+
|
|
4754
|
+
// Schedule a timeout if we don't hear back from the server.
|
|
4755
|
+
if (this._pingTimeoutTimer) {
|
|
4756
|
+
clearTimeout(this._pingTimeoutTimer);
|
|
4757
|
+
}
|
|
4758
|
+
|
|
4759
|
+
this._pingTimeoutTimer = setTimeout(
|
|
4760
|
+
_connectionTimeoutHandler.bind(this),
|
|
4761
|
+
this._timeoutInterval
|
|
4762
|
+
);
|
|
4763
|
+
|
|
4764
|
+
_startPingTimer.call(this);
|
|
4765
|
+
}, this._pingInterval);
|
|
4766
|
+
}
|
|
4767
|
+
|
|
4768
|
+
class VoltConnection extends EventEmitter__default["default"] {
|
|
4769
|
+
constructor(voltClient, grpc) {
|
|
4770
|
+
super();
|
|
4771
|
+
|
|
4772
|
+
const config = voltClient.config;
|
|
4773
|
+
this._grpc = grpc;
|
|
4774
|
+
this._autoRetry =
|
|
4775
|
+
config.autoReconnect === undefined ? true : !!config.autoReconnect;
|
|
4776
|
+
this._dying = false;
|
|
4777
|
+
this._voltClient = voltClient;
|
|
4778
|
+
this._pingTimer = 0;
|
|
4779
|
+
this._pingTimeoutTimer = 0;
|
|
4780
|
+
this._connectionId = "";
|
|
4781
|
+
this._pingInterval = config.pingInterval || 10000;
|
|
4782
|
+
this._reconnectInterval = config.reconnectInterval || 5000;
|
|
4783
|
+
this._timeoutInterval = config.timeoutInterval || 60000;
|
|
4784
|
+
this._helloPayload = undefined;
|
|
4785
|
+
}
|
|
4786
|
+
|
|
4787
|
+
get connectionId() {
|
|
4788
|
+
return this._connectionId;
|
|
4789
|
+
}
|
|
4790
|
+
|
|
4791
|
+
connect(helloPayload, throwOnFail) {
|
|
4792
|
+
this._helloPayload = helloPayload;
|
|
4793
|
+
if (throwOnFail) {
|
|
4794
|
+
return _doConnect.call(this, this._helloPayload);
|
|
4795
|
+
} else {
|
|
4796
|
+
return Promise.resolve(_cleanUp.call(this, true));
|
|
4797
|
+
}
|
|
4798
|
+
}
|
|
4799
|
+
|
|
4800
|
+
disconnect() {
|
|
4801
|
+
this._dying = true;
|
|
4802
|
+
_cleanUp.call(this);
|
|
4803
|
+
}
|
|
4804
|
+
|
|
4805
|
+
send(request) {
|
|
4806
|
+
this.call.write(request);
|
|
4807
|
+
}
|
|
4808
|
+
}
|
|
4809
|
+
|
|
4811
4810
|
/* eslint-disable no-underscore-dangle */
|
|
4812
4811
|
|
|
4813
4812
|
const { publicKeyToPem, removeCarriageReturn, signBase64 } = js.voltUtils;
|
|
@@ -5108,7 +5107,9 @@ function connectInternal(helloPayload) {
|
|
|
5108
5107
|
|
|
5109
5108
|
if (rpcInvocation) {
|
|
5110
5109
|
if (rpcInvocation.started) {
|
|
5111
|
-
rpcInvocation.parsePayload(invoke_request)
|
|
5110
|
+
rpcInvocation.parsePayload(invoke_request).catch((err) => {
|
|
5111
|
+
log$1("invoke_request - error [%s]", err.message);
|
|
5112
|
+
});
|
|
5112
5113
|
} else {
|
|
5113
5114
|
rpcInvocation
|
|
5114
5115
|
.initialise(invoke_request)
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.18.
|
|
6
|
+
"version": "0.18.6",
|
|
7
7
|
"description": "tdx Volt library for nodejs clients",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"exports": {
|
|
@@ -37,7 +37,6 @@
|
|
|
37
37
|
"author": "toby.ealden@gmail.com",
|
|
38
38
|
"license": "ISC",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@grpc/proto-loader": "^0.7.13",
|
|
41
40
|
"@tdxvolt/volt-client-web": "^0.18.1",
|
|
42
41
|
"bent": "^7.3.12",
|
|
43
42
|
"builtin-modules": "^3.3.0",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
import camelCase from "lodash.camelcase";
|
|
18
18
|
import Protobuf from "protobufjs";
|
|
19
19
|
import descriptor from "protobufjs/ext/descriptor/index.js";
|
|
20
|
-
|
|
20
|
+
|
|
21
|
+
const IDEMPOTENCY_UNKNOWN = "IDEMPOTENCY_UNKNOWN";
|
|
21
22
|
|
|
22
23
|
const descriptorOptions = {
|
|
23
24
|
longs: String,
|
|
@@ -94,7 +95,7 @@ function mapMethodOptions(options) {
|
|
|
94
95
|
},
|
|
95
96
|
{
|
|
96
97
|
deprecated: false,
|
|
97
|
-
idempotency_level:
|
|
98
|
+
idempotency_level: IDEMPOTENCY_UNKNOWN,
|
|
98
99
|
uninterpreted_option: []
|
|
99
100
|
}
|
|
100
101
|
);
|
package/src/proto-utils.js
CHANGED
|
@@ -29,7 +29,6 @@ function getServiceDescriptors(service) {
|
|
|
29
29
|
let root = new protobuf.Root();
|
|
30
30
|
for (let protoFile of service.service_description.proto_file) {
|
|
31
31
|
protobuf.parse(protoFile.protobuf, root, defaultLoaderOptions);
|
|
32
|
-
log("parsed proto file %s", protoFile.file_path);
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
// Create a package definition from the root object.
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
/* eslint-disable no-underscore-dangle */
|
|
2
|
+
import { voltUtils as voltClientUtils } from "@tdxvolt/volt-client-web/js";
|
|
3
|
+
import bent from "bent";
|
|
2
4
|
import debug from "debug";
|
|
3
5
|
import ip from "ip";
|
|
4
|
-
import bent from "bent";
|
|
5
6
|
import lodash from "lodash";
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
getServiceDescriptors,
|
|
9
|
-
getBuiltInServiceDescriptors
|
|
10
|
-
} from "./proto-utils.js";
|
|
11
|
-
import { createClient as createGrpcClient } from "./grpc-utils.js";
|
|
12
|
-
import * as voltUtils from "./utils.js";
|
|
7
|
+
import { v4 as generateId } from "uuid";
|
|
13
8
|
import { constants } from "./constants.js";
|
|
14
9
|
import GRPCCall from "./grpc-call.js";
|
|
10
|
+
import { createClient as createGrpcClient } from "./grpc-utils.js";
|
|
11
|
+
import {
|
|
12
|
+
getBuiltInServiceDescriptors,
|
|
13
|
+
getServiceDescriptors
|
|
14
|
+
} from "./proto-utils.js";
|
|
15
15
|
import RpcInvocation from "./rpc-invocation.js";
|
|
16
|
-
import
|
|
17
|
-
import
|
|
16
|
+
import * as voltUtils from "./utils.js";
|
|
17
|
+
import VoltConnection from "./volt-connection.js";
|
|
18
18
|
|
|
19
19
|
const { publicKeyToPem, removeCarriageReturn, signBase64 } = voltClientUtils;
|
|
20
20
|
|
|
@@ -314,7 +314,9 @@ export function connectInternal(helloPayload) {
|
|
|
314
314
|
|
|
315
315
|
if (rpcInvocation) {
|
|
316
316
|
if (rpcInvocation.started) {
|
|
317
|
-
rpcInvocation.parsePayload(invoke_request)
|
|
317
|
+
rpcInvocation.parsePayload(invoke_request).catch((err) => {
|
|
318
|
+
log("invoke_request - error [%s]", err.message);
|
|
319
|
+
});
|
|
318
320
|
} else {
|
|
319
321
|
rpcInvocation
|
|
320
322
|
.initialise(invoke_request)
|