@sansavision/create-pulse 0.1.0-alpha.10 → 0.1.0-alpha.12
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/package.json
CHANGED
|
@@ -69,12 +69,39 @@ export default function App() {
|
|
|
69
69
|
|
|
70
70
|
const broadcastAction = useCallback((action: string, time: number) => {
|
|
71
71
|
logEvent(`SEND: ${action} @ ${time.toFixed(2)}s`);
|
|
72
|
-
const
|
|
72
|
+
const sendTs = Date.now();
|
|
73
|
+
const msg = { action, time, ts: sendTs };
|
|
73
74
|
broadcast(msg);
|
|
74
75
|
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
//
|
|
76
|
+
// Single-tab simulation: defer peerTime update by the measured relay
|
|
77
|
+
// round-trip so that drift is visible and realistic. In a real
|
|
78
|
+
// multi-tab setup the relay echo handler (handleSyncMessage) updates
|
|
79
|
+
// peerTime — but since the relay does not echo back to the sender,
|
|
80
|
+
// we simulate it here with the actual measured delay.
|
|
81
|
+
const simulatedDelay = delayHistoryRef.current.length > 0
|
|
82
|
+
? delayHistoryRef.current[delayHistoryRef.current.length - 1]
|
|
83
|
+
: 4; // sensible default ~4ms first message
|
|
84
|
+
|
|
85
|
+
setTimeout(() => {
|
|
86
|
+
if (action === 'tick') {
|
|
87
|
+
setPeerTime(time);
|
|
88
|
+
} else if (action === 'play') {
|
|
89
|
+
setIsPlaying(true);
|
|
90
|
+
setPeerTime(time);
|
|
91
|
+
} else if (action === 'pause') {
|
|
92
|
+
setIsPlaying(false);
|
|
93
|
+
setPeerTime(time);
|
|
94
|
+
} else if (action === 'seek') {
|
|
95
|
+
setPeerTime(time);
|
|
96
|
+
}
|
|
97
|
+
}, simulatedDelay);
|
|
98
|
+
|
|
99
|
+
// Measure delay after the event loop processes the send
|
|
100
|
+
setTimeout(() => {
|
|
101
|
+
const delay = Date.now() - sendTs;
|
|
102
|
+
setLastDelay(delay);
|
|
103
|
+
delayHistoryRef.current = [...delayHistoryRef.current.slice(-29), delay];
|
|
104
|
+
}, 0);
|
|
78
105
|
}, [broadcast, logEvent]);
|
|
79
106
|
|
|
80
107
|
// Computed delay stats
|
|
@@ -207,7 +207,13 @@ export function GameSync({ useChannel, logEvent }: GameSyncProps) {
|
|
|
207
207
|
// Send to peers
|
|
208
208
|
broadcast(payload);
|
|
209
209
|
|
|
210
|
-
// Delay is measured in handleSyncMessage when the relay echoes back
|
|
210
|
+
// Delay is measured in handleSyncMessage when the relay echoes back.
|
|
211
|
+
// Also measure locally via deferred setTimeout for single-tab demos.
|
|
212
|
+
setTimeout(() => {
|
|
213
|
+
const delay = Date.now() - sendTs;
|
|
214
|
+
setLastDelay(delay);
|
|
215
|
+
delayHistoryRef.current = [...delayHistoryRef.current.slice(-29), delay];
|
|
216
|
+
}, 0);
|
|
211
217
|
|
|
212
218
|
// Interpolate fallback for when broadcast doesn't echo locally fast enough
|
|
213
219
|
const rv = remoteViewRef.current;
|
|
@@ -101,7 +101,12 @@ export function ServerMetrics({ useChannel, logEvent }: ServerMetricsProps) {
|
|
|
101
101
|
// Normally the server does this, here we do it so the demo "just works" locally
|
|
102
102
|
broadcast(fakeMetrics);
|
|
103
103
|
|
|
104
|
-
//
|
|
104
|
+
// Measure delay via deferred setTimeout for single-tab demos
|
|
105
|
+
setTimeout(() => {
|
|
106
|
+
const delay = Date.now() - sendTs;
|
|
107
|
+
setLastDelay(delay);
|
|
108
|
+
delayHistoryRef.current = [...delayHistoryRef.current.slice(-29), delay];
|
|
109
|
+
}, 0);
|
|
105
110
|
}, 1000);
|
|
106
111
|
|
|
107
112
|
return () => clearInterval(interval);
|
|
@@ -77,12 +77,40 @@ export default function App() {
|
|
|
77
77
|
|
|
78
78
|
const broadcastAction = useCallback((action: string, time: number) => {
|
|
79
79
|
logEvent(`SEND: ${action} @ ${time.toFixed(2)}s`);
|
|
80
|
-
const
|
|
80
|
+
const sendTs = Date.now();
|
|
81
|
+
const msg = { action, time, ts: sendTs };
|
|
81
82
|
broadcast(msg);
|
|
82
83
|
|
|
83
|
-
//
|
|
84
|
-
//
|
|
85
|
-
//
|
|
84
|
+
// Single-tab simulation: defer peerTime update by the measured relay
|
|
85
|
+
// round-trip so that drift is visible and realistic. In a real
|
|
86
|
+
// multi-tab setup the relay echo handler (handleSyncMessage) updates
|
|
87
|
+
// peerTime — but since the relay does not echo back to the sender,
|
|
88
|
+
// we simulate it here with the actual measured delay.
|
|
89
|
+
const simulatedDelay = delayHistoryRef.current.length > 0
|
|
90
|
+
? delayHistoryRef.current[delayHistoryRef.current.length - 1]
|
|
91
|
+
: 4; // sensible default ~4ms first message
|
|
92
|
+
|
|
93
|
+
setTimeout(() => {
|
|
94
|
+
if (action === 'tick') {
|
|
95
|
+
setPeerTime(time);
|
|
96
|
+
} else if (action === 'play') {
|
|
97
|
+
setIsPlaying(true);
|
|
98
|
+
setPeerTime(time);
|
|
99
|
+
} else if (action === 'pause') {
|
|
100
|
+
setIsPlaying(false);
|
|
101
|
+
setPeerTime(time);
|
|
102
|
+
} else if (action === 'seek') {
|
|
103
|
+
setPeerTime(time);
|
|
104
|
+
}
|
|
105
|
+
}, simulatedDelay);
|
|
106
|
+
|
|
107
|
+
// Measure delay after the event loop processes the send (captures
|
|
108
|
+
// real serialization + WebSocket write time, not synchronous 0).
|
|
109
|
+
setTimeout(() => {
|
|
110
|
+
const delay = Date.now() - sendTs;
|
|
111
|
+
setLastDelay(delay);
|
|
112
|
+
delayHistoryRef.current = [...delayHistoryRef.current.slice(-29), delay];
|
|
113
|
+
}, 0);
|
|
86
114
|
}, [broadcast, logEvent]);
|
|
87
115
|
|
|
88
116
|
const handleQualityChange = useCallback((quality: typeof QUALITY_OPTIONS[0]) => {
|