@andy.ian/dsh-homing 2.1.10 → 2.1.11
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/lib/vendor/vnc.bundle.js +61 -44
- package/lib/vnc-app.js +64 -34
- package/lib/vnc-boot.js +1 -1
- package/package.json +1 -1
package/lib/vendor/vnc.bundle.js
CHANGED
|
@@ -14517,19 +14517,7 @@ async function rotateDesktop(mode) {
|
|
|
14517
14517
|
setStatus("\u5207\u6362\u5931\u8D25\uFF1A" + (data.detail || "\u672A\u77E5\u539F\u56E0"), "bad");
|
|
14518
14518
|
return;
|
|
14519
14519
|
}
|
|
14520
|
-
|
|
14521
|
-
if (mode === "portrait") localStorage.setItem("dsh-vnc-portrait", "1");
|
|
14522
|
-
else localStorage.removeItem("dsh-vnc-portrait");
|
|
14523
|
-
} catch {
|
|
14524
|
-
}
|
|
14525
|
-
setStatus(mode === "portrait" ? "\u5DF2\u5207\u7AD6\u5C4F\uFF0C\u91CD\u8FDE\u4E2D\u2026" : "\u5DF2\u5207\u6A2A\u5C4F\uFF0C\u91CD\u8FDE\u4E2D\u2026", "ok");
|
|
14526
|
-
setTimeout(() => {
|
|
14527
|
-
try {
|
|
14528
|
-
cleanup();
|
|
14529
|
-
connect();
|
|
14530
|
-
} catch {
|
|
14531
|
-
}
|
|
14532
|
-
}, 1200);
|
|
14520
|
+
setStatus(mode === "portrait" ? "\u5DF2\u5207\u7AD6\u5C4F\uFF0C\u753B\u9762\u81EA\u52A8\u9002\u914D\u4E2D\u2026" : "\u5DF2\u5207\u6A2A\u5C4F\uFF0C\u753B\u9762\u81EA\u52A8\u9002\u914D\u4E2D\u2026", "ok");
|
|
14533
14521
|
} catch (error) {
|
|
14534
14522
|
setStatus("\u5207\u6362\u5931\u8D25\uFF1A" + (error?.message ?? error), "bad");
|
|
14535
14523
|
}
|
|
@@ -14671,13 +14659,38 @@ function canvasOfGuard() {
|
|
|
14671
14659
|
}, true);
|
|
14672
14660
|
}
|
|
14673
14661
|
}
|
|
14662
|
+
var reconnectTimer = null;
|
|
14663
|
+
var reconnectTries = 0;
|
|
14664
|
+
var userClosed = false;
|
|
14665
|
+
function clearReconnect() {
|
|
14666
|
+
if (reconnectTimer !== null) {
|
|
14667
|
+
clearTimeout(reconnectTimer);
|
|
14668
|
+
reconnectTimer = null;
|
|
14669
|
+
}
|
|
14670
|
+
}
|
|
14671
|
+
function scheduleReconnect() {
|
|
14672
|
+
if (userClosed || reconnectTimer !== null) return;
|
|
14673
|
+
reconnectTries += 1;
|
|
14674
|
+
if (reconnectTries > 6) {
|
|
14675
|
+
setStatus("\u8FDE\u63A5\u4E2D\u65AD\uFF0C\u8BF7\u70B9\u300C\u8FDE\u63A5\u300D\u91CD\u8BD5", "bad");
|
|
14676
|
+
return;
|
|
14677
|
+
}
|
|
14678
|
+
const delay = Math.min(800 * reconnectTries, 4e3);
|
|
14679
|
+
setStatus("\u8FDE\u63A5\u4E2D\u65AD\uFF0C" + (delay / 1e3).toFixed(1) + " \u79D2\u540E\u91CD\u8FDE\u2026", "bad");
|
|
14680
|
+
reconnectTimer = setTimeout(() => {
|
|
14681
|
+
reconnectTimer = null;
|
|
14682
|
+
if (rfb === null && !userClosed) connect();
|
|
14683
|
+
}, delay);
|
|
14684
|
+
}
|
|
14674
14685
|
function cleanup() {
|
|
14686
|
+
clearReconnect();
|
|
14675
14687
|
if (rfb !== null) {
|
|
14688
|
+
const old = rfb;
|
|
14689
|
+
rfb = null;
|
|
14676
14690
|
try {
|
|
14677
|
-
|
|
14691
|
+
old.disconnect();
|
|
14678
14692
|
} catch {
|
|
14679
14693
|
}
|
|
14680
|
-
rfb = null;
|
|
14681
14694
|
}
|
|
14682
14695
|
connected = false;
|
|
14683
14696
|
stopPolling();
|
|
@@ -14687,11 +14700,21 @@ function cleanup() {
|
|
|
14687
14700
|
passwordEl.disabled = false;
|
|
14688
14701
|
}
|
|
14689
14702
|
function connect() {
|
|
14690
|
-
|
|
14703
|
+
userClosed = false;
|
|
14704
|
+
clearReconnect();
|
|
14705
|
+
if (rfb !== null) {
|
|
14706
|
+
const old = rfb;
|
|
14707
|
+
rfb = null;
|
|
14708
|
+
try {
|
|
14709
|
+
old.disconnect();
|
|
14710
|
+
} catch {
|
|
14711
|
+
}
|
|
14712
|
+
}
|
|
14691
14713
|
setStatus("\u8FDE\u63A5\u4E2D\u2026");
|
|
14692
14714
|
connectBtn.disabled = true;
|
|
14715
|
+
let client = null;
|
|
14693
14716
|
try {
|
|
14694
|
-
|
|
14717
|
+
client = new RFB(screenEl, wsUrl(), {
|
|
14695
14718
|
wsProtocols: ["binary"]
|
|
14696
14719
|
});
|
|
14697
14720
|
} catch (error) {
|
|
@@ -14699,12 +14722,15 @@ function connect() {
|
|
|
14699
14722
|
cleanup();
|
|
14700
14723
|
return;
|
|
14701
14724
|
}
|
|
14702
|
-
rfb
|
|
14703
|
-
|
|
14704
|
-
|
|
14705
|
-
|
|
14725
|
+
rfb = client;
|
|
14726
|
+
client.scaleViewport = false;
|
|
14727
|
+
client.clipViewport = false;
|
|
14728
|
+
client.showDotCursor = false;
|
|
14729
|
+
client.focusOnClick = true;
|
|
14706
14730
|
setViewMode("width");
|
|
14707
|
-
|
|
14731
|
+
client.addEventListener("connect", () => {
|
|
14732
|
+
if (rfb !== client) return;
|
|
14733
|
+
reconnectTries = 0;
|
|
14708
14734
|
connected = true;
|
|
14709
14735
|
report("connect-ok", "ok");
|
|
14710
14736
|
disconnectBtn.disabled = false;
|
|
@@ -14719,40 +14745,31 @@ function connect() {
|
|
|
14719
14745
|
});
|
|
14720
14746
|
}
|
|
14721
14747
|
});
|
|
14722
|
-
|
|
14748
|
+
client.addEventListener("disconnect", (event) => {
|
|
14749
|
+
if (rfb !== client) return;
|
|
14723
14750
|
const clean = event.detail?.clean ?? false;
|
|
14724
|
-
report("disconnect", clean ? "clean" : "dirty", { detail: event.detail ?? null, reason:
|
|
14725
|
-
|
|
14751
|
+
report("disconnect", clean ? "clean" : "dirty", { detail: event.detail ?? null, reason: client._lastFailReason ?? null });
|
|
14752
|
+
rfb = null;
|
|
14726
14753
|
cleanup();
|
|
14754
|
+
if (clean || userClosed) {
|
|
14755
|
+
setStatus("\u5DF2\u65AD\u5F00", clean ? "" : "bad");
|
|
14756
|
+
return;
|
|
14757
|
+
}
|
|
14758
|
+
scheduleReconnect();
|
|
14727
14759
|
});
|
|
14728
|
-
|
|
14760
|
+
client.addEventListener("securityfailure", (event) => {
|
|
14761
|
+
if (rfb !== client) return;
|
|
14729
14762
|
setStatus("\u8BA4\u8BC1\u5931\u8D25\uFF1A" + (event.detail?.reason ?? "\u5BC6\u7801\u9519\u8BEF"), "bad");
|
|
14763
|
+
rfb = null;
|
|
14730
14764
|
cleanup();
|
|
14731
14765
|
});
|
|
14732
14766
|
}
|
|
14733
14767
|
connectBtn.addEventListener("click", connect);
|
|
14734
14768
|
disconnectBtn.addEventListener("click", () => {
|
|
14769
|
+
userClosed = true;
|
|
14735
14770
|
cleanup();
|
|
14736
14771
|
setStatus("\u5DF2\u65AD\u5F00");
|
|
14737
14772
|
});
|
|
14738
|
-
window.addEventListener("pagehide", () => {
|
|
14739
|
-
try {
|
|
14740
|
-
if (localStorage.getItem("dsh-vnc-portrait") === "1") {
|
|
14741
|
-
localStorage.removeItem("dsh-vnc-portrait");
|
|
14742
|
-
const body = new Blob([JSON.stringify({ kind: "rotate", mode: "landscape" })], { type: "application/json" });
|
|
14743
|
-
if (navigator.sendBeacon) navigator.sendBeacon("/remote/input", body);
|
|
14744
|
-
else fetch("/remote/input", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ kind: "rotate", mode: "landscape" }), keepalive: true }).catch(() => {
|
|
14745
|
-
});
|
|
14746
|
-
}
|
|
14747
|
-
} catch {
|
|
14748
|
-
}
|
|
14749
|
-
if (rfb !== null) {
|
|
14750
|
-
try {
|
|
14751
|
-
rfb.disconnect();
|
|
14752
|
-
} catch {
|
|
14753
|
-
}
|
|
14754
|
-
}
|
|
14755
|
-
});
|
|
14756
14773
|
setupMobileKeyboard();
|
|
14757
14774
|
setupToolbar();
|
|
14758
14775
|
function autoConnect() {
|
package/lib/vnc-app.js
CHANGED
|
@@ -410,14 +410,9 @@ async function rotateDesktop(mode) {
|
|
|
410
410
|
setStatus('切换失败:' + (data.detail || '未知原因'), 'bad')
|
|
411
411
|
return
|
|
412
412
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
} catch { /* 忽略 */ }
|
|
417
|
-
setStatus(mode === 'portrait' ? '已切竖屏,重连中…' : '已切横屏,重连中…', 'ok')
|
|
418
|
-
setTimeout(() => {
|
|
419
|
-
try { cleanup(); connect() } catch { /* 忽略 */ }
|
|
420
|
-
}, 1200)
|
|
413
|
+
// 不再强制重连:noVNC 会随帧缓冲尺寸变化自动适配;
|
|
414
|
+
// 若 TightVNC 因分辨率变化断开,由下面的自动重连逻辑接管。
|
|
415
|
+
setStatus(mode === 'portrait' ? '已切竖屏,画面自动适配中…' : '已切横屏,画面自动适配中…', 'ok')
|
|
421
416
|
} catch (error) {
|
|
422
417
|
setStatus('切换失败:' + (error?.message ?? error), 'bad')
|
|
423
418
|
}
|
|
@@ -571,10 +566,39 @@ function canvasOfGuard() {
|
|
|
571
566
|
}
|
|
572
567
|
}
|
|
573
568
|
|
|
569
|
+
let reconnectTimer = null
|
|
570
|
+
let reconnectTries = 0
|
|
571
|
+
let userClosed = false
|
|
572
|
+
|
|
573
|
+
function clearReconnect() {
|
|
574
|
+
if (reconnectTimer !== null) {
|
|
575
|
+
clearTimeout(reconnectTimer)
|
|
576
|
+
reconnectTimer = null
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
/** 非用户主动断开:退避重连(TightVNC 在分辨率变化时可能断开连接) */
|
|
581
|
+
function scheduleReconnect() {
|
|
582
|
+
if (userClosed || reconnectTimer !== null) return
|
|
583
|
+
reconnectTries += 1
|
|
584
|
+
if (reconnectTries > 6) {
|
|
585
|
+
setStatus('连接中断,请点「连接」重试', 'bad')
|
|
586
|
+
return
|
|
587
|
+
}
|
|
588
|
+
const delay = Math.min(800 * reconnectTries, 4000)
|
|
589
|
+
setStatus('连接中断,' + (delay / 1000).toFixed(1) + ' 秒后重连…', 'bad')
|
|
590
|
+
reconnectTimer = setTimeout(() => {
|
|
591
|
+
reconnectTimer = null
|
|
592
|
+
if (rfb === null && !userClosed) connect()
|
|
593
|
+
}, delay)
|
|
594
|
+
}
|
|
595
|
+
|
|
574
596
|
function cleanup() {
|
|
597
|
+
clearReconnect()
|
|
575
598
|
if (rfb !== null) {
|
|
576
|
-
|
|
599
|
+
const old = rfb
|
|
577
600
|
rfb = null
|
|
601
|
+
try { old.disconnect() } catch { /* 已断开 */ }
|
|
578
602
|
}
|
|
579
603
|
connected = false
|
|
580
604
|
stopPolling()
|
|
@@ -585,12 +609,20 @@ function cleanup() {
|
|
|
585
609
|
}
|
|
586
610
|
|
|
587
611
|
function connect() {
|
|
588
|
-
|
|
612
|
+
userClosed = false
|
|
613
|
+
clearReconnect()
|
|
614
|
+
if (rfb !== null) {
|
|
615
|
+
const old = rfb
|
|
616
|
+
rfb = null
|
|
617
|
+
try { old.disconnect() } catch { /* 已断开 */ }
|
|
618
|
+
}
|
|
589
619
|
setStatus('连接中…')
|
|
590
620
|
connectBtn.disabled = true
|
|
621
|
+
|
|
622
|
+
let client = null
|
|
591
623
|
try {
|
|
592
624
|
// 密码由服务端代认证(lib/vnc-auth-proxy.mjs),浏览器不持有密码
|
|
593
|
-
|
|
625
|
+
client = new RFB(screenEl, wsUrl(), {
|
|
594
626
|
wsProtocols: ['binary'],
|
|
595
627
|
})
|
|
596
628
|
} catch (error) {
|
|
@@ -598,14 +630,16 @@ function connect() {
|
|
|
598
630
|
cleanup()
|
|
599
631
|
return
|
|
600
632
|
}
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
633
|
+
rfb = client
|
|
634
|
+
client.scaleViewport = false
|
|
635
|
+
client.clipViewport = false
|
|
636
|
+
client.showDotCursor = false
|
|
637
|
+
client.focusOnClick = true
|
|
606
638
|
setViewMode('width')
|
|
607
639
|
|
|
608
|
-
|
|
640
|
+
client.addEventListener('connect', () => {
|
|
641
|
+
if (rfb !== client) return
|
|
642
|
+
reconnectTries = 0
|
|
609
643
|
connected = true
|
|
610
644
|
report('connect-ok', 'ok')
|
|
611
645
|
disconnectBtn.disabled = false
|
|
@@ -618,37 +652,33 @@ function connect() {
|
|
|
618
652
|
focusByHwnd(focus).then((found) => { if (!found) setStatus('未找到对应窗口,已显示整屏') })
|
|
619
653
|
}
|
|
620
654
|
})
|
|
621
|
-
|
|
655
|
+
client.addEventListener('disconnect', (event) => {
|
|
656
|
+
if (rfb !== client) return // 旧连接的迟到事件不能影响新连接
|
|
622
657
|
const clean = event.detail?.clean ?? false
|
|
623
|
-
report('disconnect', clean ? 'clean' : 'dirty', { detail: event.detail ?? null, reason:
|
|
624
|
-
|
|
658
|
+
report('disconnect', clean ? 'clean' : 'dirty', { detail: event.detail ?? null, reason: client._lastFailReason ?? null })
|
|
659
|
+
rfb = null
|
|
625
660
|
cleanup()
|
|
661
|
+
if (clean || userClosed) {
|
|
662
|
+
setStatus('已断开', clean ? '' : 'bad')
|
|
663
|
+
return
|
|
664
|
+
}
|
|
665
|
+
scheduleReconnect()
|
|
626
666
|
})
|
|
627
|
-
|
|
667
|
+
client.addEventListener('securityfailure', (event) => {
|
|
668
|
+
if (rfb !== client) return
|
|
628
669
|
setStatus('认证失败:' + (event.detail?.reason ?? '密码错误'), 'bad')
|
|
670
|
+
rfb = null
|
|
629
671
|
cleanup()
|
|
630
672
|
})
|
|
631
673
|
}
|
|
632
674
|
|
|
633
675
|
connectBtn.addEventListener('click', connect)
|
|
634
676
|
disconnectBtn.addEventListener('click', () => {
|
|
677
|
+
userClosed = true
|
|
635
678
|
cleanup()
|
|
636
679
|
setStatus('已断开')
|
|
637
680
|
})
|
|
638
681
|
|
|
639
|
-
window.addEventListener('pagehide', () => {
|
|
640
|
-
// 离开页面时如果竖屏是我们切的,恢复横屏,避免把 PC 留在竖屏
|
|
641
|
-
try {
|
|
642
|
-
if (localStorage.getItem('dsh-vnc-portrait') === '1') {
|
|
643
|
-
localStorage.removeItem('dsh-vnc-portrait')
|
|
644
|
-
const body = new Blob([JSON.stringify({ kind: 'rotate', mode: 'landscape' })], { type: 'application/json' })
|
|
645
|
-
if (navigator.sendBeacon) navigator.sendBeacon('/remote/input', body)
|
|
646
|
-
else fetch('/remote/input', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ kind: 'rotate', mode: 'landscape' }), keepalive: true }).catch(() => {})
|
|
647
|
-
}
|
|
648
|
-
} catch { /* 忽略 */ }
|
|
649
|
-
if (rfb !== null) { try { rfb.disconnect() } catch { /* 忽略 */ } }
|
|
650
|
-
})
|
|
651
|
-
|
|
652
682
|
setupMobileKeyboard()
|
|
653
683
|
setupToolbar()
|
|
654
684
|
|
package/lib/vnc-boot.js
CHANGED