Skip to content

Commit aff4154

Browse files
authored
Merge pull request #3 from oofnish/claude/fix-asset-cache-busting
Fix stale-cache asset loading; add broker connection watchdog
2 parents 07b0c85 + 5a95a3f commit aff4154

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

app.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,25 @@ function brokerAvailable() {
7878
return typeof Peer !== 'undefined';
7979
}
8080

81+
// If the broker never confirms our registration, surface an error instead of
82+
// hanging silently on the placeholder.
83+
const BROKER_TIMEOUT_MS = 15000;
84+
let brokerTimer = null;
85+
86+
function armBrokerWatchdog(statusId) {
87+
clearTimeout(brokerTimer);
88+
brokerTimer = setTimeout(() => {
89+
$(statusId).textContent =
90+
'Could not reach the signaling broker. Check your internet, or use the manual code.';
91+
setStatus('Connection error', 'error');
92+
}, BROKER_TIMEOUT_MS);
93+
}
94+
95+
function clearBrokerWatchdog() {
96+
clearTimeout(brokerTimer);
97+
brokerTimer = null;
98+
}
99+
81100
// Create side: register a code and wait for the other device to connect.
82101
function startEasyHost() {
83102
if (!brokerAvailable()) {
@@ -91,8 +110,10 @@ function startEasyHost() {
91110

92111
const code = randomCode();
93112
peer = new Peer(PEER_PREFIX + code, { debug: 1 });
113+
armBrokerWatchdog('create-easy-status');
94114

95115
peer.on('open', () => {
116+
clearBrokerWatchdog();
96117
$('my-code').textContent = code;
97118
setStatus('Waiting for the other device…', 'connecting');
98119
$('create-easy-status').textContent = 'Waiting for the other device to join…';
@@ -105,6 +126,7 @@ function startEasyHost() {
105126
});
106127

107128
peer.on('error', (err) => {
129+
clearBrokerWatchdog();
108130
if (err.type === 'unavailable-id') {
109131
// Rare clash on the shared broker — try a fresh code.
110132
peer.destroy();
@@ -129,13 +151,18 @@ function startEasyJoin() {
129151
$('join-easy-status').textContent = 'Connecting…';
130152
setStatus('Connecting…', 'connecting');
131153
peer = new Peer({ debug: 1 });
154+
armBrokerWatchdog('join-easy-status');
132155

133156
peer.on('open', () => {
134-
const conn = peer.connect(PEER_PREFIX + code, { reliable: true, serialization: 'none' });
157+
clearBrokerWatchdog();
158+
// 'raw' passes strings and binary through untouched; we do our own
159+
// chunking. (Note: PeerJS has no 'none' serializer despite the enum.)
160+
const conn = peer.connect(PEER_PREFIX + code, { reliable: true, serialization: 'raw' });
135161
adoptPeerConnection(conn);
136162
});
137163

138164
peer.on('error', (err) => {
165+
clearBrokerWatchdog();
139166
if (err.type === 'peer-unavailable') {
140167
$('join-easy-status').textContent = 'No device is waiting on that code. Double-check it.';
141168
setStatus('Not connected', 'idle');
@@ -452,6 +479,7 @@ function addOutgoingNote(text) {
452479
// ---- Mode toggles & reset -------------------------------------------------
453480

454481
function teardownConnections() {
482+
clearBrokerWatchdog();
455483
if (channel) try { channel.close(); } catch (_) {}
456484
if (pc) try { pc.close(); } catch (_) {}
457485
if (peer) try { peer.destroy(); } catch (_) {}

index.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>FileDropper — LAN file &amp; clipboard transfer</title>
7-
<link rel="stylesheet" href="style.css" />
7+
<!-- Bump the ?v= version whenever style.css / app.js change so browsers
8+
don't run a stale cached copy against fresh HTML. -->
9+
<link rel="stylesheet" href="style.css?v=3" />
810
</head>
911
<body>
1012
<header>
@@ -126,7 +128,7 @@ <h3>Sending</h3>
126128
<p>Runs in your browser via WebRTC. <a href="https://github.com/oofnish/filedropper" target="_blank" rel="noopener">Source</a></p>
127129
</footer>
128130

129-
<script src="vendor/peerjs.min.js"></script>
130-
<script src="app.js"></script>
131+
<script src="vendor/peerjs.min.js?v=1.5.4"></script>
132+
<script src="app.js?v=3"></script>
131133
</body>
132134
</html>

0 commit comments

Comments
 (0)