@rootintf/protocol-2phw 1.0.28-api-0.8 → 1.0.34-api.0.8
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/dist/twoPhW.cjs.js +104 -66
- package/dist/twoPhW.es.mjs +104 -66
- package/package.json +43 -43
- package/src/EventLog-mem.mjs +6 -3
- package/src/twoPhW.mjs +10 -12
- package/tests/event-log-mem.spec.mjs +1 -1
- package/tests/twoPhW-new.spec.mjs +2 -2
- package/tests/twoPhW.test.mjs +0 -175
package/dist/twoPhW.cjs.js
CHANGED
|
@@ -81,6 +81,21 @@ function l_concat_(obj_labels, arg) {
|
|
|
81
81
|
return Object.freeze(result);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
function l_LL_(obj, x) {
|
|
85
|
+
if (! obj || typeof obj !== 'object')
|
|
86
|
+
throw new Error('obj must be an object');
|
|
87
|
+
if (! Number.isSafeInteger(x) || x < 0)
|
|
88
|
+
throw new Error('Shift value must be a safe, non-negative integer');
|
|
89
|
+
|
|
90
|
+
const obj_new= {};
|
|
91
|
+
for (const [k,v] of Object.entries(obj)) {
|
|
92
|
+
if (typeof v !== 'number' || ! Number.isFinite(v))
|
|
93
|
+
continue; // Skip non-numeric
|
|
94
|
+
obj_new[k] = v<<x;
|
|
95
|
+
}
|
|
96
|
+
return Object.freeze(obj_new);
|
|
97
|
+
}
|
|
98
|
+
|
|
84
99
|
//-------------------------------------------------------------------------------------------------
|
|
85
100
|
|
|
86
101
|
function handler_default_( /* ... */ ) {
|
|
@@ -239,16 +254,6 @@ function requireJsonMsg_cjs () {
|
|
|
239
254
|
|
|
240
255
|
// console.log('OUT', __name({variableName}) );
|
|
241
256
|
|
|
242
|
-
function l_toBigInt_(ref, obj, ignore= false) {
|
|
243
|
-
console.assert(ref !== BigInt(0), 'no labels initialized');
|
|
244
|
-
let bigInt = BigInt(0);
|
|
245
|
-
for (const [k,v] of Object.entries(obj)) {
|
|
246
|
-
if ( ( ignore || v ) && ref[k])
|
|
247
|
-
bigInt|= BigInt( ref[k] );
|
|
248
|
-
// console.log('0b'+ bigInt.toString(2) );
|
|
249
|
-
}
|
|
250
|
-
return bigInt;
|
|
251
|
-
}
|
|
252
257
|
|
|
253
258
|
//-------------------------------------------------------------------------------------------------
|
|
254
259
|
|
|
@@ -260,62 +265,93 @@ function requireJsonMsg_cjs () {
|
|
|
260
265
|
|
|
261
266
|
//-------------------------------------------------------------------------------------------------
|
|
262
267
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
BitLogr.prototype['log']= function (nr_logged, /* ... */ ) {
|
|
270
|
-
// console.log('NOP')
|
|
271
|
-
};
|
|
272
|
-
}
|
|
268
|
+
function l_toBigInt_(obj_labels, obj, ignore= false) {
|
|
269
|
+
if (! obj_labels || typeof obj_labels !== 'object')
|
|
270
|
+
throw new Error('obj_labels must be an object');
|
|
271
|
+
if (! obj || typeof obj !== 'object')
|
|
272
|
+
throw new Error('obj must be an object');
|
|
273
273
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
set labels(obj) {
|
|
280
|
-
this._Bint_labels= obj;
|
|
281
|
-
this._Bint_toggled= BigInt(0);
|
|
274
|
+
let bigInt = BigInt(0);
|
|
275
|
+
for (const [k,v] of Object.entries(obj)) {
|
|
276
|
+
if ( ( ignore || v ) && obj_labels[k] !== undefined && typeof obj_labels[k] === 'number')
|
|
277
|
+
bigInt|= BigInt( obj_labels[k] );
|
|
278
|
+
// console.log('0b'+ bigInt.toString(2) );
|
|
282
279
|
}
|
|
280
|
+
return bigInt;
|
|
281
|
+
}
|
|
283
282
|
|
|
284
|
-
|
|
285
|
-
// let name= __name(label);
|
|
286
|
-
// _labels[name]= label[name];
|
|
287
|
-
// console.log(_labels);
|
|
288
|
-
// }
|
|
283
|
+
// console.log(l_toBigInt_({},{}))
|
|
289
284
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
this._Bint_toggled= l_toBigInt_(this._Bint_labels, obj);
|
|
285
|
+
const LOGR = (function () {
|
|
286
|
+
let _instance; // Private variable to hold the single instance
|
|
293
287
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
288
|
+
function _create_instance() {
|
|
289
|
+
// Private state (replacing constructor properties)
|
|
290
|
+
let _handler_log = handler_default_;
|
|
291
|
+
let _obj_labels = undefined;
|
|
292
|
+
let _Bint_toggled = BigInt(0);
|
|
298
293
|
|
|
299
|
-
|
|
300
|
-
if (
|
|
294
|
+
function _log_fxn(nr_logged, argsFn /* args */) {
|
|
295
|
+
if ((BigInt(nr_logged) & _Bint_toggled) === BigInt(0))
|
|
301
296
|
return false;
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
297
|
+
|
|
298
|
+
const args = argsFn();
|
|
299
|
+
_handler_log.apply(this, args);
|
|
300
|
+
// _handler_log.apply(this, args);
|
|
307
301
|
return true;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return {
|
|
305
|
+
set handler(fx) {
|
|
306
|
+
_handler_log = fx;
|
|
307
|
+
},
|
|
308
|
+
get handler() {
|
|
309
|
+
return _handler_log;
|
|
310
|
+
},
|
|
311
|
+
|
|
312
|
+
get labels() { return _obj_labels; },
|
|
313
|
+
set labels(obj) {
|
|
314
|
+
_obj_labels = obj;
|
|
315
|
+
_Bint_toggled = BigInt(0);
|
|
316
|
+
},
|
|
317
|
+
|
|
318
|
+
// put= function(label, abbrv) {
|
|
319
|
+
// let name= __name(label);
|
|
320
|
+
// _labels[name]= label[name];
|
|
321
|
+
// console.log(_labels);
|
|
322
|
+
// }
|
|
323
|
+
|
|
324
|
+
get toggled() { return _Bint_toggled; },
|
|
325
|
+
set toggled(obj_toggled) {
|
|
326
|
+
_Bint_toggled= l_toBigInt_(_obj_labels, obj_toggled);
|
|
327
|
+
},
|
|
328
|
+
|
|
329
|
+
log(nr_logged, argsFn) {
|
|
330
|
+
|
|
331
|
+
return _log_fxn.call(this, nr_logged, argsFn); // Pass the thunk
|
|
332
|
+
}
|
|
308
333
|
};
|
|
309
334
|
}
|
|
310
335
|
|
|
311
|
-
//
|
|
312
|
-
|
|
336
|
+
// Public interface
|
|
337
|
+
return {
|
|
338
|
+
get_instance() {
|
|
339
|
+
if (!_instance) {
|
|
340
|
+
_instance = _create_instance(); // Lazy initialization
|
|
341
|
+
}
|
|
342
|
+
return _instance;
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
})();
|
|
313
347
|
|
|
314
|
-
let LOGR_=
|
|
348
|
+
let LOGR_= LOGR.get_instance();
|
|
349
|
+
const log_= LOGR_.log;
|
|
315
350
|
|
|
316
351
|
const l_= {
|
|
317
352
|
VALIDATION : 0b1 << 0,
|
|
318
353
|
};
|
|
354
|
+
LOGR_.labels= l_;
|
|
319
355
|
|
|
320
356
|
// TODO: use RFC3339 "timestamp"? https://ajv.js.org/json-type-definition.html
|
|
321
357
|
|
|
@@ -332,7 +368,7 @@ function requireJsonMsg_cjs () {
|
|
|
332
368
|
validate : function (json) {
|
|
333
369
|
const b_valid = schema_Msg(json);
|
|
334
370
|
if (!b_valid)
|
|
335
|
-
|
|
371
|
+
log_(l_.VALIDATION, () => ['JSON_Msg: validate: ', schema_Msg.errors]);
|
|
336
372
|
return b_valid;
|
|
337
373
|
},
|
|
338
374
|
// TODO: requires a separate ajv module require, and JTD specific schema
|
|
@@ -354,7 +390,7 @@ function requireJsonMsg_cjs () {
|
|
|
354
390
|
return false;
|
|
355
391
|
const b_valid= schema_Msg_msg(json);
|
|
356
392
|
if (!b_valid)
|
|
357
|
-
|
|
393
|
+
log_(l_.VALIDATION, () => ['JSON_Msg_msg: validate: ', schema_Msg_msg.errors]);
|
|
358
394
|
return b_valid;
|
|
359
395
|
}
|
|
360
396
|
}
|
|
@@ -382,7 +418,7 @@ function requireJsonMsg_cjs () {
|
|
|
382
418
|
return false;
|
|
383
419
|
const b_valid= schema_MsgAck_msg(json);
|
|
384
420
|
if (!b_valid)
|
|
385
|
-
|
|
421
|
+
log_(l_.VALIDATION, () => ['JSON_MsgAck: validate: ', schema_MsgAck_msg.errors]);
|
|
386
422
|
return b_valid;
|
|
387
423
|
}
|
|
388
424
|
}
|
|
@@ -391,6 +427,7 @@ function requireJsonMsg_cjs () {
|
|
|
391
427
|
jsonMsg_cjs.JSON_Msg = JSON_Msg;
|
|
392
428
|
jsonMsg_cjs.JSON_MsgAck_msg = JSON_MsgAck_msg;
|
|
393
429
|
jsonMsg_cjs.JSON_Msg_msg = JSON_Msg_msg;
|
|
430
|
+
jsonMsg_cjs.l = l_;
|
|
394
431
|
return jsonMsg_cjs;
|
|
395
432
|
}
|
|
396
433
|
|
|
@@ -442,15 +479,18 @@ class EventLog {
|
|
|
442
479
|
evt.timeout_id = setTimeout(() => {
|
|
443
480
|
if (this.map_timeouts.delete(idx)) {
|
|
444
481
|
evt.timeout_id = null;
|
|
445
|
-
timeout_callback(evt);
|
|
446
|
-
log_$1(l_$1.EVENTS, `Event DELETED[${idx}]: ${type}`, evt);
|
|
482
|
+
timeout_callback({idx, evt});
|
|
483
|
+
log_$1(l_$1.EVENTS, () => [`Event DELETED[${idx}]: ${type}`, evt]);
|
|
447
484
|
}
|
|
448
485
|
}, timeout_ms);
|
|
449
486
|
|
|
450
487
|
this.map_timeouts.set(idx, evt.timeout_id);
|
|
451
488
|
}
|
|
452
489
|
|
|
453
|
-
|
|
490
|
+
// the error "toISOString is not a function" occurs because Date(evt.dt) is not doing what you expect.
|
|
491
|
+
// When you pass a number to the Date constructor without using new, it doesn’t return a Date object—it returns a string. Specifically, it’s equivalent to new Date(evt.dt).toString().
|
|
492
|
+
// Date(evt.dt).toISOString() -> new Date(evt.dt).toISOString()
|
|
493
|
+
log_$1(l_$1.EVENTS, () => [`Event added[${idx}] @${new Date(evt.dt).toISOString()}: ${type}`, evt]);
|
|
454
494
|
return { idx, evt };
|
|
455
495
|
}
|
|
456
496
|
|
|
@@ -532,19 +572,15 @@ const k_TTL= 20000;
|
|
|
532
572
|
|
|
533
573
|
//-------------------------------------------------------------------------------------------------
|
|
534
574
|
|
|
535
|
-
// LOGR
|
|
536
|
-
// - l_LL and l_RR should accept 0b1 << 0 style shift
|
|
537
|
-
// - function to debug output bit values of labels instead of binary
|
|
538
|
-
// - rollup example in READMNE
|
|
539
575
|
|
|
540
576
|
const LOGR_= LOGR.get_instance();
|
|
541
577
|
const log_= LOGR_.log;
|
|
542
578
|
|
|
543
|
-
|
|
579
|
+
Object.assign(jsonMsg_cjsExports.l, l_LL_(jsonMsg_cjsExports.l, 2)); // VALIDATION : 4
|
|
544
580
|
|
|
545
|
-
|
|
581
|
+
const l_twoPhW_ = l_array_(['HANDLERS','DROPS', 'PROTOCOL_STATE','RECVER','SENDER']);
|
|
582
|
+
const l_ = l_concat_(l_$1, l_concat_(jsonMsg_cjsExports.l, l_twoPhW_) );
|
|
546
583
|
|
|
547
|
-
const l_= l_concat_( l_msgs_, l_concat_(l_$1, l_array_(['HANDLERS','DROPS','VALIDATION'])) );
|
|
548
584
|
LOGR_.labels= l_;
|
|
549
585
|
|
|
550
586
|
//-------------------------------------------------------------------------------------------------
|
|
@@ -929,7 +965,7 @@ class TwoPhW_EventLog {
|
|
|
929
965
|
json_msgWarp: json["_msg"]
|
|
930
966
|
};
|
|
931
967
|
}
|
|
932
|
-
return null; // Explicit default for invalid cases
|
|
968
|
+
return { str_type: null, json_msgWarp: null }; // Explicit default for invalid cases
|
|
933
969
|
}
|
|
934
970
|
|
|
935
971
|
_addEvent(json_msg, timeout_ms, timeout_callback) {
|
|
@@ -940,6 +976,8 @@ class TwoPhW_EventLog {
|
|
|
940
976
|
|
|
941
977
|
_dropEvent(json_msg) {
|
|
942
978
|
const { json_msgWarp }= this._warp(json_msg);
|
|
979
|
+
if (! json_msgWarp)
|
|
980
|
+
return;
|
|
943
981
|
this._eventLog.addEvent('2PhW[DROPPED!]', json_msgWarp.warp.id, json_msg);
|
|
944
982
|
}
|
|
945
983
|
|
|
@@ -1060,7 +1098,7 @@ class TwoPhW {
|
|
|
1060
1098
|
const timeout_ms= t_ttl_rtt_(json_msgWarp.warp.ttl_msec);
|
|
1061
1099
|
const elapsed_ms= Date.now() - Date.parse(json_msgWarp.dt);
|
|
1062
1100
|
|
|
1063
|
-
this.eventLog._addEvent(json_msgWarp, timeout_ms-elapsed_ms, () => {
|
|
1101
|
+
this.eventLog._addEvent(json_msgWarp, timeout_ms-elapsed_ms, ({ _idx, _evt}) => {
|
|
1064
1102
|
this.config._callback_msg_sent_expired(json_msgWarp);
|
|
1065
1103
|
});
|
|
1066
1104
|
}
|
|
@@ -1180,7 +1218,7 @@ class TwoPhW {
|
|
|
1180
1218
|
const elapsed_ms= Date.now() - Date.parse(json_msgAckWarp.dt);
|
|
1181
1219
|
const timeout_ms= t_ttl_rtt_(json_msgWarp.warp.ttl_msec) + Date.parse(json_msgAckWarp.dt) - Date.parse(json_msgWarp.dt);
|
|
1182
1220
|
|
|
1183
|
-
this.eventLog._addEvent(json_msgAckWarp, timeout_ms-elapsed_ms, () => {
|
|
1221
|
+
this.eventLog._addEvent(json_msgAckWarp, timeout_ms-elapsed_ms, ({ _idx, _evt}) => {
|
|
1184
1222
|
this.config._callback_msg_sent_expired(json_msgAckWarp);
|
|
1185
1223
|
});
|
|
1186
1224
|
}
|
package/dist/twoPhW.es.mjs
CHANGED
|
@@ -79,6 +79,21 @@ function l_concat_(obj_labels, arg) {
|
|
|
79
79
|
return Object.freeze(result);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
function l_LL_(obj, x) {
|
|
83
|
+
if (! obj || typeof obj !== 'object')
|
|
84
|
+
throw new Error('obj must be an object');
|
|
85
|
+
if (! Number.isSafeInteger(x) || x < 0)
|
|
86
|
+
throw new Error('Shift value must be a safe, non-negative integer');
|
|
87
|
+
|
|
88
|
+
const obj_new= {};
|
|
89
|
+
for (const [k,v] of Object.entries(obj)) {
|
|
90
|
+
if (typeof v !== 'number' || ! Number.isFinite(v))
|
|
91
|
+
continue; // Skip non-numeric
|
|
92
|
+
obj_new[k] = v<<x;
|
|
93
|
+
}
|
|
94
|
+
return Object.freeze(obj_new);
|
|
95
|
+
}
|
|
96
|
+
|
|
82
97
|
//-------------------------------------------------------------------------------------------------
|
|
83
98
|
|
|
84
99
|
function handler_default_( /* ... */ ) {
|
|
@@ -237,16 +252,6 @@ function requireJsonMsg_cjs () {
|
|
|
237
252
|
|
|
238
253
|
// console.log('OUT', __name({variableName}) );
|
|
239
254
|
|
|
240
|
-
function l_toBigInt_(ref, obj, ignore= false) {
|
|
241
|
-
console.assert(ref !== BigInt(0), 'no labels initialized');
|
|
242
|
-
let bigInt = BigInt(0);
|
|
243
|
-
for (const [k,v] of Object.entries(obj)) {
|
|
244
|
-
if ( ( ignore || v ) && ref[k])
|
|
245
|
-
bigInt|= BigInt( ref[k] );
|
|
246
|
-
// console.log('0b'+ bigInt.toString(2) );
|
|
247
|
-
}
|
|
248
|
-
return bigInt;
|
|
249
|
-
}
|
|
250
255
|
|
|
251
256
|
//-------------------------------------------------------------------------------------------------
|
|
252
257
|
|
|
@@ -258,62 +263,93 @@ function requireJsonMsg_cjs () {
|
|
|
258
263
|
|
|
259
264
|
//-------------------------------------------------------------------------------------------------
|
|
260
265
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
BitLogr.prototype['log']= function (nr_logged, /* ... */ ) {
|
|
268
|
-
// console.log('NOP')
|
|
269
|
-
};
|
|
270
|
-
}
|
|
266
|
+
function l_toBigInt_(obj_labels, obj, ignore= false) {
|
|
267
|
+
if (! obj_labels || typeof obj_labels !== 'object')
|
|
268
|
+
throw new Error('obj_labels must be an object');
|
|
269
|
+
if (! obj || typeof obj !== 'object')
|
|
270
|
+
throw new Error('obj must be an object');
|
|
271
271
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
set labels(obj) {
|
|
278
|
-
this._Bint_labels= obj;
|
|
279
|
-
this._Bint_toggled= BigInt(0);
|
|
272
|
+
let bigInt = BigInt(0);
|
|
273
|
+
for (const [k,v] of Object.entries(obj)) {
|
|
274
|
+
if ( ( ignore || v ) && obj_labels[k] !== undefined && typeof obj_labels[k] === 'number')
|
|
275
|
+
bigInt|= BigInt( obj_labels[k] );
|
|
276
|
+
// console.log('0b'+ bigInt.toString(2) );
|
|
280
277
|
}
|
|
278
|
+
return bigInt;
|
|
279
|
+
}
|
|
281
280
|
|
|
282
|
-
|
|
283
|
-
// let name= __name(label);
|
|
284
|
-
// _labels[name]= label[name];
|
|
285
|
-
// console.log(_labels);
|
|
286
|
-
// }
|
|
281
|
+
// console.log(l_toBigInt_({},{}))
|
|
287
282
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
this._Bint_toggled= l_toBigInt_(this._Bint_labels, obj);
|
|
283
|
+
const LOGR = (function () {
|
|
284
|
+
let _instance; // Private variable to hold the single instance
|
|
291
285
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
286
|
+
function _create_instance() {
|
|
287
|
+
// Private state (replacing constructor properties)
|
|
288
|
+
let _handler_log = handler_default_;
|
|
289
|
+
let _obj_labels = undefined;
|
|
290
|
+
let _Bint_toggled = BigInt(0);
|
|
296
291
|
|
|
297
|
-
|
|
298
|
-
if (
|
|
292
|
+
function _log_fxn(nr_logged, argsFn /* args */) {
|
|
293
|
+
if ((BigInt(nr_logged) & _Bint_toggled) === BigInt(0))
|
|
299
294
|
return false;
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
295
|
+
|
|
296
|
+
const args = argsFn();
|
|
297
|
+
_handler_log.apply(this, args);
|
|
298
|
+
// _handler_log.apply(this, args);
|
|
305
299
|
return true;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return {
|
|
303
|
+
set handler(fx) {
|
|
304
|
+
_handler_log = fx;
|
|
305
|
+
},
|
|
306
|
+
get handler() {
|
|
307
|
+
return _handler_log;
|
|
308
|
+
},
|
|
309
|
+
|
|
310
|
+
get labels() { return _obj_labels; },
|
|
311
|
+
set labels(obj) {
|
|
312
|
+
_obj_labels = obj;
|
|
313
|
+
_Bint_toggled = BigInt(0);
|
|
314
|
+
},
|
|
315
|
+
|
|
316
|
+
// put= function(label, abbrv) {
|
|
317
|
+
// let name= __name(label);
|
|
318
|
+
// _labels[name]= label[name];
|
|
319
|
+
// console.log(_labels);
|
|
320
|
+
// }
|
|
321
|
+
|
|
322
|
+
get toggled() { return _Bint_toggled; },
|
|
323
|
+
set toggled(obj_toggled) {
|
|
324
|
+
_Bint_toggled= l_toBigInt_(_obj_labels, obj_toggled);
|
|
325
|
+
},
|
|
326
|
+
|
|
327
|
+
log(nr_logged, argsFn) {
|
|
328
|
+
|
|
329
|
+
return _log_fxn.call(this, nr_logged, argsFn); // Pass the thunk
|
|
330
|
+
}
|
|
306
331
|
};
|
|
307
332
|
}
|
|
308
333
|
|
|
309
|
-
//
|
|
310
|
-
|
|
334
|
+
// Public interface
|
|
335
|
+
return {
|
|
336
|
+
get_instance() {
|
|
337
|
+
if (!_instance) {
|
|
338
|
+
_instance = _create_instance(); // Lazy initialization
|
|
339
|
+
}
|
|
340
|
+
return _instance;
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
})();
|
|
311
345
|
|
|
312
|
-
let LOGR_=
|
|
346
|
+
let LOGR_= LOGR.get_instance();
|
|
347
|
+
const log_= LOGR_.log;
|
|
313
348
|
|
|
314
349
|
const l_= {
|
|
315
350
|
VALIDATION : 0b1 << 0,
|
|
316
351
|
};
|
|
352
|
+
LOGR_.labels= l_;
|
|
317
353
|
|
|
318
354
|
// TODO: use RFC3339 "timestamp"? https://ajv.js.org/json-type-definition.html
|
|
319
355
|
|
|
@@ -330,7 +366,7 @@ function requireJsonMsg_cjs () {
|
|
|
330
366
|
validate : function (json) {
|
|
331
367
|
const b_valid = schema_Msg(json);
|
|
332
368
|
if (!b_valid)
|
|
333
|
-
|
|
369
|
+
log_(l_.VALIDATION, () => ['JSON_Msg: validate: ', schema_Msg.errors]);
|
|
334
370
|
return b_valid;
|
|
335
371
|
},
|
|
336
372
|
// TODO: requires a separate ajv module require, and JTD specific schema
|
|
@@ -352,7 +388,7 @@ function requireJsonMsg_cjs () {
|
|
|
352
388
|
return false;
|
|
353
389
|
const b_valid= schema_Msg_msg(json);
|
|
354
390
|
if (!b_valid)
|
|
355
|
-
|
|
391
|
+
log_(l_.VALIDATION, () => ['JSON_Msg_msg: validate: ', schema_Msg_msg.errors]);
|
|
356
392
|
return b_valid;
|
|
357
393
|
}
|
|
358
394
|
}
|
|
@@ -380,7 +416,7 @@ function requireJsonMsg_cjs () {
|
|
|
380
416
|
return false;
|
|
381
417
|
const b_valid= schema_MsgAck_msg(json);
|
|
382
418
|
if (!b_valid)
|
|
383
|
-
|
|
419
|
+
log_(l_.VALIDATION, () => ['JSON_MsgAck: validate: ', schema_MsgAck_msg.errors]);
|
|
384
420
|
return b_valid;
|
|
385
421
|
}
|
|
386
422
|
}
|
|
@@ -389,6 +425,7 @@ function requireJsonMsg_cjs () {
|
|
|
389
425
|
jsonMsg_cjs.JSON_Msg = JSON_Msg;
|
|
390
426
|
jsonMsg_cjs.JSON_MsgAck_msg = JSON_MsgAck_msg;
|
|
391
427
|
jsonMsg_cjs.JSON_Msg_msg = JSON_Msg_msg;
|
|
428
|
+
jsonMsg_cjs.l = l_;
|
|
392
429
|
return jsonMsg_cjs;
|
|
393
430
|
}
|
|
394
431
|
|
|
@@ -440,15 +477,18 @@ class EventLog {
|
|
|
440
477
|
evt.timeout_id = setTimeout(() => {
|
|
441
478
|
if (this.map_timeouts.delete(idx)) {
|
|
442
479
|
evt.timeout_id = null;
|
|
443
|
-
timeout_callback(evt);
|
|
444
|
-
log_$1(l_$1.EVENTS, `Event DELETED[${idx}]: ${type}`, evt);
|
|
480
|
+
timeout_callback({idx, evt});
|
|
481
|
+
log_$1(l_$1.EVENTS, () => [`Event DELETED[${idx}]: ${type}`, evt]);
|
|
445
482
|
}
|
|
446
483
|
}, timeout_ms);
|
|
447
484
|
|
|
448
485
|
this.map_timeouts.set(idx, evt.timeout_id);
|
|
449
486
|
}
|
|
450
487
|
|
|
451
|
-
|
|
488
|
+
// the error "toISOString is not a function" occurs because Date(evt.dt) is not doing what you expect.
|
|
489
|
+
// When you pass a number to the Date constructor without using new, it doesn’t return a Date object—it returns a string. Specifically, it’s equivalent to new Date(evt.dt).toString().
|
|
490
|
+
// Date(evt.dt).toISOString() -> new Date(evt.dt).toISOString()
|
|
491
|
+
log_$1(l_$1.EVENTS, () => [`Event added[${idx}] @${new Date(evt.dt).toISOString()}: ${type}`, evt]);
|
|
452
492
|
return { idx, evt };
|
|
453
493
|
}
|
|
454
494
|
|
|
@@ -530,19 +570,15 @@ const k_TTL= 20000;
|
|
|
530
570
|
|
|
531
571
|
//-------------------------------------------------------------------------------------------------
|
|
532
572
|
|
|
533
|
-
// LOGR
|
|
534
|
-
// - l_LL and l_RR should accept 0b1 << 0 style shift
|
|
535
|
-
// - function to debug output bit values of labels instead of binary
|
|
536
|
-
// - rollup example in READMNE
|
|
537
573
|
|
|
538
574
|
const LOGR_= LOGR.get_instance();
|
|
539
575
|
const log_= LOGR_.log;
|
|
540
576
|
|
|
541
|
-
|
|
577
|
+
Object.assign(jsonMsg_cjsExports.l, l_LL_(jsonMsg_cjsExports.l, 2)); // VALIDATION : 4
|
|
542
578
|
|
|
543
|
-
|
|
579
|
+
const l_twoPhW_ = l_array_(['HANDLERS','DROPS', 'PROTOCOL_STATE','RECVER','SENDER']);
|
|
580
|
+
const l_ = l_concat_(l_$1, l_concat_(jsonMsg_cjsExports.l, l_twoPhW_) );
|
|
544
581
|
|
|
545
|
-
const l_= l_concat_( l_msgs_, l_concat_(l_$1, l_array_(['HANDLERS','DROPS','VALIDATION'])) );
|
|
546
582
|
LOGR_.labels= l_;
|
|
547
583
|
|
|
548
584
|
//-------------------------------------------------------------------------------------------------
|
|
@@ -927,7 +963,7 @@ class TwoPhW_EventLog {
|
|
|
927
963
|
json_msgWarp: json["_msg"]
|
|
928
964
|
};
|
|
929
965
|
}
|
|
930
|
-
return null; // Explicit default for invalid cases
|
|
966
|
+
return { str_type: null, json_msgWarp: null }; // Explicit default for invalid cases
|
|
931
967
|
}
|
|
932
968
|
|
|
933
969
|
_addEvent(json_msg, timeout_ms, timeout_callback) {
|
|
@@ -938,6 +974,8 @@ class TwoPhW_EventLog {
|
|
|
938
974
|
|
|
939
975
|
_dropEvent(json_msg) {
|
|
940
976
|
const { json_msgWarp }= this._warp(json_msg);
|
|
977
|
+
if (! json_msgWarp)
|
|
978
|
+
return;
|
|
941
979
|
this._eventLog.addEvent('2PhW[DROPPED!]', json_msgWarp.warp.id, json_msg);
|
|
942
980
|
}
|
|
943
981
|
|
|
@@ -1058,7 +1096,7 @@ class TwoPhW {
|
|
|
1058
1096
|
const timeout_ms= t_ttl_rtt_(json_msgWarp.warp.ttl_msec);
|
|
1059
1097
|
const elapsed_ms= Date.now() - Date.parse(json_msgWarp.dt);
|
|
1060
1098
|
|
|
1061
|
-
this.eventLog._addEvent(json_msgWarp, timeout_ms-elapsed_ms, () => {
|
|
1099
|
+
this.eventLog._addEvent(json_msgWarp, timeout_ms-elapsed_ms, ({ _idx, _evt}) => {
|
|
1062
1100
|
this.config._callback_msg_sent_expired(json_msgWarp);
|
|
1063
1101
|
});
|
|
1064
1102
|
}
|
|
@@ -1178,7 +1216,7 @@ class TwoPhW {
|
|
|
1178
1216
|
const elapsed_ms= Date.now() - Date.parse(json_msgAckWarp.dt);
|
|
1179
1217
|
const timeout_ms= t_ttl_rtt_(json_msgWarp.warp.ttl_msec) + Date.parse(json_msgAckWarp.dt) - Date.parse(json_msgWarp.dt);
|
|
1180
1218
|
|
|
1181
|
-
this.eventLog._addEvent(json_msgAckWarp, timeout_ms-elapsed_ms, () => {
|
|
1219
|
+
this.eventLog._addEvent(json_msgAckWarp, timeout_ms-elapsed_ms, ({ _idx, _evt}) => {
|
|
1182
1220
|
this.config._callback_msg_sent_expired(json_msgAckWarp);
|
|
1183
1221
|
});
|
|
1184
1222
|
}
|
package/package.json
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@rootintf/protocol-2phw",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "dist/twoPhW.cjs.js",
|
|
6
|
-
"browser": "dist/twoPhW.es.mjs",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"build": "node src/ajv-gen-validate.cjs && rollup --config",
|
|
9
|
-
"script": "node --experimental-json-modules tests/twoPhW.test.mjs",
|
|
10
|
-
"test": "jasmine --config=jasmine.json",
|
|
11
|
-
"clean": "del-cli dist && del-cli src/validate-esm.mjs && echo OK"
|
|
12
|
-
},
|
|
13
|
-
"repository": {
|
|
14
|
-
"type": "git",
|
|
15
|
-
"url": "git+https://gitlab.com/interface-x/npm-protocol-2PhW.git"
|
|
16
|
-
},
|
|
17
|
-
"keywords": [
|
|
18
|
-
"metaverse",
|
|
19
|
-
"warp",
|
|
20
|
-
"protocol"
|
|
21
|
-
],
|
|
22
|
-
"author": "K.Nevelsteen, PhD",
|
|
23
|
-
"license": "ISC",
|
|
24
|
-
"bugs": {
|
|
25
|
-
"url": "https://gitlab.com/interface-x/npm-protocol-2PhW.git/-/issues"
|
|
26
|
-
},
|
|
27
|
-
"homepage": "https://gitlab.com/interface-x/npm-protocol-2PhW.git#readme",
|
|
28
|
-
"dependencies": {
|
|
29
|
-
"@knev/bitlogr": "^2.0.11",
|
|
30
|
-
"@rootintf/json-msg": "^1.1.
|
|
31
|
-
"ajv": "^8.17.1"
|
|
32
|
-
},
|
|
33
|
-
"devDependencies": {
|
|
34
|
-
"@rollup/plugin-commonjs": "^28.0.3",
|
|
35
|
-
"@rollup/plugin-json": "^6.1.0",
|
|
36
|
-
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
37
|
-
"ajv-cli": "^5.0.0",
|
|
38
|
-
"del-cli": "^6.0.0",
|
|
39
|
-
"jasmine": "^5.6.0",
|
|
40
|
-
"rollup": "^4.39.0",
|
|
41
|
-
"uuid": "^11.1.0"
|
|
42
|
-
}
|
|
43
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@rootintf/protocol-2phw",
|
|
3
|
+
"version": "1.0.34-api.0.8",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/twoPhW.cjs.js",
|
|
6
|
+
"browser": "dist/twoPhW.es.mjs",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "node src/ajv-gen-validate.cjs && rollup --config",
|
|
9
|
+
"script": "node --experimental-json-modules tests/twoPhW.test.mjs",
|
|
10
|
+
"test": "jasmine --config=jasmine.json",
|
|
11
|
+
"clean": "del-cli dist && del-cli src/validate-esm.mjs && echo OK"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://gitlab.com/interface-x/npm-protocol-2PhW.git"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"metaverse",
|
|
19
|
+
"warp",
|
|
20
|
+
"protocol"
|
|
21
|
+
],
|
|
22
|
+
"author": "K.Nevelsteen, PhD",
|
|
23
|
+
"license": "ISC",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://gitlab.com/interface-x/npm-protocol-2PhW.git/-/issues"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://gitlab.com/interface-x/npm-protocol-2PhW.git#readme",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@knev/bitlogr": "^2.0.11",
|
|
30
|
+
"@rootintf/json-msg": "^1.1.5",
|
|
31
|
+
"ajv": "^8.17.1"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@rollup/plugin-commonjs": "^28.0.3",
|
|
35
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
36
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
37
|
+
"ajv-cli": "^5.0.0",
|
|
38
|
+
"del-cli": "^6.0.0",
|
|
39
|
+
"jasmine": "^5.6.0",
|
|
40
|
+
"rollup": "^4.39.0",
|
|
41
|
+
"uuid": "^11.1.0"
|
|
42
|
+
}
|
|
43
|
+
}
|
package/src/EventLog-mem.mjs
CHANGED
|
@@ -47,15 +47,18 @@ class EventLog {
|
|
|
47
47
|
evt.timeout_id = setTimeout(() => {
|
|
48
48
|
if (this.map_timeouts.delete(idx)) {
|
|
49
49
|
evt.timeout_id = null;
|
|
50
|
-
timeout_callback(evt);
|
|
51
|
-
log_(l_.EVENTS, `Event DELETED[${idx}]: ${type}`, evt);
|
|
50
|
+
timeout_callback({idx, evt});
|
|
51
|
+
log_(l_.EVENTS, () => [`Event DELETED[${idx}]: ${type}`, evt]);
|
|
52
52
|
}
|
|
53
53
|
}, timeout_ms);
|
|
54
54
|
|
|
55
55
|
this.map_timeouts.set(idx, evt.timeout_id);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
// the error "toISOString is not a function" occurs because Date(evt.dt) is not doing what you expect.
|
|
59
|
+
// When you pass a number to the Date constructor without using new, it doesn’t return a Date object—it returns a string. Specifically, it’s equivalent to new Date(evt.dt).toString().
|
|
60
|
+
// Date(evt.dt).toISOString() -> new Date(evt.dt).toISOString()
|
|
61
|
+
log_(l_.EVENTS, () => [`Event added[${idx}] @${new Date(evt.dt).toISOString()}: ${type}`, evt]);
|
|
59
62
|
return { idx, evt };
|
|
60
63
|
}
|
|
61
64
|
|
package/src/twoPhW.mjs
CHANGED
|
@@ -9,8 +9,8 @@ import {
|
|
|
9
9
|
} from './validate-esm.mjs';
|
|
10
10
|
|
|
11
11
|
// import { v4 as uuidv4 } from 'uuid'; // uuid is already a dep of JSON_Msg, so why not
|
|
12
|
-
import { LOGR, l_array, l_concat } from '@knev/bitlogr';
|
|
13
|
-
import { JSON_Msg, JSON_Msg_msg, JSON_MsgAck_msg } from '@rootintf/json-msg'
|
|
12
|
+
import { LOGR, l_array, l_concat, l_LL } from '@knev/bitlogr';
|
|
13
|
+
import { JSON_Msg, JSON_Msg_msg, JSON_MsgAck_msg, l as l_json_msg_ } from '@rootintf/json-msg'
|
|
14
14
|
|
|
15
15
|
import { EventLog, l as l_evtlog_ } from './EventLog-mem.mjs'
|
|
16
16
|
|
|
@@ -18,19 +18,15 @@ const k_TTL= 20000;
|
|
|
18
18
|
|
|
19
19
|
//-------------------------------------------------------------------------------------------------
|
|
20
20
|
|
|
21
|
-
// LOGR
|
|
22
|
-
// - l_LL and l_RR should accept 0b1 << 0 style shift
|
|
23
|
-
// - function to debug output bit values of labels instead of binary
|
|
24
|
-
// - rollup example in READMNE
|
|
25
21
|
|
|
26
22
|
const LOGR_= LOGR.get_instance();
|
|
27
23
|
const log_= LOGR_.log;
|
|
28
24
|
|
|
29
|
-
|
|
25
|
+
Object.assign(l_json_msg_, l_LL(l_json_msg_, 2)); // VALIDATION : 4
|
|
30
26
|
|
|
31
|
-
|
|
27
|
+
const l_twoPhW_ = l_array(['HANDLERS','DROPS', 'PROTOCOL_STATE','RECVER','SENDER']);
|
|
28
|
+
const l_ = l_concat(l_evtlog_, l_concat(l_json_msg_, l_twoPhW_) )
|
|
32
29
|
|
|
33
|
-
const l_= l_concat( l_msgs_, l_concat(l_evtlog_, l_array(['HANDLERS','DROPS','VALIDATION'])) )
|
|
34
30
|
LOGR_.labels= l_;
|
|
35
31
|
|
|
36
32
|
//-------------------------------------------------------------------------------------------------
|
|
@@ -421,7 +417,7 @@ class TwoPhW_EventLog {
|
|
|
421
417
|
json_msgWarp: json["_msg"]
|
|
422
418
|
};
|
|
423
419
|
}
|
|
424
|
-
return null; // Explicit default for invalid cases
|
|
420
|
+
return { str_type: null, json_msgWarp: null }; // Explicit default for invalid cases
|
|
425
421
|
}
|
|
426
422
|
|
|
427
423
|
_addEvent(json_msg, timeout_ms, timeout_callback) {
|
|
@@ -432,6 +428,8 @@ class TwoPhW_EventLog {
|
|
|
432
428
|
|
|
433
429
|
_dropEvent(json_msg) {
|
|
434
430
|
const { json_msgWarp }= this._warp(json_msg);
|
|
431
|
+
if (! json_msgWarp)
|
|
432
|
+
return;
|
|
435
433
|
this._eventLog.addEvent('2PhW[DROPPED!]', json_msgWarp.warp.id, json_msg);
|
|
436
434
|
}
|
|
437
435
|
|
|
@@ -552,7 +550,7 @@ class TwoPhW {
|
|
|
552
550
|
const timeout_ms= t_ttl_rtt_(json_msgWarp.warp.ttl_msec);
|
|
553
551
|
const elapsed_ms= Date.now() - Date.parse(json_msgWarp.dt);
|
|
554
552
|
|
|
555
|
-
this.eventLog._addEvent(json_msgWarp, timeout_ms-elapsed_ms, () => {
|
|
553
|
+
this.eventLog._addEvent(json_msgWarp, timeout_ms-elapsed_ms, ({ _idx, _evt}) => {
|
|
556
554
|
this.config._callback_msg_sent_expired(json_msgWarp);
|
|
557
555
|
});
|
|
558
556
|
}
|
|
@@ -672,7 +670,7 @@ class TwoPhW {
|
|
|
672
670
|
const elapsed_ms= Date.now() - Date.parse(json_msgAckWarp.dt);
|
|
673
671
|
const timeout_ms= t_ttl_rtt_(json_msgWarp.warp.ttl_msec) + Date.parse(json_msgAckWarp.dt) - Date.parse(json_msgWarp.dt);
|
|
674
672
|
|
|
675
|
-
this.eventLog._addEvent(json_msgAckWarp, timeout_ms-elapsed_ms, () => {
|
|
673
|
+
this.eventLog._addEvent(json_msgAckWarp, timeout_ms-elapsed_ms, ({ _idx, _evt}) => {
|
|
676
674
|
this.config._callback_msg_sent_expired(json_msgAckWarp);
|
|
677
675
|
});
|
|
678
676
|
}
|
|
@@ -163,7 +163,7 @@ describe('EventLog', () => {
|
|
|
163
163
|
|
|
164
164
|
jasmine.clock().tick(5001);
|
|
165
165
|
|
|
166
|
-
expect(timeout_callback).toHaveBeenCalledWith(evt);
|
|
166
|
+
expect(timeout_callback).toHaveBeenCalledWith({ idx, evt});
|
|
167
167
|
expect(eventLog.map_timeouts.size).toBe(0); // Timeout should be cleaned up
|
|
168
168
|
});
|
|
169
169
|
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
StateAckEngage, StateEngage, StateAckWarp, StateWarp, StateInitialState, StateINVALID,
|
|
6
6
|
EventLog,
|
|
7
7
|
t_ttl_rtt,
|
|
8
|
-
TwoPhW, JSON_MsgOptions, JSON_MsgWarp, JSON_MsgEngage, JSON_MsgAckWarp, JSON_MsgAckEngage, l as
|
|
8
|
+
TwoPhW, JSON_MsgOptions, JSON_MsgWarp, JSON_MsgEngage, JSON_MsgAckWarp, JSON_MsgAckEngage, l as l_twoPhW_,
|
|
9
9
|
} from '../src/TwoPhW.mjs';
|
|
10
10
|
import { JSON_Msg, JSON_Msg_msg, JSON_MsgAck_msg } from '@rootintf/json-msg'
|
|
11
11
|
|
|
@@ -24,7 +24,7 @@ const RTT_MSEC_2000= 2000;
|
|
|
24
24
|
|
|
25
25
|
const LOGR_= LOGR.get_instance()
|
|
26
26
|
|
|
27
|
-
const l_ = l_concat(
|
|
27
|
+
const l_ = l_concat(l_twoPhW_, ['LOG_TEST']);
|
|
28
28
|
LOGR_.labels= l_;
|
|
29
29
|
LOGR_.toggled= {
|
|
30
30
|
LOG_TEST : true
|
package/tests/twoPhW.test.mjs
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
// throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
|
|
3
|
-
// https://stackoverflow.com/questions/69118216/crypto-getrandomvalues-not-supported-in-react-js
|
|
4
|
-
// - https://stackoverflow.com/questions/52612122/how-to-use-jest-to-test-functions-using-crypto-or-window-mscrypto
|
|
5
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
6
|
-
import crypto from 'crypto'
|
|
7
|
-
Object.defineProperty(globalThis, 'crypto', {
|
|
8
|
-
value: {
|
|
9
|
-
getRandomValues: arr => crypto.randomBytes(arr.length)
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
import { TwoPhW, JSON_MsgOptions, JSON_MsgWarp, JSON_MsgEngage, l as l_2PhW } from '../src/twoPhW.mjs';
|
|
14
|
-
|
|
15
|
-
console.log('l_2PhW', l_2PhW, Object.keys(l_2PhW).length);
|
|
16
|
-
|
|
17
|
-
const recv_referer_= [ "recv", uuidv4()];
|
|
18
|
-
console.log('recv_referer_= ' + recv_referer_);
|
|
19
|
-
|
|
20
|
-
const send_referer_= [ "send", uuidv4()];
|
|
21
|
-
console.log('send_referer_= ' + send_referer_);
|
|
22
|
-
|
|
23
|
-
var twoPhW_recv_= new TwoPhW();
|
|
24
|
-
var twoPhW_send_= new TwoPhW();
|
|
25
|
-
|
|
26
|
-
twoPhW_recv_.config.receiver( callback_msgWarp_, callback_msgEngage_ );
|
|
27
|
-
twoPhW_recv_.config.callback_msgOptions= callback_msgOptions_;
|
|
28
|
-
twoPhW_recv_.config.logr= {
|
|
29
|
-
// HANDLERS : 1,
|
|
30
|
-
// VALIDATION : 1
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
twoPhW_send_.config.sender( callback_msgAckWarp_, callback_msgAckEngage_ );
|
|
34
|
-
twoPhW_send_.config.callback_msgOptions= callback_msgOptions_;
|
|
35
|
-
twoPhW_send_.config.logr= {
|
|
36
|
-
HANDLERS : 1,
|
|
37
|
-
// VALIDATION : 1
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
//-------------------------------------------------------------------------------------------------
|
|
41
|
-
|
|
42
|
-
function callback_msgOptions_(msg, json_msgOptions)
|
|
43
|
-
{
|
|
44
|
-
console.log('callback_msgOptions_: ', json_msgOptions);
|
|
45
|
-
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
//-------------------------------------------------------------------------------------------------
|
|
50
|
-
// Sender
|
|
51
|
-
|
|
52
|
-
function callback_msgAckWarp_(msg, json_msgAckWarp)
|
|
53
|
-
{
|
|
54
|
-
console.log('callback_msgAckWarp_: Ack: ', json_msgAckWarp);
|
|
55
|
-
|
|
56
|
-
// console.log('callback_msgAckWarp_: publish: Engage: ', json_Engage);
|
|
57
|
-
// IPSME_MsgEnv.publish( JSON.stringify(json_Engage) );
|
|
58
|
-
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function callback_msgAckEngage_(msg, json_msgAckEngage)
|
|
63
|
-
{
|
|
64
|
-
console.log('callback_msgAckEngage_: Ack: ', json_msgAckEngage);
|
|
65
|
-
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
//-------------------------------------------------------------------------------------------------
|
|
70
|
-
// Receiver
|
|
71
|
-
|
|
72
|
-
function callback_msgWarp_(msg, json_msgWarp)
|
|
73
|
-
{
|
|
74
|
-
// console.log('callback_msgWarp_: Warp: ', json_Warp);
|
|
75
|
-
console.log('callback_msgWarp_: Warp: ...');
|
|
76
|
-
|
|
77
|
-
// console.log('callback_msgWarp_: publish Ack Warp: ', json_Ack);
|
|
78
|
-
// IPSME_MsgEnv.publish( JSON.stringify(json_Ack) );
|
|
79
|
-
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function callback_msgEngage_(msg, json_msgEngage)
|
|
84
|
-
{
|
|
85
|
-
// console.log('callback_msgEngage_: Engage: ', json_Engage);
|
|
86
|
-
console.log('callback_msgEngage_: Engage: ...');
|
|
87
|
-
|
|
88
|
-
// console.log('callback_msgEngage_: publish: Ack Engage: ', json_Ack);
|
|
89
|
-
// IPSME_MsgEnv.publish( JSON.stringify(json_Ack) );
|
|
90
|
-
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
//-------------------------------------------------------------------------------------------------
|
|
95
|
-
|
|
96
|
-
function callback_Abort_()
|
|
97
|
-
{
|
|
98
|
-
console.log('callback_Abort: ... : ');
|
|
99
|
-
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
//-------------------------------------------------------------------------------------------------
|
|
104
|
-
|
|
105
|
-
// const json_Warp_ = {
|
|
106
|
-
// id: "f5d6c2b8-1481-49b2-882c-262bb1c9ef8c",
|
|
107
|
-
// referer: "af9447e3-4b36-424f-8d07-976a9216a298",
|
|
108
|
-
// dt: "2022-10-28T06:26:19.692Z",
|
|
109
|
-
// warp: {
|
|
110
|
-
// user: {},
|
|
111
|
-
// hyperport: {},
|
|
112
|
-
// ttl_msec: 4000
|
|
113
|
-
// },
|
|
114
|
-
// "2PhW" : "0.6"
|
|
115
|
-
// }
|
|
116
|
-
|
|
117
|
-
// const json_Engage_ = {
|
|
118
|
-
// referer: "af9447e3-4b36-424f-8d07-976a9216a298",
|
|
119
|
-
// dt: "2022-10-28T06:26:19.692Z",
|
|
120
|
-
// engage: {
|
|
121
|
-
// id: "f5d6c2b8-1481-49b2-882c-262bb1c9ef8c",
|
|
122
|
-
// user: {},
|
|
123
|
-
// hyperport: {}
|
|
124
|
-
// }
|
|
125
|
-
// }
|
|
126
|
-
|
|
127
|
-
const json_msgWarp_= twoPhW_send_.create_MsgWarp_out(uuidv4(), { "user": "user"}, { "hyperport" : "hyperport" }, 4000);
|
|
128
|
-
json_msgWarp_.referer= send_referer_;
|
|
129
|
-
|
|
130
|
-
const ttl_warp= json_msgWarp_.warp.ttl_msec;
|
|
131
|
-
|
|
132
|
-
const json_msgOptions= JSON_MsgOptions.create_with_msg_options(json_msgWarp_, {
|
|
133
|
-
"ttl_msec_incr" : [ ttl_warp, 3000 ]
|
|
134
|
-
});
|
|
135
|
-
json_msgOptions.referer= recv_referer_;
|
|
136
|
-
|
|
137
|
-
// https://stackoverflow.com/questions/951021/what-is-the-javascript-version-of-sleep
|
|
138
|
-
await new Promise(r => setTimeout(r, 1500));
|
|
139
|
-
|
|
140
|
-
twoPhW_send_.handler_msg(json_msgOptions);
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
// twoPhW_recv_.handler_msg(json_msgWarp_);
|
|
144
|
-
// twoPhW.handler_msg(json_Engage_);
|
|
145
|
-
|
|
146
|
-
//-------------------------------------------------------------------------------------------------
|
|
147
|
-
|
|
148
|
-
// const json_Ack_str_ = {
|
|
149
|
-
// referer: ["twoPhW", "af9447e3-4b36-424f-8d07-976a9216a298"],
|
|
150
|
-
// dt: "2022-10-28T06:26:19.692Z",
|
|
151
|
-
// ack: {
|
|
152
|
-
// "ok" : true,
|
|
153
|
-
// "_msg" : JSON.stringify( json_Warp_ )
|
|
154
|
-
// }
|
|
155
|
-
// }
|
|
156
|
-
|
|
157
|
-
// const json_Ack_obj_ = {
|
|
158
|
-
// referer: ["twoPhW", "af9447e3-4b36-424f-8d07-976a9216a298"],
|
|
159
|
-
// dt: "2022-10-28T06:26:19.692Z",
|
|
160
|
-
// ack: {
|
|
161
|
-
// "ok" : true,
|
|
162
|
-
// "_msg" : json_Warp_.warp
|
|
163
|
-
// }
|
|
164
|
-
// }
|
|
165
|
-
|
|
166
|
-
// twoPhW.handler_msg(json_Ack_str_);
|
|
167
|
-
|
|
168
|
-
//-------------------------------------------------------------------------------------------------
|
|
169
|
-
|
|
170
|
-
twoPhW_recv_.config.options= {
|
|
171
|
-
logr : {
|
|
172
|
-
DROPS : 1
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
// twoPhW.handler_msg('THIS msg SHOULD DROP');
|