@naylence/runtime 0.3.5-test.940 → 0.3.5-test.942
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 +115 -4
- package/dist/browser/index.mjs +115 -4
- package/dist/cjs/naylence/fame/connector/broadcast-channel-connector.browser.js +19 -0
- package/dist/cjs/naylence/fame/connector/inpage-connector.js +93 -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.browser.js +19 -0
- package/dist/esm/naylence/fame/connector/inpage-connector.js +93 -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 +115 -4
- package/dist/node/index.mjs +115 -4
- package/dist/node/node.cjs +115 -4
- package/dist/node/node.mjs +115 -4
- package/dist/types/naylence/fame/connector/inpage-connector.d.ts +7 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -1
package/dist/browser/index.cjs
CHANGED
|
@@ -98,12 +98,12 @@ installProcessEnvShim();
|
|
|
98
98
|
// --- END ENV SHIM ---
|
|
99
99
|
|
|
100
100
|
// This file is auto-generated during build - do not edit manually
|
|
101
|
-
// Generated from package.json version: 0.3.5-test.
|
|
101
|
+
// Generated from package.json version: 0.3.5-test.942
|
|
102
102
|
/**
|
|
103
103
|
* The package version, injected at build time.
|
|
104
104
|
* @internal
|
|
105
105
|
*/
|
|
106
|
-
const VERSION = '0.3.5-test.
|
|
106
|
+
const VERSION = '0.3.5-test.942';
|
|
107
107
|
|
|
108
108
|
/**
|
|
109
109
|
* Fame protocol specific error classes with WebSocket close codes and proper inheritance.
|
|
@@ -9993,6 +9993,24 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
|
|
|
9993
9993
|
if (typeof document !== 'undefined') {
|
|
9994
9994
|
document.addEventListener('visibilitychange', this.visibilityChangeHandler);
|
|
9995
9995
|
this.visibilityChangeListenerRegistered = true;
|
|
9996
|
+
// Track page lifecycle events to detect browser unload/discard
|
|
9997
|
+
if (typeof window !== 'undefined') {
|
|
9998
|
+
const lifecycleLogger = (event) => {
|
|
9999
|
+
logger$_.info('broadcast_channel_page_lifecycle', {
|
|
10000
|
+
channel: this.channelName,
|
|
10001
|
+
connector_id: this.connectorId,
|
|
10002
|
+
event_type: event.type,
|
|
10003
|
+
visibility_state: document.visibilityState,
|
|
10004
|
+
timestamp: new Date().toISOString(),
|
|
10005
|
+
});
|
|
10006
|
+
};
|
|
10007
|
+
window.addEventListener('beforeunload', lifecycleLogger);
|
|
10008
|
+
window.addEventListener('unload', lifecycleLogger);
|
|
10009
|
+
window.addEventListener('pagehide', lifecycleLogger);
|
|
10010
|
+
window.addEventListener('pageshow', lifecycleLogger);
|
|
10011
|
+
document.addEventListener('freeze', lifecycleLogger);
|
|
10012
|
+
document.addEventListener('resume', lifecycleLogger);
|
|
10013
|
+
}
|
|
9996
10014
|
// Log initial state with detailed visibility info
|
|
9997
10015
|
logger$_.debug('broadcast_channel_initial_visibility', {
|
|
9998
10016
|
channel: this.channelName,
|
|
@@ -10001,6 +10019,7 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
|
|
|
10001
10019
|
document_hidden: document.hidden,
|
|
10002
10020
|
visibility_state: document.visibilityState,
|
|
10003
10021
|
has_focus: document.hasFocus(),
|
|
10022
|
+
timestamp: new Date().toISOString(),
|
|
10004
10023
|
});
|
|
10005
10024
|
}
|
|
10006
10025
|
}
|
|
@@ -10758,7 +10777,7 @@ class UpstreamSessionManager extends TaskSpawner {
|
|
|
10758
10777
|
this.currentStopSubtasks = null;
|
|
10759
10778
|
await Promise.allSettled(tasks.map((task) => task.promise));
|
|
10760
10779
|
if (this.connector) {
|
|
10761
|
-
logger$Z.
|
|
10780
|
+
logger$Z.debug('upstream_stopping_old_connector', {
|
|
10762
10781
|
connect_epoch: this.connectEpoch,
|
|
10763
10782
|
target_system_id: this.targetSystemId,
|
|
10764
10783
|
timestamp: new Date().toISOString(),
|
|
@@ -10769,7 +10788,7 @@ class UpstreamSessionManager extends TaskSpawner {
|
|
|
10769
10788
|
error: err instanceof Error ? err.message : String(err),
|
|
10770
10789
|
});
|
|
10771
10790
|
});
|
|
10772
|
-
logger$Z.
|
|
10791
|
+
logger$Z.debug('upstream_old_connector_stopped', {
|
|
10773
10792
|
connect_epoch: this.connectEpoch,
|
|
10774
10793
|
target_system_id: this.targetSystemId,
|
|
10775
10794
|
timestamp: new Date().toISOString(),
|
|
@@ -20313,6 +20332,7 @@ class InPageConnector extends BaseAsyncConnector {
|
|
|
20313
20332
|
ensureBrowserEnvironment$2();
|
|
20314
20333
|
super(baseConfig);
|
|
20315
20334
|
this.listenerRegistered = false;
|
|
20335
|
+
this.visibilityChangeListenerRegistered = false;
|
|
20316
20336
|
this.channelName =
|
|
20317
20337
|
typeof config.channelName === 'string' && config.channelName.trim().length > 0
|
|
20318
20338
|
? config.channelName.trim()
|
|
@@ -20400,6 +20420,92 @@ class InPageConnector extends BaseAsyncConnector {
|
|
|
20400
20420
|
};
|
|
20401
20421
|
getSharedBus$1().addEventListener(this.channelName, this.onMsg);
|
|
20402
20422
|
this.listenerRegistered = true;
|
|
20423
|
+
// Setup visibility change monitoring
|
|
20424
|
+
this.visibilityChangeHandler = () => {
|
|
20425
|
+
const isHidden = document.hidden;
|
|
20426
|
+
logger$G.debug('inpage_visibility_changed', {
|
|
20427
|
+
channel: this.channelName,
|
|
20428
|
+
connector_id: this.connectorId,
|
|
20429
|
+
visibility: isHidden ? 'hidden' : 'visible',
|
|
20430
|
+
timestamp: new Date().toISOString(),
|
|
20431
|
+
});
|
|
20432
|
+
// Pause/resume connector based on visibility
|
|
20433
|
+
if (isHidden && this.state === core.ConnectorState.STARTED) {
|
|
20434
|
+
this.pause().catch((err) => {
|
|
20435
|
+
logger$G.warning('inpage_pause_failed', {
|
|
20436
|
+
channel: this.channelName,
|
|
20437
|
+
connector_id: this.connectorId,
|
|
20438
|
+
error: err instanceof Error ? err.message : String(err),
|
|
20439
|
+
});
|
|
20440
|
+
});
|
|
20441
|
+
}
|
|
20442
|
+
else if (!isHidden && this.state === core.ConnectorState.PAUSED) {
|
|
20443
|
+
this.resume().catch((err) => {
|
|
20444
|
+
logger$G.warning('inpage_resume_failed', {
|
|
20445
|
+
channel: this.channelName,
|
|
20446
|
+
connector_id: this.connectorId,
|
|
20447
|
+
error: err instanceof Error ? err.message : String(err),
|
|
20448
|
+
});
|
|
20449
|
+
});
|
|
20450
|
+
}
|
|
20451
|
+
};
|
|
20452
|
+
if (typeof document !== 'undefined') {
|
|
20453
|
+
document.addEventListener('visibilitychange', this.visibilityChangeHandler);
|
|
20454
|
+
this.visibilityChangeListenerRegistered = true;
|
|
20455
|
+
// Track page lifecycle events to detect browser unload/discard
|
|
20456
|
+
if (typeof window !== 'undefined') {
|
|
20457
|
+
const lifecycleLogger = (event) => {
|
|
20458
|
+
logger$G.info('inpage_page_lifecycle', {
|
|
20459
|
+
channel: this.channelName,
|
|
20460
|
+
connector_id: this.connectorId,
|
|
20461
|
+
event_type: event.type,
|
|
20462
|
+
visibility_state: document.visibilityState,
|
|
20463
|
+
timestamp: new Date().toISOString(),
|
|
20464
|
+
});
|
|
20465
|
+
};
|
|
20466
|
+
window.addEventListener('beforeunload', lifecycleLogger);
|
|
20467
|
+
window.addEventListener('unload', lifecycleLogger);
|
|
20468
|
+
window.addEventListener('pagehide', lifecycleLogger);
|
|
20469
|
+
window.addEventListener('pageshow', lifecycleLogger);
|
|
20470
|
+
document.addEventListener('freeze', lifecycleLogger);
|
|
20471
|
+
document.addEventListener('resume', lifecycleLogger);
|
|
20472
|
+
}
|
|
20473
|
+
// Log initial state with detailed visibility info
|
|
20474
|
+
logger$G.debug('inpage_initial_visibility', {
|
|
20475
|
+
channel: this.channelName,
|
|
20476
|
+
connector_id: this.connectorId,
|
|
20477
|
+
visibility: document.hidden ? 'hidden' : 'visible',
|
|
20478
|
+
document_hidden: document.hidden,
|
|
20479
|
+
visibility_state: document.visibilityState,
|
|
20480
|
+
has_focus: document.hasFocus(),
|
|
20481
|
+
timestamp: new Date().toISOString(),
|
|
20482
|
+
});
|
|
20483
|
+
}
|
|
20484
|
+
}
|
|
20485
|
+
/**
|
|
20486
|
+
* Override start() to check initial visibility state
|
|
20487
|
+
*/
|
|
20488
|
+
async start(inboundHandler) {
|
|
20489
|
+
await super.start(inboundHandler);
|
|
20490
|
+
// After transitioning to STARTED, check if tab is already hidden
|
|
20491
|
+
if (typeof document !== 'undefined' && document.hidden) {
|
|
20492
|
+
logger$G.debug('inpage_start_in_hidden_tab', {
|
|
20493
|
+
channel: this.channelName,
|
|
20494
|
+
connector_id: this.connectorId,
|
|
20495
|
+
document_hidden: document.hidden,
|
|
20496
|
+
visibility_state: document.visibilityState,
|
|
20497
|
+
has_focus: document.hasFocus(),
|
|
20498
|
+
timestamp: new Date().toISOString(),
|
|
20499
|
+
});
|
|
20500
|
+
// Immediately pause if tab is hidden at start time
|
|
20501
|
+
await this.pause().catch((err) => {
|
|
20502
|
+
logger$G.warning('inpage_initial_pause_failed', {
|
|
20503
|
+
channel: this.channelName,
|
|
20504
|
+
connector_id: this.connectorId,
|
|
20505
|
+
error: err instanceof Error ? err.message : String(err),
|
|
20506
|
+
});
|
|
20507
|
+
});
|
|
20508
|
+
}
|
|
20403
20509
|
}
|
|
20404
20510
|
// Allow listeners to feed envelopes directly into the in-page receive queue.
|
|
20405
20511
|
async pushToReceive(rawOrEnvelope) {
|
|
@@ -20449,6 +20555,11 @@ class InPageConnector extends BaseAsyncConnector {
|
|
|
20449
20555
|
getSharedBus$1().removeEventListener(this.channelName, this.onMsg);
|
|
20450
20556
|
this.listenerRegistered = false;
|
|
20451
20557
|
}
|
|
20558
|
+
if (this.visibilityChangeListenerRegistered && this.visibilityChangeHandler && typeof document !== 'undefined') {
|
|
20559
|
+
document.removeEventListener('visibilitychange', this.visibilityChangeHandler);
|
|
20560
|
+
this.visibilityChangeListenerRegistered = false;
|
|
20561
|
+
this.visibilityChangeHandler = undefined;
|
|
20562
|
+
}
|
|
20452
20563
|
const closeCode = typeof code === 'number' ? code : 1000;
|
|
20453
20564
|
const closeReason = typeof reason === 'string' && reason.length > 0 ? reason : 'closed';
|
|
20454
20565
|
const shutdownError = new FameTransportClose(closeReason, closeCode);
|
package/dist/browser/index.mjs
CHANGED
|
@@ -96,12 +96,12 @@ installProcessEnvShim();
|
|
|
96
96
|
// --- END ENV SHIM ---
|
|
97
97
|
|
|
98
98
|
// This file is auto-generated during build - do not edit manually
|
|
99
|
-
// Generated from package.json version: 0.3.5-test.
|
|
99
|
+
// Generated from package.json version: 0.3.5-test.942
|
|
100
100
|
/**
|
|
101
101
|
* The package version, injected at build time.
|
|
102
102
|
* @internal
|
|
103
103
|
*/
|
|
104
|
-
const VERSION = '0.3.5-test.
|
|
104
|
+
const VERSION = '0.3.5-test.942';
|
|
105
105
|
|
|
106
106
|
/**
|
|
107
107
|
* Fame protocol specific error classes with WebSocket close codes and proper inheritance.
|
|
@@ -9991,6 +9991,24 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
|
|
|
9991
9991
|
if (typeof document !== 'undefined') {
|
|
9992
9992
|
document.addEventListener('visibilitychange', this.visibilityChangeHandler);
|
|
9993
9993
|
this.visibilityChangeListenerRegistered = true;
|
|
9994
|
+
// Track page lifecycle events to detect browser unload/discard
|
|
9995
|
+
if (typeof window !== 'undefined') {
|
|
9996
|
+
const lifecycleLogger = (event) => {
|
|
9997
|
+
logger$_.info('broadcast_channel_page_lifecycle', {
|
|
9998
|
+
channel: this.channelName,
|
|
9999
|
+
connector_id: this.connectorId,
|
|
10000
|
+
event_type: event.type,
|
|
10001
|
+
visibility_state: document.visibilityState,
|
|
10002
|
+
timestamp: new Date().toISOString(),
|
|
10003
|
+
});
|
|
10004
|
+
};
|
|
10005
|
+
window.addEventListener('beforeunload', lifecycleLogger);
|
|
10006
|
+
window.addEventListener('unload', lifecycleLogger);
|
|
10007
|
+
window.addEventListener('pagehide', lifecycleLogger);
|
|
10008
|
+
window.addEventListener('pageshow', lifecycleLogger);
|
|
10009
|
+
document.addEventListener('freeze', lifecycleLogger);
|
|
10010
|
+
document.addEventListener('resume', lifecycleLogger);
|
|
10011
|
+
}
|
|
9994
10012
|
// Log initial state with detailed visibility info
|
|
9995
10013
|
logger$_.debug('broadcast_channel_initial_visibility', {
|
|
9996
10014
|
channel: this.channelName,
|
|
@@ -9999,6 +10017,7 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
|
|
|
9999
10017
|
document_hidden: document.hidden,
|
|
10000
10018
|
visibility_state: document.visibilityState,
|
|
10001
10019
|
has_focus: document.hasFocus(),
|
|
10020
|
+
timestamp: new Date().toISOString(),
|
|
10002
10021
|
});
|
|
10003
10022
|
}
|
|
10004
10023
|
}
|
|
@@ -10756,7 +10775,7 @@ class UpstreamSessionManager extends TaskSpawner {
|
|
|
10756
10775
|
this.currentStopSubtasks = null;
|
|
10757
10776
|
await Promise.allSettled(tasks.map((task) => task.promise));
|
|
10758
10777
|
if (this.connector) {
|
|
10759
|
-
logger$Z.
|
|
10778
|
+
logger$Z.debug('upstream_stopping_old_connector', {
|
|
10760
10779
|
connect_epoch: this.connectEpoch,
|
|
10761
10780
|
target_system_id: this.targetSystemId,
|
|
10762
10781
|
timestamp: new Date().toISOString(),
|
|
@@ -10767,7 +10786,7 @@ class UpstreamSessionManager extends TaskSpawner {
|
|
|
10767
10786
|
error: err instanceof Error ? err.message : String(err),
|
|
10768
10787
|
});
|
|
10769
10788
|
});
|
|
10770
|
-
logger$Z.
|
|
10789
|
+
logger$Z.debug('upstream_old_connector_stopped', {
|
|
10771
10790
|
connect_epoch: this.connectEpoch,
|
|
10772
10791
|
target_system_id: this.targetSystemId,
|
|
10773
10792
|
timestamp: new Date().toISOString(),
|
|
@@ -20311,6 +20330,7 @@ class InPageConnector extends BaseAsyncConnector {
|
|
|
20311
20330
|
ensureBrowserEnvironment$2();
|
|
20312
20331
|
super(baseConfig);
|
|
20313
20332
|
this.listenerRegistered = false;
|
|
20333
|
+
this.visibilityChangeListenerRegistered = false;
|
|
20314
20334
|
this.channelName =
|
|
20315
20335
|
typeof config.channelName === 'string' && config.channelName.trim().length > 0
|
|
20316
20336
|
? config.channelName.trim()
|
|
@@ -20398,6 +20418,92 @@ class InPageConnector extends BaseAsyncConnector {
|
|
|
20398
20418
|
};
|
|
20399
20419
|
getSharedBus$1().addEventListener(this.channelName, this.onMsg);
|
|
20400
20420
|
this.listenerRegistered = true;
|
|
20421
|
+
// Setup visibility change monitoring
|
|
20422
|
+
this.visibilityChangeHandler = () => {
|
|
20423
|
+
const isHidden = document.hidden;
|
|
20424
|
+
logger$G.debug('inpage_visibility_changed', {
|
|
20425
|
+
channel: this.channelName,
|
|
20426
|
+
connector_id: this.connectorId,
|
|
20427
|
+
visibility: isHidden ? 'hidden' : 'visible',
|
|
20428
|
+
timestamp: new Date().toISOString(),
|
|
20429
|
+
});
|
|
20430
|
+
// Pause/resume connector based on visibility
|
|
20431
|
+
if (isHidden && this.state === ConnectorState.STARTED) {
|
|
20432
|
+
this.pause().catch((err) => {
|
|
20433
|
+
logger$G.warning('inpage_pause_failed', {
|
|
20434
|
+
channel: this.channelName,
|
|
20435
|
+
connector_id: this.connectorId,
|
|
20436
|
+
error: err instanceof Error ? err.message : String(err),
|
|
20437
|
+
});
|
|
20438
|
+
});
|
|
20439
|
+
}
|
|
20440
|
+
else if (!isHidden && this.state === ConnectorState.PAUSED) {
|
|
20441
|
+
this.resume().catch((err) => {
|
|
20442
|
+
logger$G.warning('inpage_resume_failed', {
|
|
20443
|
+
channel: this.channelName,
|
|
20444
|
+
connector_id: this.connectorId,
|
|
20445
|
+
error: err instanceof Error ? err.message : String(err),
|
|
20446
|
+
});
|
|
20447
|
+
});
|
|
20448
|
+
}
|
|
20449
|
+
};
|
|
20450
|
+
if (typeof document !== 'undefined') {
|
|
20451
|
+
document.addEventListener('visibilitychange', this.visibilityChangeHandler);
|
|
20452
|
+
this.visibilityChangeListenerRegistered = true;
|
|
20453
|
+
// Track page lifecycle events to detect browser unload/discard
|
|
20454
|
+
if (typeof window !== 'undefined') {
|
|
20455
|
+
const lifecycleLogger = (event) => {
|
|
20456
|
+
logger$G.info('inpage_page_lifecycle', {
|
|
20457
|
+
channel: this.channelName,
|
|
20458
|
+
connector_id: this.connectorId,
|
|
20459
|
+
event_type: event.type,
|
|
20460
|
+
visibility_state: document.visibilityState,
|
|
20461
|
+
timestamp: new Date().toISOString(),
|
|
20462
|
+
});
|
|
20463
|
+
};
|
|
20464
|
+
window.addEventListener('beforeunload', lifecycleLogger);
|
|
20465
|
+
window.addEventListener('unload', lifecycleLogger);
|
|
20466
|
+
window.addEventListener('pagehide', lifecycleLogger);
|
|
20467
|
+
window.addEventListener('pageshow', lifecycleLogger);
|
|
20468
|
+
document.addEventListener('freeze', lifecycleLogger);
|
|
20469
|
+
document.addEventListener('resume', lifecycleLogger);
|
|
20470
|
+
}
|
|
20471
|
+
// Log initial state with detailed visibility info
|
|
20472
|
+
logger$G.debug('inpage_initial_visibility', {
|
|
20473
|
+
channel: this.channelName,
|
|
20474
|
+
connector_id: this.connectorId,
|
|
20475
|
+
visibility: document.hidden ? 'hidden' : 'visible',
|
|
20476
|
+
document_hidden: document.hidden,
|
|
20477
|
+
visibility_state: document.visibilityState,
|
|
20478
|
+
has_focus: document.hasFocus(),
|
|
20479
|
+
timestamp: new Date().toISOString(),
|
|
20480
|
+
});
|
|
20481
|
+
}
|
|
20482
|
+
}
|
|
20483
|
+
/**
|
|
20484
|
+
* Override start() to check initial visibility state
|
|
20485
|
+
*/
|
|
20486
|
+
async start(inboundHandler) {
|
|
20487
|
+
await super.start(inboundHandler);
|
|
20488
|
+
// After transitioning to STARTED, check if tab is already hidden
|
|
20489
|
+
if (typeof document !== 'undefined' && document.hidden) {
|
|
20490
|
+
logger$G.debug('inpage_start_in_hidden_tab', {
|
|
20491
|
+
channel: this.channelName,
|
|
20492
|
+
connector_id: this.connectorId,
|
|
20493
|
+
document_hidden: document.hidden,
|
|
20494
|
+
visibility_state: document.visibilityState,
|
|
20495
|
+
has_focus: document.hasFocus(),
|
|
20496
|
+
timestamp: new Date().toISOString(),
|
|
20497
|
+
});
|
|
20498
|
+
// Immediately pause if tab is hidden at start time
|
|
20499
|
+
await this.pause().catch((err) => {
|
|
20500
|
+
logger$G.warning('inpage_initial_pause_failed', {
|
|
20501
|
+
channel: this.channelName,
|
|
20502
|
+
connector_id: this.connectorId,
|
|
20503
|
+
error: err instanceof Error ? err.message : String(err),
|
|
20504
|
+
});
|
|
20505
|
+
});
|
|
20506
|
+
}
|
|
20401
20507
|
}
|
|
20402
20508
|
// Allow listeners to feed envelopes directly into the in-page receive queue.
|
|
20403
20509
|
async pushToReceive(rawOrEnvelope) {
|
|
@@ -20447,6 +20553,11 @@ class InPageConnector extends BaseAsyncConnector {
|
|
|
20447
20553
|
getSharedBus$1().removeEventListener(this.channelName, this.onMsg);
|
|
20448
20554
|
this.listenerRegistered = false;
|
|
20449
20555
|
}
|
|
20556
|
+
if (this.visibilityChangeListenerRegistered && this.visibilityChangeHandler && typeof document !== 'undefined') {
|
|
20557
|
+
document.removeEventListener('visibilitychange', this.visibilityChangeHandler);
|
|
20558
|
+
this.visibilityChangeListenerRegistered = false;
|
|
20559
|
+
this.visibilityChangeHandler = undefined;
|
|
20560
|
+
}
|
|
20450
20561
|
const closeCode = typeof code === 'number' ? code : 1000;
|
|
20451
20562
|
const closeReason = typeof reason === 'string' && reason.length > 0 ? reason : 'closed';
|
|
20452
20563
|
const shutdownError = new FameTransportClose(closeReason, closeCode);
|
|
@@ -181,6 +181,24 @@ class BroadcastChannelConnector extends base_async_connector_js_1.BaseAsyncConne
|
|
|
181
181
|
if (typeof document !== 'undefined') {
|
|
182
182
|
document.addEventListener('visibilitychange', this.visibilityChangeHandler);
|
|
183
183
|
this.visibilityChangeListenerRegistered = true;
|
|
184
|
+
// Track page lifecycle events to detect browser unload/discard
|
|
185
|
+
if (typeof window !== 'undefined') {
|
|
186
|
+
const lifecycleLogger = (event) => {
|
|
187
|
+
logger.info('broadcast_channel_page_lifecycle', {
|
|
188
|
+
channel: this.channelName,
|
|
189
|
+
connector_id: this.connectorId,
|
|
190
|
+
event_type: event.type,
|
|
191
|
+
visibility_state: document.visibilityState,
|
|
192
|
+
timestamp: new Date().toISOString(),
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
window.addEventListener('beforeunload', lifecycleLogger);
|
|
196
|
+
window.addEventListener('unload', lifecycleLogger);
|
|
197
|
+
window.addEventListener('pagehide', lifecycleLogger);
|
|
198
|
+
window.addEventListener('pageshow', lifecycleLogger);
|
|
199
|
+
document.addEventListener('freeze', lifecycleLogger);
|
|
200
|
+
document.addEventListener('resume', lifecycleLogger);
|
|
201
|
+
}
|
|
184
202
|
// Log initial state with detailed visibility info
|
|
185
203
|
logger.debug('broadcast_channel_initial_visibility', {
|
|
186
204
|
channel: this.channelName,
|
|
@@ -189,6 +207,7 @@ class BroadcastChannelConnector extends base_async_connector_js_1.BaseAsyncConne
|
|
|
189
207
|
document_hidden: document.hidden,
|
|
190
208
|
visibility_state: document.visibilityState,
|
|
191
209
|
has_focus: document.hasFocus(),
|
|
210
|
+
timestamp: new Date().toISOString(),
|
|
192
211
|
});
|
|
193
212
|
}
|
|
194
213
|
}
|
|
@@ -9,6 +9,7 @@ const base_async_connector_js_1 = require("./base-async-connector.js");
|
|
|
9
9
|
const errors_js_1 = require("../errors/errors.js");
|
|
10
10
|
const logging_js_1 = require("../util/logging.js");
|
|
11
11
|
const bounded_async_queue_js_1 = require("../util/bounded-async-queue.js");
|
|
12
|
+
const core_1 = require("@naylence/core");
|
|
12
13
|
const logger = (0, logging_js_1.getLogger)('naylence.fame.connector.inpage_connector');
|
|
13
14
|
exports.INPAGE_CONNECTOR_TYPE = 'inpage-connector';
|
|
14
15
|
const DEFAULT_CHANNEL = 'naylence-fabric';
|
|
@@ -67,6 +68,7 @@ class InPageConnector extends base_async_connector_js_1.BaseAsyncConnector {
|
|
|
67
68
|
ensureBrowserEnvironment();
|
|
68
69
|
super(baseConfig);
|
|
69
70
|
this.listenerRegistered = false;
|
|
71
|
+
this.visibilityChangeListenerRegistered = false;
|
|
70
72
|
this.channelName =
|
|
71
73
|
typeof config.channelName === 'string' && config.channelName.trim().length > 0
|
|
72
74
|
? config.channelName.trim()
|
|
@@ -154,6 +156,92 @@ class InPageConnector extends base_async_connector_js_1.BaseAsyncConnector {
|
|
|
154
156
|
};
|
|
155
157
|
getSharedBus().addEventListener(this.channelName, this.onMsg);
|
|
156
158
|
this.listenerRegistered = true;
|
|
159
|
+
// Setup visibility change monitoring
|
|
160
|
+
this.visibilityChangeHandler = () => {
|
|
161
|
+
const isHidden = document.hidden;
|
|
162
|
+
logger.debug('inpage_visibility_changed', {
|
|
163
|
+
channel: this.channelName,
|
|
164
|
+
connector_id: this.connectorId,
|
|
165
|
+
visibility: isHidden ? 'hidden' : 'visible',
|
|
166
|
+
timestamp: new Date().toISOString(),
|
|
167
|
+
});
|
|
168
|
+
// Pause/resume connector based on visibility
|
|
169
|
+
if (isHidden && this.state === core_1.ConnectorState.STARTED) {
|
|
170
|
+
this.pause().catch((err) => {
|
|
171
|
+
logger.warning('inpage_pause_failed', {
|
|
172
|
+
channel: this.channelName,
|
|
173
|
+
connector_id: this.connectorId,
|
|
174
|
+
error: err instanceof Error ? err.message : String(err),
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
else if (!isHidden && this.state === core_1.ConnectorState.PAUSED) {
|
|
179
|
+
this.resume().catch((err) => {
|
|
180
|
+
logger.warning('inpage_resume_failed', {
|
|
181
|
+
channel: this.channelName,
|
|
182
|
+
connector_id: this.connectorId,
|
|
183
|
+
error: err instanceof Error ? err.message : String(err),
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
if (typeof document !== 'undefined') {
|
|
189
|
+
document.addEventListener('visibilitychange', this.visibilityChangeHandler);
|
|
190
|
+
this.visibilityChangeListenerRegistered = true;
|
|
191
|
+
// Track page lifecycle events to detect browser unload/discard
|
|
192
|
+
if (typeof window !== 'undefined') {
|
|
193
|
+
const lifecycleLogger = (event) => {
|
|
194
|
+
logger.info('inpage_page_lifecycle', {
|
|
195
|
+
channel: this.channelName,
|
|
196
|
+
connector_id: this.connectorId,
|
|
197
|
+
event_type: event.type,
|
|
198
|
+
visibility_state: document.visibilityState,
|
|
199
|
+
timestamp: new Date().toISOString(),
|
|
200
|
+
});
|
|
201
|
+
};
|
|
202
|
+
window.addEventListener('beforeunload', lifecycleLogger);
|
|
203
|
+
window.addEventListener('unload', lifecycleLogger);
|
|
204
|
+
window.addEventListener('pagehide', lifecycleLogger);
|
|
205
|
+
window.addEventListener('pageshow', lifecycleLogger);
|
|
206
|
+
document.addEventListener('freeze', lifecycleLogger);
|
|
207
|
+
document.addEventListener('resume', lifecycleLogger);
|
|
208
|
+
}
|
|
209
|
+
// Log initial state with detailed visibility info
|
|
210
|
+
logger.debug('inpage_initial_visibility', {
|
|
211
|
+
channel: this.channelName,
|
|
212
|
+
connector_id: this.connectorId,
|
|
213
|
+
visibility: document.hidden ? 'hidden' : 'visible',
|
|
214
|
+
document_hidden: document.hidden,
|
|
215
|
+
visibility_state: document.visibilityState,
|
|
216
|
+
has_focus: document.hasFocus(),
|
|
217
|
+
timestamp: new Date().toISOString(),
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Override start() to check initial visibility state
|
|
223
|
+
*/
|
|
224
|
+
async start(inboundHandler) {
|
|
225
|
+
await super.start(inboundHandler);
|
|
226
|
+
// After transitioning to STARTED, check if tab is already hidden
|
|
227
|
+
if (typeof document !== 'undefined' && document.hidden) {
|
|
228
|
+
logger.debug('inpage_start_in_hidden_tab', {
|
|
229
|
+
channel: this.channelName,
|
|
230
|
+
connector_id: this.connectorId,
|
|
231
|
+
document_hidden: document.hidden,
|
|
232
|
+
visibility_state: document.visibilityState,
|
|
233
|
+
has_focus: document.hasFocus(),
|
|
234
|
+
timestamp: new Date().toISOString(),
|
|
235
|
+
});
|
|
236
|
+
// Immediately pause if tab is hidden at start time
|
|
237
|
+
await this.pause().catch((err) => {
|
|
238
|
+
logger.warning('inpage_initial_pause_failed', {
|
|
239
|
+
channel: this.channelName,
|
|
240
|
+
connector_id: this.connectorId,
|
|
241
|
+
error: err instanceof Error ? err.message : String(err),
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
}
|
|
157
245
|
}
|
|
158
246
|
// Allow listeners to feed envelopes directly into the in-page receive queue.
|
|
159
247
|
async pushToReceive(rawOrEnvelope) {
|
|
@@ -203,6 +291,11 @@ class InPageConnector extends base_async_connector_js_1.BaseAsyncConnector {
|
|
|
203
291
|
getSharedBus().removeEventListener(this.channelName, this.onMsg);
|
|
204
292
|
this.listenerRegistered = false;
|
|
205
293
|
}
|
|
294
|
+
if (this.visibilityChangeListenerRegistered && this.visibilityChangeHandler && typeof document !== 'undefined') {
|
|
295
|
+
document.removeEventListener('visibilitychange', this.visibilityChangeHandler);
|
|
296
|
+
this.visibilityChangeListenerRegistered = false;
|
|
297
|
+
this.visibilityChangeHandler = undefined;
|
|
298
|
+
}
|
|
206
299
|
const closeCode = typeof code === 'number' ? code : 1000;
|
|
207
300
|
const closeReason = typeof reason === 'string' && reason.length > 0 ? reason : 'closed';
|
|
208
301
|
const shutdownError = new errors_js_1.FameTransportClose(closeReason, closeCode);
|
|
@@ -388,7 +388,7 @@ class UpstreamSessionManager extends task_spawner_js_1.TaskSpawner {
|
|
|
388
388
|
this.currentStopSubtasks = null;
|
|
389
389
|
await Promise.allSettled(tasks.map((task) => task.promise));
|
|
390
390
|
if (this.connector) {
|
|
391
|
-
logger.
|
|
391
|
+
logger.debug('upstream_stopping_old_connector', {
|
|
392
392
|
connect_epoch: this.connectEpoch,
|
|
393
393
|
target_system_id: this.targetSystemId,
|
|
394
394
|
timestamp: new Date().toISOString(),
|
|
@@ -399,7 +399,7 @@ class UpstreamSessionManager extends task_spawner_js_1.TaskSpawner {
|
|
|
399
399
|
error: err instanceof Error ? err.message : String(err),
|
|
400
400
|
});
|
|
401
401
|
});
|
|
402
|
-
logger.
|
|
402
|
+
logger.debug('upstream_old_connector_stopped', {
|
|
403
403
|
connect_epoch: this.connectEpoch,
|
|
404
404
|
target_system_id: this.targetSystemId,
|
|
405
405
|
timestamp: new Date().toISOString(),
|
package/dist/cjs/version.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// This file is auto-generated during build - do not edit manually
|
|
3
|
-
// Generated from package.json version: 0.3.5-test.
|
|
3
|
+
// Generated from package.json version: 0.3.5-test.942
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.VERSION = void 0;
|
|
6
6
|
/**
|
|
7
7
|
* The package version, injected at build time.
|
|
8
8
|
* @internal
|
|
9
9
|
*/
|
|
10
|
-
exports.VERSION = '0.3.5-test.
|
|
10
|
+
exports.VERSION = '0.3.5-test.942';
|
|
@@ -178,6 +178,24 @@ export class BroadcastChannelConnector extends BaseAsyncConnector {
|
|
|
178
178
|
if (typeof document !== 'undefined') {
|
|
179
179
|
document.addEventListener('visibilitychange', this.visibilityChangeHandler);
|
|
180
180
|
this.visibilityChangeListenerRegistered = true;
|
|
181
|
+
// Track page lifecycle events to detect browser unload/discard
|
|
182
|
+
if (typeof window !== 'undefined') {
|
|
183
|
+
const lifecycleLogger = (event) => {
|
|
184
|
+
logger.info('broadcast_channel_page_lifecycle', {
|
|
185
|
+
channel: this.channelName,
|
|
186
|
+
connector_id: this.connectorId,
|
|
187
|
+
event_type: event.type,
|
|
188
|
+
visibility_state: document.visibilityState,
|
|
189
|
+
timestamp: new Date().toISOString(),
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
window.addEventListener('beforeunload', lifecycleLogger);
|
|
193
|
+
window.addEventListener('unload', lifecycleLogger);
|
|
194
|
+
window.addEventListener('pagehide', lifecycleLogger);
|
|
195
|
+
window.addEventListener('pageshow', lifecycleLogger);
|
|
196
|
+
document.addEventListener('freeze', lifecycleLogger);
|
|
197
|
+
document.addEventListener('resume', lifecycleLogger);
|
|
198
|
+
}
|
|
181
199
|
// Log initial state with detailed visibility info
|
|
182
200
|
logger.debug('broadcast_channel_initial_visibility', {
|
|
183
201
|
channel: this.channelName,
|
|
@@ -186,6 +204,7 @@ export class BroadcastChannelConnector extends BaseAsyncConnector {
|
|
|
186
204
|
document_hidden: document.hidden,
|
|
187
205
|
visibility_state: document.visibilityState,
|
|
188
206
|
has_focus: document.hasFocus(),
|
|
207
|
+
timestamp: new Date().toISOString(),
|
|
189
208
|
});
|
|
190
209
|
}
|
|
191
210
|
}
|