@kangsicj/nexussync 1.6.2 → 1.6.3
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/NexusSync.meta.js +1 -1
- package/dist/NexusSync.user.js +183 -24
- package/package.json +1 -1
package/dist/NexusSync.meta.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// @icon https://cdn.jsdelivr.net/npm/@kangsicj/nexussync@latest/assets/icon.svg
|
|
9
9
|
// @updateURL https://cdn.jsdelivr.net/npm/@kangsicj/nexussync@latest/dist/NexusSync.meta.js
|
|
10
10
|
// @downloadURL https://cdn.jsdelivr.net/npm/@kangsicj/nexussync@latest/dist/NexusSync.user.js
|
|
11
|
-
// @version 1.6.
|
|
11
|
+
// @version 1.6.3
|
|
12
12
|
// @description Watch any web video together in perfect sync: cinema mode, live AI subtitles & translation, chat bubbles with auto-translation, quick ink, cover, go-together to the next episode.
|
|
13
13
|
// @description:ko 어떤 웹 영상이든 완벽한 싱크로 함께 보기: 시네마 모드, 실시간 AI 자막·번역, 자동 번역 말풍선 채팅, 잠깐 그리기, 가리기, 다음 화도 함께.
|
|
14
14
|
// @match *://*/*
|
package/dist/NexusSync.user.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// @icon https://cdn.jsdelivr.net/npm/@kangsicj/nexussync@latest/assets/icon.svg
|
|
9
9
|
// @updateURL https://cdn.jsdelivr.net/npm/@kangsicj/nexussync@latest/dist/NexusSync.meta.js
|
|
10
10
|
// @downloadURL https://cdn.jsdelivr.net/npm/@kangsicj/nexussync@latest/dist/NexusSync.user.js
|
|
11
|
-
// @version 1.6.
|
|
11
|
+
// @version 1.6.3
|
|
12
12
|
// @description Watch any web video together in perfect sync: cinema mode, live AI subtitles & translation, chat bubbles with auto-translation, quick ink, cover, go-together to the next episode.
|
|
13
13
|
// @description:ko 어떤 웹 영상이든 완벽한 싱크로 함께 보기: 시네마 모드, 실시간 AI 자막·번역, 자동 번역 말풍선 채팅, 잠깐 그리기, 가리기, 다음 화도 함께.
|
|
14
14
|
// @match *://*/*
|
|
@@ -46,12 +46,12 @@
|
|
|
46
46
|
|
|
47
47
|
// The version of the code that is actually running (the manager's metadata can lag
|
|
48
48
|
// behind when an old copy is still installed).
|
|
49
|
-
const NXU_VERSION = '1.6.
|
|
49
|
+
const NXU_VERSION = '1.6.3';
|
|
50
50
|
// Rank used by the one-instance guard below and to tell newer builds apart in a room.
|
|
51
51
|
// It is independent of the public version (1.0.0 is the first public release, after
|
|
52
52
|
// private builds that reached ranks up to 10.2.0), so every older copy still installed
|
|
53
53
|
// steps aside instead of this release.
|
|
54
|
-
const NXU_RANK = '11.6.
|
|
54
|
+
const NXU_RANK = '11.6.3';
|
|
55
55
|
const NXU_SESSION = Math.random().toString(36).slice(2, 10); // this page load // raise with every release
|
|
56
56
|
// App icon (same artwork as assets/icon.svg / @icon), inlined so it shows offline too.
|
|
57
57
|
const NXU_ICON = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTYgMjU2IiByb2xlPSJpbWciIGFyaWEtbGFiZWw9Ik5leHVzU3luYyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJueGJnIiB4MT0iMCIgeTE9IjAiIHgyPSIxIiB5Mj0iMSI+PHN0b3Agb2Zmc2V0PSIwIiBzdG9wLWNvbG9yPSIjNWIyZWZmIi8+PHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjZmY0ZmEzIi8+PC9saW5lYXJHcmFkaWVudD48cmFkaWFsR3JhZGllbnQgaWQ9Im54Z2xvdyIgY3g9IjAuODIiIGN5PSIwLjE0IiByPSIwLjciPjxzdG9wIG9mZnNldD0iMCIgc3RvcC1jb2xvcj0iIzdjZjlmZiIgc3RvcC1vcGFjaXR5PSIwLjU1Ii8+PHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjN2NmOWZmIiBzdG9wLW9wYWNpdHk9IjAiLz48L3JhZGlhbEdyYWRpZW50PjxsaW5lYXJHcmFkaWVudCBpZD0ibnhwbGF5IiB4MT0iMCIgeTE9IjAiIHgyPSIxIiB5Mj0iMSI+PHN0b3Agb2Zmc2V0PSIwIiBzdG9wLWNvbG9yPSIjZmZmZmZmIi8+PHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjZmZlM2YxIi8+PC9saW5lYXJHcmFkaWVudD48Y2xpcFBhdGggaWQ9Im54ciI+PHJlY3Qgd2lkdGg9IjI1NiIgaGVpZ2h0PSIyNTYiIHJ4PSI1OCIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNueHIpIj48cmVjdCB3aWR0aD0iMjU2IiBoZWlnaHQ9IjI1NiIgZmlsbD0idXJsKCNueGJnKSIvPjxyZWN0IHdpZHRoPSIyNTYiIGhlaWdodD0iMjU2IiBmaWxsPSJ1cmwoI254Z2xvdykiLz48ZyBmaWxsPSJub25lIiBzdHJva2U9IiNmZmZmZmYiIHN0cm9rZS13aWR0aD0iMTUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCI+PHBhdGggZD0iTTYwIDExNiBBNzAgNzAgMCAwIDEgMTc4IDcyIi8+PHBhdGggZD0iTTE5NiAxNDAgQTcwIDcwIDAgMCAxIDc4IDE4NCIvPjwvZz48cGF0aCBkPSJNMTg2IDUwIEwyMDAgOTIgTDE1NyA4NiBaIiBmaWxsPSIjZmZmZmZmIi8+PHBhdGggZD0iTTcwIDIwNiBMNTYgMTY0IEw5OSAxNzAgWiIgZmlsbD0iI2ZmZmZmZiIvPjxwYXRoIGQ9Ik0xMTAgOTIgUTEwNCA4OCAxMDQgOTYgTDEwNCAxNjAgUTEwNCAxNjggMTEwIDE2NCBMMTYyIDEzMiBRMTY4IDEyOCAxNjIgMTI0IFoiIGZpbGw9InVybCgjbnhwbGF5KSIvPjwvZz48L3N2Zz4=';
|
|
@@ -686,7 +686,7 @@
|
|
|
686
686
|
tuneAuto: 'Automatic', tuneAutoBtn: '🤖 Find the timing automatically', tuneAutoHint: 'Uses the sound (or the picture) of what both of you have played over the last minutes. Play together for a little while first.',
|
|
687
687
|
tuneAutoNeed: 'Not enough to compare yet — play together for a little longer and try again.', tuneAutoFound: 'Found: {s} ({c}% sure)', tuneAutoNone: 'No clear match. Try “Same scene” instead.', tuneAsking: 'Asking the others…', tuneApplied: '⏱ Timing set: {s}',
|
|
688
688
|
tuneMarkReceived: '📍 {name} marked a scene', tuneNoPeer: 'Nobody else is in the room yet.',
|
|
689
|
-
tuneSrcSame: '🟢 Same video on every device — kept in step automatically, frame by frame.', tuneSrcDiff: '🟠 Different versions (length differs by {s}) — the timing is found automatically after a little playing, or set it here.', tuneSrcUnknown: 'Waiting for the others’ video…',
|
|
689
|
+
tuneSrcSame: '🟢 Same video on every device — kept in step automatically, frame by frame.', tuneSrcDiff: '🟠 Different versions (length differs by {s}) — the timing is found automatically after a little playing, or set it here.', tuneSrcUnknown: 'Waiting for the others’ video…', tuneSrcShifted: '🟠 Same length, but the scenes differ — the timing is lined up automatically while you play, or set it here.', tuneDiffPicture: 'Same time, but the pictures differ', tuneShiftFound: 'Same length but different scenes: timing set to {s} automatically (tap to undo).',
|
|
690
690
|
tuneSameReset: '⏱ Same video as the others: timing correction removed.', tuneAutoApplied: 'Different version: timing set to {s} automatically (tap to undo).', tuneSuggest: 'Your videos differ by {s}. Tap to line them up.',
|
|
691
691
|
subMenu: 'Subtitles', xsubOff: 'Off', subTrack: 'From the video', subSearch: '🔎 Find subtitles (OpenSubtitles)', subFile: '📂 Open a subtitle file…', subAi: '🧠 AI live subtitles', subDelay: 'Timing', subLater: 'later', subEarlier: 'earlier', xsubSize: 'Size',
|
|
692
692
|
subLoaded: '💬 Subtitles: {name}', subMulti: 'Several subtitles at once — tap one to take it away.', subNone: 'No subtitles found in this video.', subSuggest: '💬 No subtitles? Find them', subLoadFail: 'Could not load these subtitles.',
|
|
@@ -804,7 +804,7 @@
|
|
|
804
804
|
tuneAuto: '자동', tuneAutoBtn: '🤖 자동으로 맞추기', tuneAutoHint: '최근 몇 분 동안 서로 재생한 소리(또는 화면)를 비교해요. 먼저 잠시 함께 재생해 주세요.',
|
|
805
805
|
tuneAutoNeed: '아직 비교할 내용이 부족해요 — 조금 더 함께 재생한 뒤 다시 시도하세요.', tuneAutoFound: '찾았어요: {s} (확신 {c}%)', tuneAutoNone: '뚜렷한 일치를 못 찾았어요. “같은 장면”으로 맞춰 보세요.', tuneAsking: '다른 사람에게 요청하는 중…', tuneApplied: '⏱ 타이밍 보정: {s}',
|
|
806
806
|
tuneMarkReceived: '📍 {name}님이 장면을 표시했어요', tuneNoPeer: '아직 방에 다른 사람이 없어요.',
|
|
807
|
-
tuneSrcSame: '🟢 모두 같은 영상이에요 — 프레임 단위로 자동으로 맞추고 있어요.', tuneSrcDiff: '🟠 서로 다른 버전이에요 (길이 차이 {s}) — 잠시 재생하면 자동으로 맞추고, 여기서 직접 맞출 수도 있어요.', tuneSrcUnknown: '다른 사람의 영상 정보를 기다리는 중…',
|
|
807
|
+
tuneSrcSame: '🟢 모두 같은 영상이에요 — 프레임 단위로 자동으로 맞추고 있어요.', tuneSrcDiff: '🟠 서로 다른 버전이에요 (길이 차이 {s}) — 잠시 재생하면 자동으로 맞추고, 여기서 직접 맞출 수도 있어요.', tuneSrcUnknown: '다른 사람의 영상 정보를 기다리는 중…', tuneSrcShifted: '🟠 길이는 같지만 장면이 달라요 — 재생하는 동안 자동으로 맞추고, 여기서 직접 맞출 수도 있어요.', tuneDiffPicture: '시간은 같지만 화면이 달라요', tuneShiftFound: '길이는 같지만 장면이 달라서 타이밍을 {s} 자동 보정했어요 (누르면 되돌리기).',
|
|
808
808
|
tuneSameReset: '⏱ 상대와 같은 영상이라 타이밍 보정을 해제했어요.', tuneAutoApplied: '다른 버전이라 타이밍을 {s} 자동 보정했어요 (누르면 되돌리기).', tuneSuggest: '서로 영상 길이가 {s} 달라요. 눌러서 맞춰 보세요.',
|
|
809
809
|
subMenu: '자막', xsubOff: '끄기', subTrack: '영상에 포함된 자막', subSearch: '🔎 자막 찾기 (OpenSubtitles)', subFile: '📂 자막 파일 열기…', subAi: '🧠 AI 실시간 자막', subDelay: '싱크', subLater: '늦게', subEarlier: '빠르게', xsubSize: '크기',
|
|
810
810
|
subLoaded: '💬 자막: {name}', subMulti: '자막 여러 개를 함께 보는 중 — 누르면 그 자막만 꺼져요.', subNone: '이 영상에는 포함된 자막이 없어요.', subSuggest: '💬 자막이 없나요? 찾아보기', subLoadFail: '자막을 불러오지 못했어요.',
|
|
@@ -1336,6 +1336,8 @@
|
|
|
1336
1336
|
try { if (video.mediaKeys || video.webkitKeys) return; } catch (_) { } // DRM video always draws black
|
|
1337
1337
|
const doc = video.ownerDocument;
|
|
1338
1338
|
if (root.getRootNode() !== doc) return; // player inside a site's shadow DOM: our styles can't reach it
|
|
1339
|
+
const seeThrough = this._seeThrough(video, root);
|
|
1340
|
+
if (seeThrough) { logDebug('Ambient light off for this player: ' + seeThrough, 'info'); return; }
|
|
1339
1341
|
const view = doc.defaultView || window;
|
|
1340
1342
|
const lite = IS_TOUCH;
|
|
1341
1343
|
const layer = doc.createElement('div');
|
|
@@ -1418,12 +1420,40 @@
|
|
|
1418
1420
|
};
|
|
1419
1421
|
this._ambient = { layer, root, timer, video, view, onSeek, onMeta, stage, stop, redraw: () => draw(true) };
|
|
1420
1422
|
},
|
|
1421
|
-
//
|
|
1423
|
+
// The glow sits behind the picture, which only works when the picture covers it. A
|
|
1424
|
+
// player that shows the video see-through (faded, blended, blurred, or hidden while
|
|
1425
|
+
// it draws the frames elsewhere) would let the blurry glow through: then no glow.
|
|
1426
|
+
_seeThrough(video, root) {
|
|
1427
|
+
try {
|
|
1428
|
+
const view = video.ownerDocument.defaultView || window;
|
|
1429
|
+
for (let el = video; el && el.nodeType === 1; el = el.parentElement) {
|
|
1430
|
+
const cs = view.getComputedStyle(el);
|
|
1431
|
+
if (Number(cs.opacity) < 0.95) return 'the picture is faded (' + (el === video ? 'video' : el.tagName.toLowerCase()) + ' opacity ' + cs.opacity + ')';
|
|
1432
|
+
if (cs.visibility !== 'visible') return 'the video is hidden';
|
|
1433
|
+
if (cs.mixBlendMode && cs.mixBlendMode !== 'normal') return 'the picture is blended (' + cs.mixBlendMode + ')';
|
|
1434
|
+
if (/blur|opacity/i.test(cs.filter || '')) return 'the picture is filtered (' + cs.filter + ')';
|
|
1435
|
+
if (el === root) break;
|
|
1436
|
+
}
|
|
1437
|
+
// Frames drawn into a canvas (or another video) over the real video.
|
|
1438
|
+
const vr = video.getBoundingClientRect();
|
|
1439
|
+
if (vr.width > 40 && vr.height > 40) {
|
|
1440
|
+
for (const other of root.querySelectorAll('canvas, video')) {
|
|
1441
|
+
if (other === video) continue;
|
|
1442
|
+
const r = other.getBoundingClientRect();
|
|
1443
|
+
const ix = Math.max(0, Math.min(r.right, vr.right) - Math.max(r.left, vr.left)), iy = Math.max(0, Math.min(r.bottom, vr.bottom) - Math.max(r.top, vr.top));
|
|
1444
|
+
if (ix * iy > vr.width * vr.height * 0.6 && view.getComputedStyle(other).visibility === 'visible' && Number(view.getComputedStyle(other).opacity) > 0.05) return 'the picture is drawn in another ' + other.tagName.toLowerCase();
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
} catch (_) { }
|
|
1448
|
+
return '';
|
|
1449
|
+
},
|
|
1450
|
+
// Same stacking context and the z-index just below the root: tree order then keeps the
|
|
1422
1451
|
// root (the later sibling) on top, even when a site rule overrides our z-index.
|
|
1423
1452
|
_matchLayerZ(layer, root) {
|
|
1424
1453
|
try {
|
|
1425
1454
|
const z = (root.ownerDocument.defaultView || window).getComputedStyle(root).zIndex;
|
|
1426
|
-
|
|
1455
|
+
// One below the root (never level with it: some layouts then drew the glow on top).
|
|
1456
|
+
const want = /^-?\d+$/.test(z) ? String(Math.max(-2147483647, Number(z) - 1)) : '0';
|
|
1427
1457
|
if (layer.style.getPropertyValue('z-index') !== want) layer.style.setProperty('z-index', want, 'important');
|
|
1428
1458
|
} catch (_) { }
|
|
1429
1459
|
},
|
|
@@ -1640,7 +1670,12 @@
|
|
|
1640
1670
|
// The site moved the player: re-decorate the new ancestor chain, then the glow.
|
|
1641
1671
|
if (a.root.parentNode !== a.layer.parentNode) { const target = this.applied.target; this._clearApplied(); this._applyTarget(target); }
|
|
1642
1672
|
else this._startAmbient(a.video, a.root);
|
|
1643
|
-
} else if (a)
|
|
1673
|
+
} else if (a) {
|
|
1674
|
+
// The site may fade or blur its video later (e.g. once it starts playing).
|
|
1675
|
+
const why = this._seeThrough(a.video, a.root);
|
|
1676
|
+
if (why) { logDebug('Ambient light off for this player: ' + why, 'info'); this._stopAmbient(); }
|
|
1677
|
+
else this._matchLayerZ(a.layer, a.root);
|
|
1678
|
+
}
|
|
1644
1679
|
const root = this.applied.chain[0]?.root || this.applied.siteRoot;
|
|
1645
1680
|
if (root && (this.nexusControls() !== root.classList.contains('nxu-site-ui-off') || (this.nexusControls() && this.applied.video?.hasAttribute('controls')))) {
|
|
1646
1681
|
this._applySiteUi(root, this.applied.video);
|
|
@@ -5871,11 +5906,15 @@
|
|
|
5871
5906
|
this._startPeek();
|
|
5872
5907
|
} else if (op === 'snap' && (d.img === null || (typeof d.img === 'string' && d.img.startsWith('data:image/jpeg') && d.img.length < 90000))) {
|
|
5873
5908
|
this._peer = { uid: d.uid, name: who.name, color: who.color, img: d.img, t: Number(d.t) || 0, playing: !!d.playing, off: Number(d.off) || 0, at: Date.now() };
|
|
5909
|
+
this._checkPic(this._peer);
|
|
5874
5910
|
this.paint();
|
|
5875
5911
|
} else if (op === 'mark' && Number.isFinite(d.t)) {
|
|
5876
5912
|
this._marks.set(d.uid, { t: d.t, off: Number(d.off) || 0, name: who.name, color: who.color });
|
|
5877
5913
|
showToast(t('tuneMarkReceived', { name: who.name }));
|
|
5878
5914
|
this.paint();
|
|
5915
|
+
} else if (op === 'verdict' && (d.kind === 'same' || d.kind === 'shifted')) {
|
|
5916
|
+
const mine = this.mediaSig();
|
|
5917
|
+
if (mine && Number.isFinite(d.d) && Math.abs(mine.d - d.d) < 1.5 && !(d.kind === 'same' && (this._shiftSet || Math.abs(this.offset()) >= 0.6))) this._setVerdict(d.kind, false);
|
|
5879
5918
|
} else if (op === 'envreq') {
|
|
5880
5919
|
this._myEnv().then(env => { if (env) SOCIAL.send('tune', { op: 'env', ...this._pack(env), off: this.offset(), to: d.uid }); });
|
|
5881
5920
|
} else if (op === 'env' && d.to === STATE.userId && this._autoWait) {
|
|
@@ -5950,7 +5989,7 @@
|
|
|
5950
5989
|
}
|
|
5951
5990
|
return { t0, step, v: out };
|
|
5952
5991
|
},
|
|
5953
|
-
_correlate(me, them, maxLag) {
|
|
5992
|
+
_correlate(me, them, maxLag, dRef = null) {
|
|
5954
5993
|
// lag d (seconds): my content at time x equals theirs at time x − d.
|
|
5955
5994
|
const step = me.step;
|
|
5956
5995
|
let best = { score: -Infinity, d: 0 }, second = -Infinity;
|
|
@@ -5982,7 +6021,14 @@
|
|
|
5982
6021
|
const fin = scores.filter(Number.isFinite);
|
|
5983
6022
|
const mean = fin.reduce((s, x) => s + x, 0) / Math.max(1, fin.length);
|
|
5984
6023
|
const sd = Math.sqrt(fin.reduce((s, x) => s + (x - mean) ** 2, 0) / Math.max(1, fin.length)) || 1;
|
|
5985
|
-
|
|
6024
|
+
// How well the current alignment (lag dRef) matches: a repeating picture or sound
|
|
6025
|
+
// can peak at another lag just as well, which is no reason to shift.
|
|
6026
|
+
let ref = -Infinity;
|
|
6027
|
+
if (Number.isFinite(dRef)) {
|
|
6028
|
+
const rk = Math.round(dRef / step) + Math.round(maxLag / step);
|
|
6029
|
+
for (let k = rk - 2; k <= rk + 2; k++) if (Number.isFinite(scores[k]) && scores[k] > ref) ref = scores[k];
|
|
6030
|
+
}
|
|
6031
|
+
return { d: best.d, score: best.score, second, ref, z: (best.score - mean) / sd };
|
|
5986
6032
|
},
|
|
5987
6033
|
async auto({ silent = false } = {}) {
|
|
5988
6034
|
if (!PRESENCE.others().length) { if (!silent) { this._autoMsg = t('tuneNoPeer'); this.paint(); } return null; }
|
|
@@ -5998,16 +6044,16 @@
|
|
|
5998
6044
|
for (const luma of [false, true]) {
|
|
5999
6045
|
const a = this._series(mine, luma), b = this._series(theirs.env, luma);
|
|
6000
6046
|
if (!a || !b) continue;
|
|
6001
|
-
const r = this._correlate(a, b, 240);
|
|
6047
|
+
const r = this._correlate(a, b, 240, this.offset() - theirs.off);
|
|
6002
6048
|
if (Number.isFinite(r.score) && (!res || r.z > res.z)) res = r;
|
|
6003
6049
|
}
|
|
6004
|
-
logDebug(`Sync timing: compared ${mine.ts.length} / ${theirs.env.ts.length} samples → ${res ? `lag ${res.d.toFixed(1)}s, r=${res.score.toFixed(2)}, next ${res.second.toFixed(2)}, z=${res.z.toFixed(1)}` : 'nothing comparable'}`, 'info');
|
|
6050
|
+
logDebug(`Sync timing: compared ${mine.ts.length} / ${theirs.env.ts.length} samples → ${res ? `lag ${res.d.toFixed(1)}s, r=${res.score.toFixed(2)}, next ${res.second.toFixed(2)}, z=${res.z.toFixed(1)}, now ${Number.isFinite(res.ref) ? res.ref.toFixed(2) : '-'}` : 'nothing comparable'}`, 'info');
|
|
6005
6051
|
if (!res || !(res.score > 0.3) || !(res.z >= 4)) { if (!silent) { this._autoMsg = t('tuneAutoNone'); this._autoFound = null; this.paint(); } return null; }
|
|
6006
6052
|
// d: my content at time x = theirs at x − d. With both following the room, my
|
|
6007
6053
|
// offset must be theirs + d.
|
|
6008
6054
|
const want = Math.round((theirs.off + res.d) * 10) / 10;
|
|
6009
6055
|
const sure = Math.round(Math.min(0.99, Math.max(0.5, 0.5 + (res.z - 4) * 0.06 + (res.score - 0.3) * 0.4)) * 100);
|
|
6010
|
-
if (silent) return { want, sure, score: res.score, z: res.z };
|
|
6056
|
+
if (silent) return { want, sure, score: res.score, z: res.z, theirOff: theirs.off, ref: res.ref };
|
|
6011
6057
|
this._autoFound = want;
|
|
6012
6058
|
this._autoMsg = t('tuneAutoFound', { s: this.fmt(want), c: sure });
|
|
6013
6059
|
this.paint();
|
|
@@ -6028,7 +6074,69 @@
|
|
|
6028
6074
|
if (mine.d < 0 || others.some(m => m.d < 0)) return { kind: 'same' }; // live: one timeline
|
|
6029
6075
|
const diffs = others.map(m => mine.d - m.d);
|
|
6030
6076
|
const big = diffs.reduce((a, b) => (Math.abs(b) > Math.abs(a) ? b : a), 0);
|
|
6031
|
-
|
|
6077
|
+
if (Math.abs(big) >= 1.5) return { kind: 'different', diff: Math.round(big * 10) / 10 };
|
|
6078
|
+
// Equal length is not proof of the same video (another release can have the same
|
|
6079
|
+
// length and other scenes at the same time): the pictures and the timeline decide.
|
|
6080
|
+
const v = this._verdict;
|
|
6081
|
+
if ((v && v.d === mine.d && v.kind === 'shifted') || (this._picBad >= 3 && !(v && v.d === mine.d && v.kind === 'same'))) return { kind: 'shifted' };
|
|
6082
|
+
return { kind: 'same' };
|
|
6083
|
+
},
|
|
6084
|
+
_verdict: null, _picBad: 0, _verifyTries: 0, _lastVerify: 0,
|
|
6085
|
+
_setVerdict(kind, tell = true) {
|
|
6086
|
+
const mine = this.mediaSig();
|
|
6087
|
+
if (!mine || !(mine.d > 0)) return;
|
|
6088
|
+
const prev = this._verdict;
|
|
6089
|
+
this._verdict = { kind, d: mine.d };
|
|
6090
|
+
if (kind === 'same') this._picBad = 0;
|
|
6091
|
+
if (tell && SOCIAL.live() && (!prev || prev.kind !== kind || prev.d !== mine.d)) SOCIAL.send('tune', { op: 'verdict', kind, d: mine.d });
|
|
6092
|
+
this.paint();
|
|
6093
|
+
},
|
|
6094
|
+
// Two small pictures of what should be the same moment: alike or not? (16×9 brightness)
|
|
6095
|
+
async _picsDiffer(a, b) {
|
|
6096
|
+
const read = (src) => new Promise((resolve) => {
|
|
6097
|
+
const im = new Image();
|
|
6098
|
+
im.onload = () => {
|
|
6099
|
+
try {
|
|
6100
|
+
const c = document.createElement('canvas'); c.width = 16; c.height = 9;
|
|
6101
|
+
const cx = c.getContext('2d', { willReadFrequently: true });
|
|
6102
|
+
cx.drawImage(im, 0, 0, 16, 9);
|
|
6103
|
+
const d = cx.getImageData(0, 0, 16, 9).data, out = [];
|
|
6104
|
+
for (let i = 0; i < d.length; i += 4) out.push(d[i] * 0.3 + d[i + 1] * 0.59 + d[i + 2] * 0.11);
|
|
6105
|
+
resolve(out);
|
|
6106
|
+
} catch (_) { resolve(null); }
|
|
6107
|
+
};
|
|
6108
|
+
im.onerror = () => resolve(null);
|
|
6109
|
+
im.src = src;
|
|
6110
|
+
});
|
|
6111
|
+
const [x, y] = await Promise.all([read(a), read(b)]);
|
|
6112
|
+
if (!x || !y) return null;
|
|
6113
|
+
const n = x.length, mx = x.reduce((s, v) => s + v, 0) / n, my = y.reduce((s, v) => s + v, 0) / n;
|
|
6114
|
+
let sxy = 0, sxx = 0, syy = 0, mad = 0;
|
|
6115
|
+
for (let i = 0; i < n; i++) { const dx = x[i] - mx, dy = y[i] - my; sxy += dx * dy; sxx += dx * dx; syy += dy * dy; mad += Math.abs(x[i] - y[i]); }
|
|
6116
|
+
mad /= n;
|
|
6117
|
+
const flat = Math.sqrt(sxx / n) < 6 || Math.sqrt(syy / n) < 6; // black / plain frames say nothing
|
|
6118
|
+
if (flat) return mad > 40 ? true : null;
|
|
6119
|
+
const r = sxy / Math.sqrt(sxx * syy);
|
|
6120
|
+
if (r > 0.75 && mad < 30) return false;
|
|
6121
|
+
if (r < 0.35 && mad > 18) return true;
|
|
6122
|
+
return null;
|
|
6123
|
+
},
|
|
6124
|
+
// Their picture arrived: compare it with mine at the moment that should be the same
|
|
6125
|
+
// (after each one's own timing correction). Judged a few times before calling them different.
|
|
6126
|
+
async _checkPic(p) {
|
|
6127
|
+
if (this._picBusy || !p || !p.img || !p.playing) return;
|
|
6128
|
+
this._picBusy = true;
|
|
6129
|
+
try {
|
|
6130
|
+
const mine = await this._mySnap();
|
|
6131
|
+
if (!mine || !mine.img || !mine.playing) return;
|
|
6132
|
+
this._mine = this._mine && this._mine.at > mine.at ? this._mine : mine;
|
|
6133
|
+
const theirNow = (p.t || 0) + (Date.now() - p.at) / 1000;
|
|
6134
|
+
if (Math.abs(((mine.t || 0) - this.offset()) - (theirNow - (p.off || 0))) > 0.8) return;
|
|
6135
|
+
const bad = await this._picsDiffer(mine.img, p.img);
|
|
6136
|
+
if (bad === true) this._picBad = Math.min(6, this._picBad + 1);
|
|
6137
|
+
else if (bad === false) this._picBad = Math.max(0, this._picBad - 2);
|
|
6138
|
+
if (bad === true && this._picBad === 3) { this._lastVerify = 0; this.paint(); }
|
|
6139
|
+
} catch (_) { } finally { this._picBusy = false; }
|
|
6032
6140
|
},
|
|
6033
6141
|
// Only one device shifts its timing: the one with the longer version (extra intro), or
|
|
6034
6142
|
// with equal length the lowest id.
|
|
@@ -6041,10 +6149,63 @@
|
|
|
6041
6149
|
// Runs every few seconds in a room: same source → no shift (the room's own fine sync
|
|
6042
6150
|
// does the frame-level work); different versions → find the shift by itself.
|
|
6043
6151
|
_watchStart: 0, _tries: 0, _lastKind: '',
|
|
6152
|
+
// Equal length: compare what both played. The same timeline → confirmed; a clear
|
|
6153
|
+
// shift → the one device that adjusts sets it (and tells the others).
|
|
6154
|
+
async _verifyTick(src) {
|
|
6155
|
+
const v = this._verdict, mine = this.mediaSig();
|
|
6156
|
+
if (this._verifyFor !== mine.d + '|' + location.href) { this._verifyFor = mine.d + '|' + location.href; this._verifyTries = 0; this._picBad = 0; this._shiftSet = false; this._lastVerify = 0; this._prevVerify = null; this._picAsks = 0; }
|
|
6157
|
+
if (v && v.d === mine.d && v.kind === 'same') { if (this.offset() && !this._shiftSet) { this.set(0, { quiet: true }); showToast(t('tuneSameReset')); } return; }
|
|
6158
|
+
if (v && v.d === mine.d && v.kind === 'shifted' && this._shiftSet) return;
|
|
6159
|
+
const info = currentMediaInfo();
|
|
6160
|
+
if (!info || info.paused) return;
|
|
6161
|
+
const env = this._rec;
|
|
6162
|
+
if (!env && !STATE.cinemaIframe) { this.arm(true); return; }
|
|
6163
|
+
if (STATE.video && (!env || env.ts.length < 450)) return; // ~45 s of history first
|
|
6164
|
+
if (this._verifyTries >= 6 || Date.now() - this._lastVerify < (src.kind === 'shifted' ? 15000 : 40000)) return;
|
|
6165
|
+
this._lastVerify = Date.now();
|
|
6166
|
+
this._verifyTries++;
|
|
6167
|
+
this._autoBusy = true;
|
|
6168
|
+
try {
|
|
6169
|
+
const r = await this.auto({ silent: true });
|
|
6170
|
+
if (!r || !(r.score > 0.35 && r.z >= 6)) return;
|
|
6171
|
+
const shift = r.want - this.offset();
|
|
6172
|
+
// As they play now, the two already match about as well: nothing to shift.
|
|
6173
|
+
if (Math.abs(shift) >= 0.6 && Number.isFinite(r.ref) && r.ref > Math.max(0.25, r.score * 0.5)) { this._prevVerify = null; if (Math.abs(this.offset()) < 0.6 && Math.abs(r.theirOff || 0) < 0.6) this._setVerdict('same'); return; }
|
|
6174
|
+
// A shift is only believed when two comparisons in a row find the same one
|
|
6175
|
+
// (seeks and stalls can make a single one look shifted).
|
|
6176
|
+
if (Math.abs(shift) >= 0.6) {
|
|
6177
|
+
const prev = this._prevVerify;
|
|
6178
|
+
this._prevVerify = r;
|
|
6179
|
+
if (!prev || Math.abs(prev.want - r.want) > 0.5) { this._lastVerify = Date.now() - 25000; return; }
|
|
6180
|
+
// …and only when the pictures really differ: sound and brightness alone can
|
|
6181
|
+
// point elsewhere for the very same file. Ask for pictures and look again.
|
|
6182
|
+
if (this._picBad < 3) {
|
|
6183
|
+
if (SOCIAL.live() && (this._picAsks || 0) < 3 && Date.now() - (this._picAsked || 0) > 40000) { this._picAsked = Date.now(); this._picAsks = (this._picAsks || 0) + 1; SOCIAL.send('tune', { op: 'peek' }); }
|
|
6184
|
+
this._lastVerify = Date.now() - 25000;
|
|
6185
|
+
return;
|
|
6186
|
+
}
|
|
6187
|
+
}
|
|
6188
|
+
if (Math.abs(shift) < 0.6) {
|
|
6189
|
+
// Lined up: the same video only when nobody needed a correction for it.
|
|
6190
|
+
const corrected = Math.abs(this.offset()) >= 0.6 || Math.abs(r.theirOff || 0) >= 0.6;
|
|
6191
|
+
this._setVerdict(corrected ? 'shifted' : 'same');
|
|
6192
|
+
return;
|
|
6193
|
+
}
|
|
6194
|
+
this._setVerdict('shifted');
|
|
6195
|
+
if (!this._adjuster() || Math.abs(r.want) > this.LIMIT) return;
|
|
6196
|
+
const before = this.offset();
|
|
6197
|
+
this._shiftSet = true;
|
|
6198
|
+
this.set(r.want, { quiet: true });
|
|
6199
|
+
BUBBLES.show({ icon: '🎯', name: 'NexusSync', color: '#ffca28', text: t('tuneShiftFound', { s: this.fmt(r.want) }), key: 'tune-auto', ms: 12000, onTap: () => { this.set(before); } });
|
|
6200
|
+
} catch (_) { } finally { this._autoBusy = false; }
|
|
6201
|
+
},
|
|
6044
6202
|
async autoTick() {
|
|
6045
6203
|
if (!IS_TOP || !STATE.handshakeVerified || STATE.isReadOnly || this._autoBusy) return;
|
|
6046
6204
|
const src = this.source();
|
|
6047
6205
|
if (src.kind !== this._lastKind) { this._lastKind = src.kind; this._tries = 0; this.paint(); }
|
|
6206
|
+
const mineSig = this.mediaSig();
|
|
6207
|
+
const lengthSame = src.kind === 'same' || src.kind === 'shifted';
|
|
6208
|
+
if (lengthSame && mineSig && mineSig.d > 0) { await this._verifyTick(src); return; }
|
|
6048
6209
|
if (src.kind === 'same') {
|
|
6049
6210
|
if (this.offset()) { this.set(0, { quiet: true }); showToast(t('tuneSameReset')); }
|
|
6050
6211
|
return;
|
|
@@ -6103,7 +6264,7 @@
|
|
|
6103
6264
|
const off = this.offset();
|
|
6104
6265
|
const q = s => panel.querySelector(s);
|
|
6105
6266
|
const src = this.source();
|
|
6106
|
-
q('.tune-src').textContent = src.kind === 'same' ? t('tuneSrcSame') : src.kind === 'different' ? t('tuneSrcDiff', { s: this.fmt(src.diff) }) : t('tuneSrcUnknown');
|
|
6267
|
+
q('.tune-src').textContent = src.kind === 'same' ? t('tuneSrcSame') : src.kind === 'different' ? t('tuneSrcDiff', { s: this.fmt(src.diff) }) : src.kind === 'shifted' ? t('tuneSrcShifted') : t('tuneSrcUnknown');
|
|
6107
6268
|
q('.tune-src').dataset.kind = src.kind;
|
|
6108
6269
|
panel.querySelector('.tune-body').classList.toggle('same', src.kind === 'same');
|
|
6109
6270
|
q('.tune-off-val').textContent = this.fmt(off);
|
|
@@ -6130,7 +6291,7 @@
|
|
|
6130
6291
|
const mineNow = (this._mine.t || 0) + (this._mine.playing ? (Date.now() - (this._mine.at || Date.now())) / 1000 : 0);
|
|
6131
6292
|
const theirNow = (p.t || 0) + (p.playing ? (Date.now() - p.at) / 1000 : 0);
|
|
6132
6293
|
const d = Math.round((mineNow - theirNow) * 10) / 10;
|
|
6133
|
-
diffEl.textContent = Math.abs(d) < 0.3 ? t('tuneDiffSame') : t(d > 0 ? 'tuneDiffAhead' : 'tuneDiffBehind', { s: Math.abs(d).toFixed(1) + 's', name: p.name });
|
|
6294
|
+
diffEl.textContent = Math.abs(d) < 0.3 ? t(this._picBad >= 2 ? 'tuneDiffPicture' : 'tuneDiffSame') : t(d > 0 ? 'tuneDiffAhead' : 'tuneDiffBehind', { s: Math.abs(d).toFixed(1) + 's', name: p.name });
|
|
6134
6295
|
} else diffEl.textContent = '';
|
|
6135
6296
|
pic(q('.tune-pic.theirs'), p, p ? p.name : (PRESENCE.others().length ? participantName(PRESENCE.others()[0]) : '—'), !!PRESENCE.others().length);
|
|
6136
6297
|
const theirs = [...this._marks.values()].pop();
|
|
@@ -6807,15 +6968,15 @@
|
|
|
6807
6968
|
if (!pill && uiElements.uiWrapper) {
|
|
6808
6969
|
pill = createEl('div', 'presence-pill');
|
|
6809
6970
|
pill.id = 'nxu-presence-pill';
|
|
6810
|
-
|
|
6811
|
-
|
|
6812
|
-
pill.addEventListener('click', (e) => { e.stopPropagation(); pill.classList.toggle('open'); updatePresenceUI(); });
|
|
6971
|
+
// A plain row of names: a tap does nothing (it used to flip the row into a column).
|
|
6972
|
+
pill.addEventListener('click', (e) => e.stopPropagation());
|
|
6813
6973
|
uiElements.uiWrapper.appendChild(pill);
|
|
6814
6974
|
}
|
|
6815
6975
|
if (!pill) return;
|
|
6816
6976
|
const entries = Object.values(STATE.presenceMap);
|
|
6817
6977
|
if (entries.length && STATE.role !== 'IDLE') {
|
|
6818
|
-
renderRoster(pill,
|
|
6978
|
+
const list = renderRoster(pill, 3);
|
|
6979
|
+
pill.title = list.map(m => m.name).join(', ');
|
|
6819
6980
|
pill.style.display = '';
|
|
6820
6981
|
} else {
|
|
6821
6982
|
pill.style.display = 'none';
|
|
@@ -7813,10 +7974,8 @@
|
|
|
7813
7974
|
.nx-spark { position:absolute; font-size:13px; pointer-events:none; transform:translate(-50%,-50%); opacity:0; animation:nxSpark .7s cubic-bezier(.2,.7,.3,1) both; z-index:2100; }
|
|
7814
7975
|
@keyframes nxSpark { 0% { opacity:1; transform:translate(-50%,-50%) scale(.6); } 100% { opacity:0; transform:translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.05) rotate(var(--rot)); } }
|
|
7815
7976
|
@media (prefers-reduced-motion: reduce) { .react-btn.pop, .react-btn.pop::after, .nx-spark { animation:none !important; } }
|
|
7816
|
-
.presence-pill { position:absolute; display:flex; gap:3px; align-items:center; font-size:11px; padding:3px 4px; border-radius:99px; background:rgba(0,0,0,0.45); color:#e0e0e0; white-space:nowrap; pointer-events:auto; cursor:
|
|
7817
|
-
.presence-pill.open { flex-direction:column; align-items:stretch; border-radius:12px; padding:5px; max-height:50vh; overflow:auto; }
|
|
7977
|
+
.presence-pill { position:absolute; display:flex; gap:3px; align-items:center; font-size:11px; padding:3px 4px; border-radius:99px; background:rgba(0,0,0,0.45); color:#e0e0e0; white-space:nowrap; pointer-events:auto; cursor:default; max-width:min(78vw, 360px); overflow:hidden; }
|
|
7818
7978
|
.nx-who { display:inline-flex; align-items:center; gap:4px; padding:2px 7px 2px 5px; border-radius:99px; background:rgba(255,255,255,0.1); font-size:11.5px; font-weight:600; line-height:1.3; max-width:140px; color:rgba(255,255,255,0.92); text-shadow:0 1px 2px rgba(0,0,0,0.6); }
|
|
7819
|
-
.presence-pill.open .nx-who { max-width:none; }
|
|
7820
7979
|
.nx-who.me { background:rgba(255,255,255,0.18); }
|
|
7821
7980
|
.nx-who.away { opacity:0.55; }
|
|
7822
7981
|
.nx-who.warn { background:rgba(255,170,0,0.28); }
|
|
@@ -7942,7 +8101,7 @@
|
|
|
7942
8101
|
.tune-body { gap:7px; }
|
|
7943
8102
|
.tune-src { padding:8px 10px; border-radius:10px; font-size:12.5px; font-weight:700; background:rgba(255,255,255,0.08); }
|
|
7944
8103
|
.tune-src[data-kind="same"] { background:rgba(0,230,118,0.16); }
|
|
7945
|
-
.tune-src[data-kind="different"] { background:rgba(255,202,40,0.18); }
|
|
8104
|
+
.tune-src[data-kind="different"], .tune-src[data-kind="shifted"] { background:rgba(255,202,40,0.18); }
|
|
7946
8105
|
/* Same source: the room's own frame-level sync does it all; the version tools step back. */
|
|
7947
8106
|
.tune-ver { display:flex; flex-direction:column; gap:7px; }
|
|
7948
8107
|
.tune-body.same .tune-ver { display:none; }
|
package/package.json
CHANGED