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 @@ -25,15 +25,13 @@ export default function useWebsocket(
2525 }
2626 }
2727 const normalizeBatch = ( batch : any ) => {
28- const { time, signals } = batch ;
29-
30- return [ {
28+ return batch . timestamps . map ( ( time : number , i : number ) => ( {
3129 time,
32- signal1 : signals [ 0 ] ,
33- signal2 : signals [ 1 ] ,
34- signal3 : signals [ 2 ] ,
35- signal4 : signals [ 3 ] ,
36- } ] ;
30+ signal1 : batch . signals [ 0 ] [ i ] ,
31+ signal2 : batch . signals [ 1 ] [ i ] ,
32+ signal3 : batch . signals [ 2 ] [ i ] ,
33+ signal4 : batch . signals [ 3 ] [ i ] ,
34+ } ) ) ;
3735 } ;
3836
3937 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