1- import { type Component , createMemo , onCleanup , Show } from "solid-js" ;
1+ import { type Component , createMemo , Show } from "solid-js" ;
22
33import { Layout } from "./components/layout/layout" ;
44import Sidebar from "./components/layout/sidebar" ;
@@ -12,56 +12,6 @@ export const App: Component = () => {
1212 const [ store , actions ] = useStore ( ) ;
1313 const { toast } = useToast ( ) ;
1414
15- // Fix iOS Safari WebSocket hanging bug using alternating RAF/setTimeout pattern
16- // Source - https://stackoverflow.com/a/42036303
17- // iOS has a bug where rapid WebSocket sends during pointer events can hang the connection
18- // Solution: alternate between requestAnimationFrame and setTimeout to break the pattern
19- let scheduledId : number | undefined ;
20- let pendingLedData : { index : number ; status : number } | null = null ;
21- let useRaf = true ;
22- let frametime = 0 ;
23- let lastframe = Date . now ( ) ;
24-
25- const deferredLedSend = ( data : { index : number ; status : number } ) => {
26- pendingLedData = data ;
27-
28- if ( scheduledId ) return ;
29-
30- const sendLed = ( ) => {
31- frametime = Date . now ( ) - lastframe ;
32- lastframe = Date . now ( ) ;
33-
34- if ( pendingLedData ) {
35- actions . send (
36- JSON . stringify ( {
37- event : "led" ,
38- ...pendingLedData ,
39- } ) ,
40- ) ;
41- pendingLedData = null ;
42- }
43-
44- scheduledId = undefined ;
45- useRaf = ! useRaf ;
46- } ;
47-
48- if ( useRaf ) {
49- scheduledId = requestAnimationFrame ( sendLed ) ;
50- } else {
51- scheduledId = setTimeout ( sendLed , Math . max ( 0 , frametime ) ) as unknown as number ;
52- }
53- } ;
54-
55- onCleanup ( ( ) => {
56- if ( scheduledId ) {
57- if ( useRaf ) {
58- cancelAnimationFrame ( scheduledId ) ;
59- } else {
60- clearTimeout ( scheduledId ) ;
61- }
62- }
63- } ) ;
64-
6515 const rotatedMatrix = createMemo ( ( ) => rotateArray ( store . indexMatrix , store . rotation ) ) ;
6616
6717 const wsMessage = (
@@ -177,7 +127,7 @@ export const App: Component = () => {
177127 indexData = { rotatedMatrix ( ) }
178128 brightness = { store . brightness ?? 255 }
179129 onSetLed = { ( data ) => {
180- deferredLedSend ( data ) ;
130+ wsMessage ( "led" , data ) ;
181131 } }
182132 onSetMatrix = { ( data ) => {
183133 actions ?. setLeds ( [ ...data ] ) ;
0 commit comments