@@ -19,8 +19,9 @@ import {
1919} from "rsocket-core" ;
2020import { Encoders } from "rsocket-core/RSocketEncoding" ;
2121import Protocol from "devtools-protocol" ;
22- import { action , makeObservable , observable } from "mobx" ;
22+ import { action , makeObservable , observable , computed } from "mobx" ;
2323import { observer } from "mobx-react-lite" ;
24+ import { Index , IndexSearchResult } from "flexsearch" ;
2425import WebSocketFrameReceivedEvent = Protocol . Network . WebSocketFrameReceivedEvent ;
2526import WebSocketFrameSentEvent = Protocol . Network . WebSocketFrameSentEvent ;
2627import WebSocketFrame = Protocol . Network . WebSocketFrame ;
@@ -282,6 +283,7 @@ interface WsConnectionState {
282283 id : string ,
283284 url ?: string ,
284285 frames : WsFrameState [ ] ;
286+ index : Index ;
285287 activeFrame ?: number
286288}
287289
@@ -293,12 +295,16 @@ export class AppStateStore {
293295 issueWallTime ?: number = undefined ;
294296 connections = new Map < string , WsConnectionState > ( ) ;
295297 activeConnection ?: string = undefined ;
298+ searchValue : string = "" ;
296299
297300 constructor ( handlers : ChromeHandlers ) {
298301 makeObservable ( this , {
299302 connections : observable ,
300303 activeConnection : observable ,
301304 selectConnection : action . bound ,
305+ search : action . bound ,
306+ searchValue : observable ,
307+ searchResult : computed ,
302308 frameSent : action . bound ,
303309 frameReceived : action . bound ,
304310 webSocketCreated : action . bound ,
@@ -320,6 +326,8 @@ export class AppStateStore {
320326 return ;
321327 }
322328 connection . frames = [ ]
329+ connection . index = new Index ( { tokenize : "full" } )
330+ this . searchValue = ""
323331 }
324332
325333 selectFrame ( id ?: number ) {
@@ -337,6 +345,24 @@ export class AppStateStore {
337345 this . activeConnection = value ;
338346 }
339347
348+ search ( value : string ) {
349+ this . searchValue = value ;
350+ }
351+
352+ get searchResult ( ) : IndexSearchResult {
353+ if ( ! this . activeConnection ) {
354+ return [ ]
355+ }
356+
357+ const connection = this . connections . get ( this . activeConnection ) ;
358+ if ( ! connection ) {
359+ return [ ]
360+ }
361+
362+ const result = connection . index . search ( this . searchValue ) ;
363+ return result
364+ }
365+
340366 webSocketCreated ( event : WebSocketCreatedEvent ) {
341367 const { requestId, url} = event ;
342368 if ( this . connections . get ( requestId ) ) {
@@ -347,6 +373,7 @@ export class AppStateStore {
347373 id : requestId ,
348374 url : url ,
349375 frames : [ ] ,
376+ index : new Index ( { tokenize : "full" } ) ,
350377 activeFrame : undefined ,
351378 } ) ;
352379 }
@@ -376,7 +403,9 @@ export class AppStateStore {
376403 frame . binary = stringToBuffer ( response . payloadData ) ;
377404 }
378405 const connection = this . ensureConnection ( requestId ) ;
406+ const rSocketFrame = tryDeserializeFrame ( frame . payload ) ;
379407 connection . frames . push ( frame )
408+ connection . index . add ( frame . id , ( rSocketFrame as any ) ?. data ?? frame . text ?? frame . payload )
380409 this . activeConnection = requestId ;
381410 }
382411 }
@@ -389,6 +418,7 @@ export class AppStateStore {
389418 const newConnection = {
390419 id : requestId ,
391420 frames : [ ] ,
421+ index : new Index ( { tokenize : "full" } ) ,
392422 activeFrame : undefined ,
393423 }
394424 this . connections . set ( requestId , newConnection ) ;
@@ -405,7 +435,7 @@ export class AppStateStore {
405435}
406436
407437export const App = observer ( ( { store} : { store : AppStateStore } ) => {
408- const { connections, activeConnection} = store ;
438+ const { connections, activeConnection, searchValue , searchResult } = store ;
409439 if ( ! activeConnection ) {
410440 return < div > No active WebSocket connections</ div >
411441 }
@@ -415,9 +445,10 @@ export const App = observer(({store}: { store: AppStateStore }) => {
415445 }
416446 const { frames, activeFrame} = connection ;
417447 const active = frames . find ( f => f . id === activeFrame ) ;
448+ const filteredFrames = searchResult . length ? frames . filter ( ( frame ) => searchResult . includes ( frame . id ) ) : frames ;
418449
419- const Row = ( { index, style, data } : ListChildComponentProps ) => {
420- const frame = data [ index ] ;
450+ const Row = ( { index, style } : ListChildComponentProps ) => {
451+ const frame = filteredFrames [ index ] ;
421452
422453 return (
423454 < FrameEntry
@@ -450,12 +481,19 @@ export const App = observer(({store}: { store: AppStateStore }) => {
450481 </ option > )
451482 }
452483 </ select >
484+ < input
485+ type = "text"
486+ placeholder = "Search frame..."
487+ style = { { width : "100%" } }
488+ value = { searchValue }
489+ onChange = { e => store . search ( e . target . value ) }
490+ />
453491 </ div >
454492
455493 < div className = "frame-list" >
456494 < AutoSizer disableWidth >
457495 { ( { height } ) => (
458- < FixedSizeList height = { height } width = "100%" itemCount = { frames . length } itemSize = { 18 } innerElementType = "ul" >
496+ < FixedSizeList height = { height } width = "100%" itemCount = { filteredFrames . length } itemSize = { 18 } innerElementType = "ul" >
459497 { Row }
460498 </ FixedSizeList >
461499 ) }
0 commit comments