Add broadcast on/off toggle checkbox in relays.html sidenav
This commit is contained in:
@@ -1762,6 +1762,19 @@ export function setOutboxModel(enabled) {
|
||||
console.log('[init-ndk] Outbox model:', enabled ? 'enabled' : 'disabled');
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable or disable the broadcast relay path (kind 10088) at runtime.
|
||||
* When disabled, posts only go to the user's enabled kind 10002 relays.
|
||||
* @param {boolean} enabled
|
||||
*/
|
||||
export function setBroadcastEnabled(enabled) {
|
||||
if (!ndkWorker) {
|
||||
throw new Error('NDK worker not initialized. Call initNDKPage() first.');
|
||||
}
|
||||
ndkWorker.port.postMessage({ type: 'setBroadcastEnabled', enabled });
|
||||
console.log('[init-ndk] Broadcast:', enabled ? 'enabled' : 'disabled');
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to disconnect worker
|
||||
*/
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"VERSION": "v0.7.101",
|
||||
"VERSION_NUMBER": "0.7.101",
|
||||
"BUILD_DATE": "2026-08-07T14:06:51.088Z"
|
||||
"VERSION": "v0.7.102",
|
||||
"VERSION_NUMBER": "0.7.102",
|
||||
"BUILD_DATE": "2026-08-07T19:02:39.514Z"
|
||||
}
|
||||
|
||||
+25
-1
@@ -89728,6 +89728,12 @@ let disabledRelays = new Set();
|
||||
// auto-connecting to discovered outbox relays.
|
||||
let outboxModelEnabled = true;
|
||||
|
||||
// Broadcast toggle (session-level, synced from page localStorage on init).
|
||||
// When false, handlePublish skips the broadcast relay path entirely and
|
||||
// falls through to the normal publish path (which only publishes to
|
||||
// enabled kind 10002 relays).
|
||||
let broadcastEnabled = true;
|
||||
|
||||
/**
|
||||
* Check if a relay URL is temporarily disabled.
|
||||
* Checks both the normalized and raw form.
|
||||
@@ -95697,8 +95703,11 @@ async function handlePublish(requestId, event, port) {
|
||||
// temporary NDKRelaySet. NDK's fromRelayUrls uses pool.useTemporaryRelay
|
||||
// so hundreds of broadcast relays connect transiently without polluting
|
||||
// the read subscription pool.
|
||||
// If broadcastEnabled is false, skip the broadcast path entirely and
|
||||
// fall through to the normal publish path (which only publishes to
|
||||
// enabled kind 10002 relays).
|
||||
const activeBroadcastUrls = getActiveBroadcastUrls();
|
||||
const isBroadcast = wantsBroadcastRelays(event) && activeBroadcastUrls.length > 0;
|
||||
const isBroadcast = broadcastEnabled && wantsBroadcastRelays(event) && activeBroadcastUrls.length > 0;
|
||||
let outboxWriteUrls = [];
|
||||
|
||||
if (isBroadcast) {
|
||||
@@ -97196,6 +97205,17 @@ function handleSetOutboxModel(enabled, port) {
|
||||
port.postMessage({ type: 'response', data: { success: true, outboxModelEnabled: outboxModelEnabled } });
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle set broadcast enabled request — enable or disable the broadcast relay
|
||||
* path (kind 10088). When disabled, handlePublish skips the broadcast path
|
||||
* entirely and falls through to the normal publish path.
|
||||
*/
|
||||
function handleSetBroadcastEnabled(enabled, port) {
|
||||
console.log('[Worker] Setting broadcast enabled:', enabled);
|
||||
broadcastEnabled = enabled;
|
||||
port.postMessage({ type: 'response', data: { success: true, broadcastEnabled: broadcastEnabled } });
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle reconnect relay request
|
||||
*/
|
||||
@@ -97578,6 +97598,10 @@ self.onconnect = (event) => {
|
||||
handleSetOutboxModel(e.data.enabled, port);
|
||||
break;
|
||||
|
||||
case 'setBroadcastEnabled':
|
||||
handleSetBroadcastEnabled(e.data.enabled, port);
|
||||
break;
|
||||
|
||||
case 'disconnect':
|
||||
handleDisconnect();
|
||||
break;
|
||||
|
||||
+28
-1
@@ -337,7 +337,7 @@
|
||||
/* ================================================================
|
||||
IMPORTS
|
||||
================================================================ */
|
||||
import { initNDKPage, getPubkey, injectHeaderAvatar, disconnect, getRelayData, getRelayStats, reconnectRelay, disableRelay, enableRelay, setOutboxModel, publishEvent, getVersion, updateVersionDisplay, ndkFetchEvents, setRelayEventLogging, getDiscoveredRelays } from './js/init-ndk.mjs';
|
||||
import { initNDKPage, getPubkey, injectHeaderAvatar, disconnect, getRelayData, getRelayStats, reconnectRelay, disableRelay, enableRelay, setOutboxModel, setBroadcastEnabled, publishEvent, getVersion, updateVersionDisplay, ndkFetchEvents, setRelayEventLogging, getDiscoveredRelays } from './js/init-ndk.mjs';
|
||||
import { HamburgerMorphing } from "./hamburger_morphing/hamburger.mjs";
|
||||
import { initFooterRelayStatus, updateFooterRelayStatus, initSidenavRelaySection, updateSidenavRelaySection, setRelayActivityState } from './js/relay-ui.mjs';
|
||||
|
||||
@@ -447,6 +447,10 @@ const versionInfo = await getVersion();
|
||||
<span style="flex:1;">Outbox model</span>
|
||||
<div id="divOutboxToggleCheckbox" class="divSvg" style="width:16px;height:16px;flex-shrink:0;">${outboxEnabled ? SVG_CHECKED : SVG_UNCHECKED}</div>
|
||||
</div>
|
||||
<div id="divBroadcastToggleSettings" style="display:flex;align-items:center;padding:4px 10px;cursor:pointer;font-size:80%;color:var(--primary-color);">
|
||||
<span style="flex:1;">Broadcast</span>
|
||||
<div id="divBroadcastToggleCheckbox" class="divSvg" style="width:16px;height:16px;flex-shrink:0;">${SVG_CHECKED}</div>
|
||||
</div>
|
||||
<div id="divBroadcastRelaysSettings" style="padding:4px 10px;font-size:80%;color:var(--primary-color);">
|
||||
<div id="divBroadcastRelaysHeader" style="display:flex;align-items:center;cursor:pointer;">
|
||||
<span style="flex:1;">Broadcast Relays
|
||||
@@ -525,6 +529,24 @@ const versionInfo = await getVersion();
|
||||
document.getElementById('divOutboxSettings').addEventListener('click', toggleOutbox);
|
||||
}
|
||||
|
||||
// Wire up the broadcast toggle
|
||||
const divBroadcastToggle = document.getElementById('divBroadcastToggleCheckbox');
|
||||
if (divBroadcastToggle) {
|
||||
const toggleBroadcast = () => {
|
||||
const checked = localStorage.getItem('broadcastEnabled') !== 'false'; // current state (default: true)
|
||||
const newState = !checked;
|
||||
localStorage.setItem('broadcastEnabled', newState);
|
||||
setBroadcastEnabled(newState);
|
||||
divBroadcastToggle.innerHTML = newState ? SVG_CHECKED : SVG_UNCHECKED;
|
||||
console.log('[relays.html] Broadcast toggled:', newState);
|
||||
};
|
||||
divBroadcastToggle.addEventListener('click', (e) => {
|
||||
e.stopPropagation();
|
||||
toggleBroadcast();
|
||||
});
|
||||
document.getElementById('divBroadcastToggleSettings').addEventListener('click', toggleBroadcast);
|
||||
}
|
||||
|
||||
// Wire up the Broadcast Relays collapsible section.
|
||||
initBroadcastRelaysSection();
|
||||
|
||||
@@ -1882,6 +1904,11 @@ const versionInfo = await getVersion();
|
||||
setOutboxModel(outboxModelEnabled);
|
||||
console.log('[relays.html] Outbox model on init:', outboxModelEnabled);
|
||||
|
||||
// Sync broadcast toggle state from localStorage and send to worker
|
||||
const broadcastEnabled = localStorage.getItem('broadcastEnabled') !== 'false'; // default: true
|
||||
setBroadcastEnabled(broadcastEnabled);
|
||||
console.log('[relays.html] Broadcast on init:', broadcastEnabled);
|
||||
|
||||
// Stop the worker from broadcasting relay events when the page is closing
|
||||
window.addEventListener('beforeunload', () => {
|
||||
if (connectionHistoryEnabled) {
|
||||
|
||||
Reference in New Issue
Block a user