File tree Expand file tree Collapse file tree 2 files changed +16
-12
lines changed
Expand file tree Collapse file tree 2 files changed +16
-12
lines changed Original file line number Diff line number Diff line change @@ -15,15 +15,13 @@ export default function useWebsocket(
1515 const intervalTime = 1000 / batchesPerSecond ;
1616
1717 const normalizeBatch = ( batch : any ) => {
18- const { time, signals } = batch ;
19-
20- return [ {
18+ return batch . timestamps . map ( ( time : number , i : number ) => ( {
2119 time,
22- signal1 : signals [ 0 ] ,
23- signal2 : signals [ 1 ] ,
24- signal3 : signals [ 2 ] ,
25- signal4 : signals [ 3 ] ,
26- } ] ;
20+ signal1 : batch . signals [ 0 ] [ i ] ,
21+ signal2 : batch . signals [ 1 ] [ i ] ,
22+ signal3 : batch . signals [ 2 ] [ i ] ,
23+ signal4 : batch . signals [ 3 ] [ i ] ,
24+ } ) ) ;
2725 } ;
2826
2927 useEffect ( ( ) => {
Original file line number Diff line number Diff line change 1+ const { time } = require ( 'console' ) ;
12const WebSocket = require ( 'ws' ) ;
23
34const wss = new WebSocket . Server ( { port : 8080 } ) ;
@@ -6,11 +7,16 @@ wss.on('connection', (ws) => {
67 console . log ( 'New client connected' ) ;
78
89 const interval = setInterval ( ( ) => {
10+
11+ const timestamps = Array . from ( { length : 20 } , ( _ , i ) =>
12+ Date . now ( ) + i * 3
13+ ) ;
14+ const signals = Array . from ( { length : 4 } , ( ) =>
15+ Array . from ( { length : 65 } , ( ) => Math . floor ( Math . random ( ) * 100 ) )
16+ ) ;
917 const data = {
10- time : Date . now ( ) , // Using milliseconds since epoch for time
11- signals : Array . from ( { length : 5 } , ( ) =>
12- Math . floor ( Math . random ( ) * 100 )
13- ) , // Random values for 5 brain regions
18+ timestamps,
19+ signals,
1420 } ;
1521
1622 ws . send ( JSON . stringify ( data ) ) ;
You can’t perform that action at this time.
0 commit comments