@naylence/runtime 0.3.5-test.941 → 0.3.5-test.943
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/browser/index.cjs +390 -8
- package/dist/browser/index.mjs +390 -8
- package/dist/cjs/naylence/fame/connector/broadcast-channel-connector-factory.js +12 -0
- package/dist/cjs/naylence/fame/connector/broadcast-channel-connector.browser.js +69 -1
- package/dist/cjs/naylence/fame/connector/inpage-connector-factory.js +12 -0
- package/dist/cjs/naylence/fame/connector/inpage-connector.js +159 -1
- package/dist/cjs/naylence/fame/connector/transport-frame.js +101 -0
- package/dist/cjs/naylence/fame/grants/broadcast-channel-connection-grant.js +28 -0
- package/dist/cjs/naylence/fame/grants/inpage-connection-grant.js +28 -0
- package/dist/cjs/naylence/fame/node/upstream-session-manager.js +2 -2
- package/dist/cjs/version.js +2 -2
- package/dist/esm/naylence/fame/connector/broadcast-channel-connector-factory.js +12 -0
- package/dist/esm/naylence/fame/connector/broadcast-channel-connector.browser.js +69 -1
- package/dist/esm/naylence/fame/connector/inpage-connector-factory.js +12 -0
- package/dist/esm/naylence/fame/connector/inpage-connector.js +159 -1
- package/dist/esm/naylence/fame/connector/transport-frame.js +94 -0
- package/dist/esm/naylence/fame/grants/broadcast-channel-connection-grant.js +28 -0
- package/dist/esm/naylence/fame/grants/inpage-connection-grant.js +28 -0
- package/dist/esm/naylence/fame/node/upstream-session-manager.js +2 -2
- package/dist/esm/version.js +2 -2
- package/dist/node/index.cjs +390 -8
- package/dist/node/index.mjs +390 -8
- package/dist/node/node.cjs +406 -8
- package/dist/node/node.mjs +406 -8
- package/dist/types/naylence/fame/connector/broadcast-channel-connector-factory.d.ts +2 -0
- package/dist/types/naylence/fame/connector/broadcast-channel-connector.browser.d.ts +4 -0
- package/dist/types/naylence/fame/connector/inpage-connector-factory.d.ts +2 -0
- package/dist/types/naylence/fame/connector/inpage-connector.d.ts +11 -1
- package/dist/types/naylence/fame/connector/transport-frame.d.ts +58 -0
- package/dist/types/naylence/fame/grants/broadcast-channel-connection-grant.d.ts +6 -0
- package/dist/types/naylence/fame/grants/inpage-connection-grant.d.ts +8 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -1
package/dist/node/node.mjs
CHANGED
|
@@ -5477,12 +5477,12 @@ for (const [name, config] of Object.entries(SQLITE_PROFILES)) {
|
|
|
5477
5477
|
}
|
|
5478
5478
|
|
|
5479
5479
|
// This file is auto-generated during build - do not edit manually
|
|
5480
|
-
// Generated from package.json version: 0.3.5-test.
|
|
5480
|
+
// Generated from package.json version: 0.3.5-test.943
|
|
5481
5481
|
/**
|
|
5482
5482
|
* The package version, injected at build time.
|
|
5483
5483
|
* @internal
|
|
5484
5484
|
*/
|
|
5485
|
-
const VERSION = '0.3.5-test.
|
|
5485
|
+
const VERSION = '0.3.5-test.943';
|
|
5486
5486
|
|
|
5487
5487
|
/**
|
|
5488
5488
|
* Fame errors module - Fame protocol specific error classes
|
|
@@ -11470,6 +11470,101 @@ class BoundedAsyncQueue {
|
|
|
11470
11470
|
}
|
|
11471
11471
|
}
|
|
11472
11472
|
|
|
11473
|
+
/**
|
|
11474
|
+
* Transport frame layer for multiplexing logical links on physical channels.
|
|
11475
|
+
*
|
|
11476
|
+
* This lightweight framing layer wraps raw FAME payloads to enable multiple
|
|
11477
|
+
* logical connections over a single physical channel (BroadcastChannel or InPage bus).
|
|
11478
|
+
*
|
|
11479
|
+
* The transport frame does NOT modify FAME envelopes - it only wraps the raw
|
|
11480
|
+
* Uint8Array payload at the connector level.
|
|
11481
|
+
*/
|
|
11482
|
+
/**
|
|
11483
|
+
* Transport frame version for future compatibility
|
|
11484
|
+
*/
|
|
11485
|
+
const TRANSPORT_FRAME_VERSION = 1;
|
|
11486
|
+
/**
|
|
11487
|
+
* Wrap a raw payload in a transport frame
|
|
11488
|
+
*
|
|
11489
|
+
* @param payload - Raw FAME envelope bytes
|
|
11490
|
+
* @param srcNodeId - Local node ID (this connector)
|
|
11491
|
+
* @param dstNodeId - Remote node ID (target connector)
|
|
11492
|
+
* @returns Transport frame ready for transmission
|
|
11493
|
+
*/
|
|
11494
|
+
function wrapTransportFrame(payload, srcNodeId, dstNodeId) {
|
|
11495
|
+
return {
|
|
11496
|
+
v: TRANSPORT_FRAME_VERSION,
|
|
11497
|
+
src: srcNodeId,
|
|
11498
|
+
dst: dstNodeId,
|
|
11499
|
+
payload,
|
|
11500
|
+
};
|
|
11501
|
+
}
|
|
11502
|
+
/**
|
|
11503
|
+
* Serialize a transport frame for transmission over the bus
|
|
11504
|
+
*
|
|
11505
|
+
* @param frame - Transport frame to serialize
|
|
11506
|
+
* @returns Serialized frame data ready for postMessage/dispatchEvent
|
|
11507
|
+
*/
|
|
11508
|
+
function serializeTransportFrame(frame) {
|
|
11509
|
+
// Convert Uint8Array to regular array for JSON serialization
|
|
11510
|
+
const serializable = {
|
|
11511
|
+
v: frame.v,
|
|
11512
|
+
src: frame.src,
|
|
11513
|
+
dst: frame.dst,
|
|
11514
|
+
payload: Array.from(frame.payload),
|
|
11515
|
+
};
|
|
11516
|
+
return serializable;
|
|
11517
|
+
}
|
|
11518
|
+
/**
|
|
11519
|
+
* Unwrap a transport frame, validating source and destination
|
|
11520
|
+
*
|
|
11521
|
+
* @param raw - Raw data from the bus
|
|
11522
|
+
* @param localNodeId - This connector's node ID
|
|
11523
|
+
* @param remoteNodeId - Expected remote node ID
|
|
11524
|
+
* @returns Unwrapped payload if frame is valid and addressed to us, null otherwise
|
|
11525
|
+
*/
|
|
11526
|
+
function unwrapTransportFrame(raw, localNodeId, remoteNodeId) {
|
|
11527
|
+
// Validate basic structure
|
|
11528
|
+
if (!raw || typeof raw !== 'object') {
|
|
11529
|
+
return null;
|
|
11530
|
+
}
|
|
11531
|
+
const frame = raw;
|
|
11532
|
+
// Check version
|
|
11533
|
+
if (frame.v !== TRANSPORT_FRAME_VERSION) {
|
|
11534
|
+
return null;
|
|
11535
|
+
}
|
|
11536
|
+
// Check src and dst
|
|
11537
|
+
if (typeof frame.src !== 'string' || typeof frame.dst !== 'string') {
|
|
11538
|
+
return null;
|
|
11539
|
+
}
|
|
11540
|
+
// Only accept frames addressed to us from the expected remote
|
|
11541
|
+
if (frame.dst !== localNodeId || frame.src !== remoteNodeId) {
|
|
11542
|
+
return null;
|
|
11543
|
+
}
|
|
11544
|
+
// Extract payload
|
|
11545
|
+
if (!frame.payload || !Array.isArray(frame.payload)) {
|
|
11546
|
+
return null;
|
|
11547
|
+
}
|
|
11548
|
+
// Convert array back to Uint8Array
|
|
11549
|
+
return Uint8Array.from(frame.payload);
|
|
11550
|
+
}
|
|
11551
|
+
/**
|
|
11552
|
+
* Check if raw data looks like a transport frame
|
|
11553
|
+
*
|
|
11554
|
+
* @param raw - Raw data from the bus
|
|
11555
|
+
* @returns True if this appears to be a transport frame
|
|
11556
|
+
*/
|
|
11557
|
+
function isTransportFrame(raw) {
|
|
11558
|
+
if (!raw || typeof raw !== 'object') {
|
|
11559
|
+
return false;
|
|
11560
|
+
}
|
|
11561
|
+
const frame = raw;
|
|
11562
|
+
return (typeof frame.v === 'number' &&
|
|
11563
|
+
typeof frame.src === 'string' &&
|
|
11564
|
+
typeof frame.dst === 'string' &&
|
|
11565
|
+
Array.isArray(frame.payload));
|
|
11566
|
+
}
|
|
11567
|
+
|
|
11473
11568
|
const logger$10 = getLogger('naylence.fame.connector.broadcast_channel_connector');
|
|
11474
11569
|
const BROADCAST_CHANNEL_CONNECTOR_TYPE$1 = 'broadcast-channel-connector';
|
|
11475
11570
|
const DEFAULT_CHANNEL$7 = 'naylence-fabric';
|
|
@@ -11535,9 +11630,20 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
|
|
|
11535
11630
|
this.inbox = new BoundedAsyncQueue(preferredCapacity);
|
|
11536
11631
|
this.connectorId = BroadcastChannelConnector.generateConnectorId();
|
|
11537
11632
|
this.channel = new BroadcastChannel(this.channelName);
|
|
11633
|
+
// Set local and remote node IDs (defaults to connector ID for backwards compatibility)
|
|
11634
|
+
this.localNodeId =
|
|
11635
|
+
typeof config.localNodeId === 'string' && config.localNodeId.trim().length > 0
|
|
11636
|
+
? config.localNodeId.trim()
|
|
11637
|
+
: this.connectorId;
|
|
11638
|
+
this.remoteNodeId =
|
|
11639
|
+
typeof config.remoteNodeId === 'string' && config.remoteNodeId.trim().length > 0
|
|
11640
|
+
? config.remoteNodeId.trim()
|
|
11641
|
+
: '*'; // Accept from any remote if not specified
|
|
11538
11642
|
logger$10.debug('broadcast_channel_connector_created', {
|
|
11539
11643
|
channel: this.channelName,
|
|
11540
11644
|
connector_id: this.connectorId,
|
|
11645
|
+
local_node_id: this.localNodeId,
|
|
11646
|
+
remote_node_id: this.remoteNodeId,
|
|
11541
11647
|
inbox_capacity: preferredCapacity,
|
|
11542
11648
|
timestamp: new Date().toISOString(),
|
|
11543
11649
|
});
|
|
@@ -11570,6 +11676,46 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
|
|
|
11570
11676
|
if (busMessage.senderId === this.connectorId) {
|
|
11571
11677
|
return;
|
|
11572
11678
|
}
|
|
11679
|
+
// Try to unwrap as transport frame
|
|
11680
|
+
const unwrapped = unwrapTransportFrame(busMessage.payload, this.localNodeId, this.remoteNodeId === '*' ? busMessage.senderId : this.remoteNodeId);
|
|
11681
|
+
if (unwrapped) {
|
|
11682
|
+
// Successfully unwrapped transport frame
|
|
11683
|
+
logger$10.debug('broadcast_channel_transport_frame_received', {
|
|
11684
|
+
channel: this.channelName,
|
|
11685
|
+
sender_id: busMessage.senderId,
|
|
11686
|
+
connector_id: this.connectorId,
|
|
11687
|
+
local_node_id: this.localNodeId,
|
|
11688
|
+
remote_node_id: this.remoteNodeId,
|
|
11689
|
+
payload_length: unwrapped.byteLength,
|
|
11690
|
+
});
|
|
11691
|
+
if (this._shouldSkipDuplicateAck(busMessage.senderId, unwrapped)) {
|
|
11692
|
+
return;
|
|
11693
|
+
}
|
|
11694
|
+
try {
|
|
11695
|
+
if (typeof this.inbox.tryEnqueue === 'function') {
|
|
11696
|
+
const accepted = this.inbox.tryEnqueue(unwrapped);
|
|
11697
|
+
if (accepted) {
|
|
11698
|
+
return;
|
|
11699
|
+
}
|
|
11700
|
+
}
|
|
11701
|
+
this.inbox.enqueue(unwrapped);
|
|
11702
|
+
}
|
|
11703
|
+
catch (error) {
|
|
11704
|
+
if (error instanceof QueueFullError) {
|
|
11705
|
+
logger$10.warning('broadcast_channel_receive_queue_full', {
|
|
11706
|
+
channel: this.channelName,
|
|
11707
|
+
});
|
|
11708
|
+
}
|
|
11709
|
+
else {
|
|
11710
|
+
logger$10.error('broadcast_channel_receive_error', {
|
|
11711
|
+
channel: this.channelName,
|
|
11712
|
+
error: error instanceof Error ? error.message : String(error),
|
|
11713
|
+
});
|
|
11714
|
+
}
|
|
11715
|
+
}
|
|
11716
|
+
return;
|
|
11717
|
+
}
|
|
11718
|
+
// Fall back to legacy format (no transport frame)
|
|
11573
11719
|
const payload = BroadcastChannelConnector.coercePayload(busMessage.payload);
|
|
11574
11720
|
if (!payload) {
|
|
11575
11721
|
logger$10.debug('broadcast_channel_payload_rejected', {
|
|
@@ -11708,10 +11854,26 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
|
|
|
11708
11854
|
logger$10.debug('broadcast_channel_message_sending', {
|
|
11709
11855
|
channel: this.channelName,
|
|
11710
11856
|
sender_id: this.connectorId,
|
|
11711
|
-
|
|
11857
|
+
local_node_id: this.localNodeId,
|
|
11858
|
+
remote_node_id: this.remoteNodeId,
|
|
11859
|
+
});
|
|
11860
|
+
// Only use transport framing if both localNodeId and remoteNodeId are explicitly set
|
|
11861
|
+
// (not using default values). This ensures backwards compatibility.
|
|
11862
|
+
const useTransportFrame = this.localNodeId !== this.connectorId ||
|
|
11863
|
+
this.remoteNodeId !== '*';
|
|
11864
|
+
let payload;
|
|
11865
|
+
if (useTransportFrame) {
|
|
11866
|
+
// Wrap payload in transport frame
|
|
11867
|
+
const frame = wrapTransportFrame(data, this.localNodeId, this.remoteNodeId);
|
|
11868
|
+
payload = serializeTransportFrame(frame);
|
|
11869
|
+
}
|
|
11870
|
+
else {
|
|
11871
|
+
// Legacy format: send raw payload
|
|
11872
|
+
payload = data;
|
|
11873
|
+
}
|
|
11712
11874
|
this.channel.postMessage({
|
|
11713
11875
|
senderId: this.connectorId,
|
|
11714
|
-
payload
|
|
11876
|
+
payload,
|
|
11715
11877
|
});
|
|
11716
11878
|
}
|
|
11717
11879
|
async _transportReceive() {
|
|
@@ -11959,6 +12121,14 @@ function isBroadcastChannelConnectionGrant(candidate) {
|
|
|
11959
12121
|
record.inboxCapacity <= 0)) {
|
|
11960
12122
|
return false;
|
|
11961
12123
|
}
|
|
12124
|
+
if (record.localNodeId !== undefined &&
|
|
12125
|
+
(typeof record.localNodeId !== 'string' || record.localNodeId.length === 0)) {
|
|
12126
|
+
return false;
|
|
12127
|
+
}
|
|
12128
|
+
if (record.remoteNodeId !== undefined &&
|
|
12129
|
+
(typeof record.remoteNodeId !== 'string' || record.remoteNodeId.length === 0)) {
|
|
12130
|
+
return false;
|
|
12131
|
+
}
|
|
11962
12132
|
return true;
|
|
11963
12133
|
}
|
|
11964
12134
|
function normalizeBroadcastChannelConnectionGrant(candidate) {
|
|
@@ -11992,6 +12162,20 @@ function normalizeBroadcastChannelConnectionGrant(candidate) {
|
|
|
11992
12162
|
}
|
|
11993
12163
|
result.inboxCapacity = Math.floor(inboxValue);
|
|
11994
12164
|
}
|
|
12165
|
+
const localNodeIdValue = candidate.localNodeId ?? candidate['local_node_id'];
|
|
12166
|
+
if (localNodeIdValue !== undefined) {
|
|
12167
|
+
if (typeof localNodeIdValue !== 'string' || localNodeIdValue.trim().length === 0) {
|
|
12168
|
+
throw new TypeError('BroadcastChannelConnectionGrant "localNodeId" must be a non-empty string when provided');
|
|
12169
|
+
}
|
|
12170
|
+
result.localNodeId = localNodeIdValue.trim();
|
|
12171
|
+
}
|
|
12172
|
+
const remoteNodeIdValue = candidate.remoteNodeId ?? candidate['remote_node_id'];
|
|
12173
|
+
if (remoteNodeIdValue !== undefined) {
|
|
12174
|
+
if (typeof remoteNodeIdValue !== 'string' || remoteNodeIdValue.trim().length === 0) {
|
|
12175
|
+
throw new TypeError('BroadcastChannelConnectionGrant "remoteNodeId" must be a non-empty string when provided');
|
|
12176
|
+
}
|
|
12177
|
+
result.remoteNodeId = remoteNodeIdValue.trim();
|
|
12178
|
+
}
|
|
11995
12179
|
return result;
|
|
11996
12180
|
}
|
|
11997
12181
|
function broadcastChannelGrantToConnectorConfig(grant) {
|
|
@@ -12005,6 +12189,12 @@ function broadcastChannelGrantToConnectorConfig(grant) {
|
|
|
12005
12189
|
if (normalized.inboxCapacity !== undefined) {
|
|
12006
12190
|
config.inboxCapacity = normalized.inboxCapacity;
|
|
12007
12191
|
}
|
|
12192
|
+
if (normalized.localNodeId) {
|
|
12193
|
+
config.localNodeId = normalized.localNodeId;
|
|
12194
|
+
}
|
|
12195
|
+
if (normalized.remoteNodeId) {
|
|
12196
|
+
config.remoteNodeId = normalized.remoteNodeId;
|
|
12197
|
+
}
|
|
12008
12198
|
return config;
|
|
12009
12199
|
}
|
|
12010
12200
|
|
|
@@ -12384,7 +12574,7 @@ class UpstreamSessionManager extends TaskSpawner {
|
|
|
12384
12574
|
this.currentStopSubtasks = null;
|
|
12385
12575
|
await Promise.allSettled(tasks.map((task) => task.promise));
|
|
12386
12576
|
if (this.connector) {
|
|
12387
|
-
logger$$.
|
|
12577
|
+
logger$$.debug('upstream_stopping_old_connector', {
|
|
12388
12578
|
connect_epoch: this.connectEpoch,
|
|
12389
12579
|
target_system_id: this.targetSystemId,
|
|
12390
12580
|
timestamp: new Date().toISOString(),
|
|
@@ -12395,7 +12585,7 @@ class UpstreamSessionManager extends TaskSpawner {
|
|
|
12395
12585
|
error: err instanceof Error ? err.message : String(err),
|
|
12396
12586
|
});
|
|
12397
12587
|
});
|
|
12398
|
-
logger$$.
|
|
12588
|
+
logger$$.debug('upstream_old_connector_stopped', {
|
|
12399
12589
|
connect_epoch: this.connectEpoch,
|
|
12400
12590
|
target_system_id: this.targetSystemId,
|
|
12401
12591
|
timestamp: new Date().toISOString(),
|
|
@@ -21425,6 +21615,7 @@ class InPageConnector extends BaseAsyncConnector {
|
|
|
21425
21615
|
ensureBrowserEnvironment$2();
|
|
21426
21616
|
super(baseConfig);
|
|
21427
21617
|
this.listenerRegistered = false;
|
|
21618
|
+
this.visibilityChangeListenerRegistered = false;
|
|
21428
21619
|
this.channelName =
|
|
21429
21620
|
typeof config.channelName === 'string' && config.channelName.trim().length > 0
|
|
21430
21621
|
? config.channelName.trim()
|
|
@@ -21436,9 +21627,20 @@ class InPageConnector extends BaseAsyncConnector {
|
|
|
21436
21627
|
: DEFAULT_INBOX_CAPACITY$6;
|
|
21437
21628
|
this.inbox = new BoundedAsyncQueue(preferredCapacity);
|
|
21438
21629
|
this.connectorId = InPageConnector.generateConnectorId();
|
|
21630
|
+
// Set local and remote node IDs (defaults to connector ID for backwards compatibility)
|
|
21631
|
+
this.localNodeId =
|
|
21632
|
+
typeof config.localNodeId === 'string' && config.localNodeId.trim().length > 0
|
|
21633
|
+
? config.localNodeId.trim()
|
|
21634
|
+
: this.connectorId;
|
|
21635
|
+
this.remoteNodeId =
|
|
21636
|
+
typeof config.remoteNodeId === 'string' && config.remoteNodeId.trim().length > 0
|
|
21637
|
+
? config.remoteNodeId.trim()
|
|
21638
|
+
: '*'; // Accept from any remote if not specified
|
|
21439
21639
|
logger$J.debug('inpage_connector_initialized', {
|
|
21440
21640
|
channel: this.channelName,
|
|
21441
21641
|
connector_id: this.connectorId,
|
|
21642
|
+
local_node_id: this.localNodeId,
|
|
21643
|
+
remote_node_id: this.remoteNodeId,
|
|
21442
21644
|
});
|
|
21443
21645
|
this.onMsg = (event) => {
|
|
21444
21646
|
const messageEvent = event;
|
|
@@ -21472,6 +21674,43 @@ class InPageConnector extends BaseAsyncConnector {
|
|
|
21472
21674
|
if (busMessage.senderId === this.connectorId) {
|
|
21473
21675
|
return;
|
|
21474
21676
|
}
|
|
21677
|
+
// Try to unwrap as transport frame
|
|
21678
|
+
const unwrapped = unwrapTransportFrame(busMessage.payload, this.localNodeId, this.remoteNodeId === '*' ? busMessage.senderId : this.remoteNodeId);
|
|
21679
|
+
if (unwrapped) {
|
|
21680
|
+
// Successfully unwrapped transport frame
|
|
21681
|
+
logger$J.debug('inpage_transport_frame_received', {
|
|
21682
|
+
channel: this.channelName,
|
|
21683
|
+
sender_id: busMessage.senderId,
|
|
21684
|
+
connector_id: this.connectorId,
|
|
21685
|
+
local_node_id: this.localNodeId,
|
|
21686
|
+
remote_node_id: this.remoteNodeId,
|
|
21687
|
+
payload_length: unwrapped.byteLength,
|
|
21688
|
+
});
|
|
21689
|
+
try {
|
|
21690
|
+
if (typeof this.inbox.tryEnqueue === 'function') {
|
|
21691
|
+
const accepted = this.inbox.tryEnqueue(unwrapped);
|
|
21692
|
+
if (accepted) {
|
|
21693
|
+
return;
|
|
21694
|
+
}
|
|
21695
|
+
}
|
|
21696
|
+
this.inbox.enqueue(unwrapped);
|
|
21697
|
+
}
|
|
21698
|
+
catch (error) {
|
|
21699
|
+
if (error instanceof QueueFullError) {
|
|
21700
|
+
logger$J.warning('inpage_receive_queue_full', {
|
|
21701
|
+
channel: this.channelName,
|
|
21702
|
+
});
|
|
21703
|
+
}
|
|
21704
|
+
else {
|
|
21705
|
+
logger$J.error('inpage_receive_error', {
|
|
21706
|
+
channel: this.channelName,
|
|
21707
|
+
error: error instanceof Error ? error.message : String(error),
|
|
21708
|
+
});
|
|
21709
|
+
}
|
|
21710
|
+
}
|
|
21711
|
+
return;
|
|
21712
|
+
}
|
|
21713
|
+
// Fall back to legacy format (no transport frame)
|
|
21475
21714
|
const payload = InPageConnector.coercePayload(busMessage.payload);
|
|
21476
21715
|
if (!payload) {
|
|
21477
21716
|
logger$J.debug('inpage_payload_rejected', {
|
|
@@ -21512,6 +21751,92 @@ class InPageConnector extends BaseAsyncConnector {
|
|
|
21512
21751
|
};
|
|
21513
21752
|
getSharedBus$1().addEventListener(this.channelName, this.onMsg);
|
|
21514
21753
|
this.listenerRegistered = true;
|
|
21754
|
+
// Setup visibility change monitoring
|
|
21755
|
+
this.visibilityChangeHandler = () => {
|
|
21756
|
+
const isHidden = document.hidden;
|
|
21757
|
+
logger$J.debug('inpage_visibility_changed', {
|
|
21758
|
+
channel: this.channelName,
|
|
21759
|
+
connector_id: this.connectorId,
|
|
21760
|
+
visibility: isHidden ? 'hidden' : 'visible',
|
|
21761
|
+
timestamp: new Date().toISOString(),
|
|
21762
|
+
});
|
|
21763
|
+
// Pause/resume connector based on visibility
|
|
21764
|
+
if (isHidden && this.state === ConnectorState.STARTED) {
|
|
21765
|
+
this.pause().catch((err) => {
|
|
21766
|
+
logger$J.warning('inpage_pause_failed', {
|
|
21767
|
+
channel: this.channelName,
|
|
21768
|
+
connector_id: this.connectorId,
|
|
21769
|
+
error: err instanceof Error ? err.message : String(err),
|
|
21770
|
+
});
|
|
21771
|
+
});
|
|
21772
|
+
}
|
|
21773
|
+
else if (!isHidden && this.state === ConnectorState.PAUSED) {
|
|
21774
|
+
this.resume().catch((err) => {
|
|
21775
|
+
logger$J.warning('inpage_resume_failed', {
|
|
21776
|
+
channel: this.channelName,
|
|
21777
|
+
connector_id: this.connectorId,
|
|
21778
|
+
error: err instanceof Error ? err.message : String(err),
|
|
21779
|
+
});
|
|
21780
|
+
});
|
|
21781
|
+
}
|
|
21782
|
+
};
|
|
21783
|
+
if (typeof document !== 'undefined') {
|
|
21784
|
+
document.addEventListener('visibilitychange', this.visibilityChangeHandler);
|
|
21785
|
+
this.visibilityChangeListenerRegistered = true;
|
|
21786
|
+
// Track page lifecycle events to detect browser unload/discard
|
|
21787
|
+
if (typeof window !== 'undefined') {
|
|
21788
|
+
const lifecycleLogger = (event) => {
|
|
21789
|
+
logger$J.info('inpage_page_lifecycle', {
|
|
21790
|
+
channel: this.channelName,
|
|
21791
|
+
connector_id: this.connectorId,
|
|
21792
|
+
event_type: event.type,
|
|
21793
|
+
visibility_state: document.visibilityState,
|
|
21794
|
+
timestamp: new Date().toISOString(),
|
|
21795
|
+
});
|
|
21796
|
+
};
|
|
21797
|
+
window.addEventListener('beforeunload', lifecycleLogger);
|
|
21798
|
+
window.addEventListener('unload', lifecycleLogger);
|
|
21799
|
+
window.addEventListener('pagehide', lifecycleLogger);
|
|
21800
|
+
window.addEventListener('pageshow', lifecycleLogger);
|
|
21801
|
+
document.addEventListener('freeze', lifecycleLogger);
|
|
21802
|
+
document.addEventListener('resume', lifecycleLogger);
|
|
21803
|
+
}
|
|
21804
|
+
// Log initial state with detailed visibility info
|
|
21805
|
+
logger$J.debug('inpage_initial_visibility', {
|
|
21806
|
+
channel: this.channelName,
|
|
21807
|
+
connector_id: this.connectorId,
|
|
21808
|
+
visibility: document.hidden ? 'hidden' : 'visible',
|
|
21809
|
+
document_hidden: document.hidden,
|
|
21810
|
+
visibility_state: document.visibilityState,
|
|
21811
|
+
has_focus: document.hasFocus(),
|
|
21812
|
+
timestamp: new Date().toISOString(),
|
|
21813
|
+
});
|
|
21814
|
+
}
|
|
21815
|
+
}
|
|
21816
|
+
/**
|
|
21817
|
+
* Override start() to check initial visibility state
|
|
21818
|
+
*/
|
|
21819
|
+
async start(inboundHandler) {
|
|
21820
|
+
await super.start(inboundHandler);
|
|
21821
|
+
// After transitioning to STARTED, check if tab is already hidden
|
|
21822
|
+
if (typeof document !== 'undefined' && document.hidden) {
|
|
21823
|
+
logger$J.debug('inpage_start_in_hidden_tab', {
|
|
21824
|
+
channel: this.channelName,
|
|
21825
|
+
connector_id: this.connectorId,
|
|
21826
|
+
document_hidden: document.hidden,
|
|
21827
|
+
visibility_state: document.visibilityState,
|
|
21828
|
+
has_focus: document.hasFocus(),
|
|
21829
|
+
timestamp: new Date().toISOString(),
|
|
21830
|
+
});
|
|
21831
|
+
// Immediately pause if tab is hidden at start time
|
|
21832
|
+
await this.pause().catch((err) => {
|
|
21833
|
+
logger$J.warning('inpage_initial_pause_failed', {
|
|
21834
|
+
channel: this.channelName,
|
|
21835
|
+
connector_id: this.connectorId,
|
|
21836
|
+
error: err instanceof Error ? err.message : String(err),
|
|
21837
|
+
});
|
|
21838
|
+
});
|
|
21839
|
+
}
|
|
21515
21840
|
}
|
|
21516
21841
|
// Allow listeners to feed envelopes directly into the in-page receive queue.
|
|
21517
21842
|
async pushToReceive(rawOrEnvelope) {
|
|
@@ -21544,11 +21869,27 @@ class InPageConnector extends BaseAsyncConnector {
|
|
|
21544
21869
|
logger$J.debug('inpage_message_sending', {
|
|
21545
21870
|
channel: this.channelName,
|
|
21546
21871
|
sender_id: this.connectorId,
|
|
21547
|
-
|
|
21872
|
+
local_node_id: this.localNodeId,
|
|
21873
|
+
remote_node_id: this.remoteNodeId,
|
|
21874
|
+
});
|
|
21875
|
+
// Only use transport framing if both localNodeId and remoteNodeId are explicitly set
|
|
21876
|
+
// (not using default values). This ensures backwards compatibility.
|
|
21877
|
+
const useTransportFrame = this.localNodeId !== this.connectorId ||
|
|
21878
|
+
this.remoteNodeId !== '*';
|
|
21879
|
+
let payload;
|
|
21880
|
+
if (useTransportFrame) {
|
|
21881
|
+
// Wrap payload in transport frame
|
|
21882
|
+
const frame = wrapTransportFrame(data, this.localNodeId, this.remoteNodeId);
|
|
21883
|
+
payload = serializeTransportFrame(frame);
|
|
21884
|
+
}
|
|
21885
|
+
else {
|
|
21886
|
+
// Legacy format: send raw payload
|
|
21887
|
+
payload = data;
|
|
21888
|
+
}
|
|
21548
21889
|
const event = new MessageEvent(this.channelName, {
|
|
21549
21890
|
data: {
|
|
21550
21891
|
senderId: this.connectorId,
|
|
21551
|
-
payload
|
|
21892
|
+
payload,
|
|
21552
21893
|
},
|
|
21553
21894
|
});
|
|
21554
21895
|
getSharedBus$1().dispatchEvent(event);
|
|
@@ -21561,6 +21902,11 @@ class InPageConnector extends BaseAsyncConnector {
|
|
|
21561
21902
|
getSharedBus$1().removeEventListener(this.channelName, this.onMsg);
|
|
21562
21903
|
this.listenerRegistered = false;
|
|
21563
21904
|
}
|
|
21905
|
+
if (this.visibilityChangeListenerRegistered && this.visibilityChangeHandler && typeof document !== 'undefined') {
|
|
21906
|
+
document.removeEventListener('visibilitychange', this.visibilityChangeHandler);
|
|
21907
|
+
this.visibilityChangeListenerRegistered = false;
|
|
21908
|
+
this.visibilityChangeHandler = undefined;
|
|
21909
|
+
}
|
|
21564
21910
|
const closeCode = typeof code === 'number' ? code : 1000;
|
|
21565
21911
|
const closeReason = typeof reason === 'string' && reason.length > 0 ? reason : 'closed';
|
|
21566
21912
|
const shutdownError = new FameTransportClose(closeReason, closeCode);
|
|
@@ -28855,6 +29201,14 @@ function isInPageConnectionGrant(candidate) {
|
|
|
28855
29201
|
record.inboxCapacity <= 0)) {
|
|
28856
29202
|
return false;
|
|
28857
29203
|
}
|
|
29204
|
+
if (record.localNodeId !== undefined &&
|
|
29205
|
+
(typeof record.localNodeId !== 'string' || record.localNodeId.length === 0)) {
|
|
29206
|
+
return false;
|
|
29207
|
+
}
|
|
29208
|
+
if (record.remoteNodeId !== undefined &&
|
|
29209
|
+
(typeof record.remoteNodeId !== 'string' || record.remoteNodeId.length === 0)) {
|
|
29210
|
+
return false;
|
|
29211
|
+
}
|
|
28858
29212
|
return true;
|
|
28859
29213
|
}
|
|
28860
29214
|
function normalizeInPageConnectionGrant(candidate) {
|
|
@@ -28888,6 +29242,20 @@ function normalizeInPageConnectionGrant(candidate) {
|
|
|
28888
29242
|
}
|
|
28889
29243
|
result.inboxCapacity = Math.floor(inboxValue);
|
|
28890
29244
|
}
|
|
29245
|
+
const localNodeIdValue = candidate.localNodeId ?? candidate['local_node_id'];
|
|
29246
|
+
if (localNodeIdValue !== undefined) {
|
|
29247
|
+
if (typeof localNodeIdValue !== 'string' || localNodeIdValue.trim().length === 0) {
|
|
29248
|
+
throw new TypeError('InPageConnectionGrant "localNodeId" must be a non-empty string when provided');
|
|
29249
|
+
}
|
|
29250
|
+
result.localNodeId = localNodeIdValue.trim();
|
|
29251
|
+
}
|
|
29252
|
+
const remoteNodeIdValue = candidate.remoteNodeId ?? candidate['remote_node_id'];
|
|
29253
|
+
if (remoteNodeIdValue !== undefined) {
|
|
29254
|
+
if (typeof remoteNodeIdValue !== 'string' || remoteNodeIdValue.trim().length === 0) {
|
|
29255
|
+
throw new TypeError('InPageConnectionGrant "remoteNodeId" must be a non-empty string when provided');
|
|
29256
|
+
}
|
|
29257
|
+
result.remoteNodeId = remoteNodeIdValue.trim();
|
|
29258
|
+
}
|
|
28891
29259
|
return result;
|
|
28892
29260
|
}
|
|
28893
29261
|
function inPageGrantToConnectorConfig(grant) {
|
|
@@ -28901,6 +29269,12 @@ function inPageGrantToConnectorConfig(grant) {
|
|
|
28901
29269
|
if (normalized.inboxCapacity !== undefined) {
|
|
28902
29270
|
config.inboxCapacity = normalized.inboxCapacity;
|
|
28903
29271
|
}
|
|
29272
|
+
if (normalized.localNodeId) {
|
|
29273
|
+
config.localNodeId = normalized.localNodeId;
|
|
29274
|
+
}
|
|
29275
|
+
if (normalized.remoteNodeId) {
|
|
29276
|
+
config.remoteNodeId = normalized.remoteNodeId;
|
|
29277
|
+
}
|
|
28904
29278
|
return config;
|
|
28905
29279
|
}
|
|
28906
29280
|
|
|
@@ -30168,6 +30542,8 @@ class InPageConnectorFactory extends ConnectorFactory {
|
|
|
30168
30542
|
type: INPAGE_CONNECTOR_TYPE,
|
|
30169
30543
|
channelName,
|
|
30170
30544
|
inboxCapacity,
|
|
30545
|
+
localNodeId: normalized.localNodeId,
|
|
30546
|
+
remoteNodeId: normalized.remoteNodeId,
|
|
30171
30547
|
};
|
|
30172
30548
|
const connector = new InPageConnector(connectorConfig, baseConfig);
|
|
30173
30549
|
if (options.authorization) {
|
|
@@ -30236,6 +30612,16 @@ class InPageConnectorFactory extends ConnectorFactory {
|
|
|
30236
30612
|
if (candidate.authorizationContext !== undefined) {
|
|
30237
30613
|
normalized.authorizationContext = candidate.authorizationContext;
|
|
30238
30614
|
}
|
|
30615
|
+
// Handle localNodeId
|
|
30616
|
+
const localNodeId = candidate.localNodeId ?? candidate['local_node_id'];
|
|
30617
|
+
if (typeof localNodeId === 'string' && localNodeId.trim().length > 0) {
|
|
30618
|
+
normalized.localNodeId = localNodeId.trim();
|
|
30619
|
+
}
|
|
30620
|
+
// Handle remoteNodeId
|
|
30621
|
+
const remoteNodeId = candidate.remoteNodeId ?? candidate['remote_node_id'];
|
|
30622
|
+
if (typeof remoteNodeId === 'string' && remoteNodeId.trim().length > 0) {
|
|
30623
|
+
normalized.remoteNodeId = remoteNodeId.trim();
|
|
30624
|
+
}
|
|
30239
30625
|
normalized.channelName = normalized.channelName ?? DEFAULT_CHANNEL$3;
|
|
30240
30626
|
normalized.inboxCapacity =
|
|
30241
30627
|
normalized.inboxCapacity ?? DEFAULT_INBOX_CAPACITY$3;
|
|
@@ -30335,6 +30721,8 @@ class BroadcastChannelConnectorFactory extends ConnectorFactory {
|
|
|
30335
30721
|
type: BROADCAST_CHANNEL_CONNECTOR_TYPE$1,
|
|
30336
30722
|
channelName,
|
|
30337
30723
|
inboxCapacity,
|
|
30724
|
+
localNodeId: normalized.localNodeId,
|
|
30725
|
+
remoteNodeId: normalized.remoteNodeId,
|
|
30338
30726
|
};
|
|
30339
30727
|
const connector = new BroadcastChannelConnector(connectorConfig, baseConfig);
|
|
30340
30728
|
if (options.authorization) {
|
|
@@ -30396,6 +30784,16 @@ class BroadcastChannelConnectorFactory extends ConnectorFactory {
|
|
|
30396
30784
|
if (candidate.authorizationContext !== undefined) {
|
|
30397
30785
|
normalized.authorizationContext = candidate.authorizationContext;
|
|
30398
30786
|
}
|
|
30787
|
+
// Handle localNodeId
|
|
30788
|
+
const localNodeId = candidate.localNodeId ?? candidate['local_node_id'];
|
|
30789
|
+
if (typeof localNodeId === 'string' && localNodeId.trim().length > 0) {
|
|
30790
|
+
normalized.localNodeId = localNodeId.trim();
|
|
30791
|
+
}
|
|
30792
|
+
// Handle remoteNodeId
|
|
30793
|
+
const remoteNodeId = candidate.remoteNodeId ?? candidate['remote_node_id'];
|
|
30794
|
+
if (typeof remoteNodeId === 'string' && remoteNodeId.trim().length > 0) {
|
|
30795
|
+
normalized.remoteNodeId = remoteNodeId.trim();
|
|
30796
|
+
}
|
|
30399
30797
|
normalized.channelName = normalized.channelName ?? DEFAULT_CHANNEL$2;
|
|
30400
30798
|
normalized.inboxCapacity =
|
|
30401
30799
|
normalized.inboxCapacity ?? DEFAULT_INBOX_CAPACITY$2;
|
|
@@ -7,6 +7,8 @@ export interface BroadcastChannelConnectorFactoryConfig extends ConnectorConfig,
|
|
|
7
7
|
type: typeof BROADCAST_CHANNEL_CONNECTOR_TYPE;
|
|
8
8
|
channelName?: string;
|
|
9
9
|
inboxCapacity?: number;
|
|
10
|
+
localNodeId?: string;
|
|
11
|
+
remoteNodeId?: string;
|
|
10
12
|
}
|
|
11
13
|
export interface CreateBroadcastChannelConnectorOptions {
|
|
12
14
|
authorization?: AuthorizationContext;
|
|
@@ -6,6 +6,8 @@ export interface BroadcastChannelConnectorConfig extends ConnectorConfig {
|
|
|
6
6
|
type: typeof BROADCAST_CHANNEL_CONNECTOR_TYPE;
|
|
7
7
|
channelName?: string;
|
|
8
8
|
inboxCapacity?: number;
|
|
9
|
+
localNodeId?: string;
|
|
10
|
+
remoteNodeId?: string;
|
|
9
11
|
}
|
|
10
12
|
type BroadcastChannelInboxItem = Uint8Array | FameEnvelope | FameChannelMessage;
|
|
11
13
|
export declare class BroadcastChannelConnector extends BaseAsyncConnector {
|
|
@@ -22,6 +24,8 @@ export declare class BroadcastChannelConnector extends BaseAsyncConnector {
|
|
|
22
24
|
private readonly textDecoder;
|
|
23
25
|
private visibilityChangeListenerRegistered;
|
|
24
26
|
private visibilityChangeHandler?;
|
|
27
|
+
private readonly localNodeId;
|
|
28
|
+
private readonly remoteNodeId;
|
|
25
29
|
private static generateConnectorId;
|
|
26
30
|
private static coercePayload;
|
|
27
31
|
constructor(config: BroadcastChannelConnectorConfig, baseConfig?: BaseAsyncConnectorConfig);
|
|
@@ -9,6 +9,8 @@ export interface InPageConnectorFactoryConfig extends ConnectorConfig, Partial<B
|
|
|
9
9
|
type: typeof INPAGE_CONNECTOR_TYPE;
|
|
10
10
|
channelName?: string;
|
|
11
11
|
inboxCapacity?: number;
|
|
12
|
+
localNodeId?: string;
|
|
13
|
+
remoteNodeId?: string;
|
|
12
14
|
}
|
|
13
15
|
export interface CreateInPageConnectorOptions {
|
|
14
16
|
systemId?: string;
|
|
@@ -4,12 +4,14 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { BaseAsyncConnector, type BaseAsyncConnectorConfig } from './base-async-connector.js';
|
|
6
6
|
import type { ConnectorConfig } from './connector-config.js';
|
|
7
|
-
import type { FameEnvelope, FameChannelMessage } from '@naylence/core';
|
|
7
|
+
import type { FameEnvelope, FameChannelMessage, FameEnvelopeHandler } from '@naylence/core';
|
|
8
8
|
export declare const INPAGE_CONNECTOR_TYPE: "inpage-connector";
|
|
9
9
|
export interface InPageConnectorConfig extends ConnectorConfig {
|
|
10
10
|
type: typeof INPAGE_CONNECTOR_TYPE;
|
|
11
11
|
channelName?: string;
|
|
12
12
|
inboxCapacity?: number;
|
|
13
|
+
localNodeId?: string;
|
|
14
|
+
remoteNodeId?: string;
|
|
13
15
|
}
|
|
14
16
|
type InPageInboxItem = Uint8Array | FameEnvelope | FameChannelMessage;
|
|
15
17
|
export declare class InPageConnector extends BaseAsyncConnector {
|
|
@@ -18,9 +20,17 @@ export declare class InPageConnector extends BaseAsyncConnector {
|
|
|
18
20
|
private listenerRegistered;
|
|
19
21
|
private readonly connectorId;
|
|
20
22
|
private readonly onMsg;
|
|
23
|
+
private visibilityChangeListenerRegistered;
|
|
24
|
+
private visibilityChangeHandler?;
|
|
25
|
+
private readonly localNodeId;
|
|
26
|
+
private readonly remoteNodeId;
|
|
21
27
|
private static generateConnectorId;
|
|
22
28
|
private static coercePayload;
|
|
23
29
|
constructor(config: InPageConnectorConfig, baseConfig?: BaseAsyncConnectorConfig);
|
|
30
|
+
/**
|
|
31
|
+
* Override start() to check initial visibility state
|
|
32
|
+
*/
|
|
33
|
+
start(inboundHandler: FameEnvelopeHandler): Promise<void>;
|
|
24
34
|
pushToReceive(rawOrEnvelope: Uint8Array | FameEnvelope | FameChannelMessage): Promise<void>;
|
|
25
35
|
protected _transportSendBytes(data: Uint8Array): Promise<void>;
|
|
26
36
|
protected _transportReceive(): Promise<InPageInboxItem>;
|