1- import  {  map ,  distinctUntilChanged ,  takeUntil ,  mergeScan  }  from  'rxjs/operators' 
2- import  {  maybe ,   reader ,   IMaybe   }  from  'typescript-monads ' 
1+ import  {  map ,  distinctUntilChanged ,  takeUntil ,  mergeScan ,   flatMap  }  from  'rxjs/operators' 
2+ import  {  timer ,   Observable ,   forkJoin ,   combineLatest   }  from  'rxjs ' 
33import  {  IProbeConfig ,  DEFAULT_CONFIG  }  from  './config' 
4- import  {  timer ,   Observable ,   forkJoin  }  from  'rxjs ' 
5- import  {  parseXmlResponse  }  from  './parse' 
4+ import  {  maybe ,   reader ,   IMaybe  }  from  'typescript-monads ' 
5+ import  {  parseXmlResponse ,   maybeIpAddress  }  from  './parse' 
66import  {  socketStream  }  from  './socket-stream' 
77import  {  probePayload  }  from  './probe-payload' 
88import  {  IONVIFDevice  }  from  './device' 
99export  {  IProbeConfig  }  from  './config' 
1010import  {  MD5  }  from  'object-hash' 
1111import  {  ping  }  from  'ping-rx' 
12+ import  {  ipscan  }  from  './ipscan' 
1213export  {  IONVIFDevice  } 
1314export  {  DEFAULT_CONFIG  } 
1415
@@ -42,7 +43,7 @@ export const probeONVIFDevices = () => reader<Partial<IProbeConfig>, ProbeStream
4243      buffers . forEach ( b  =>  ss . socket . send ( b ,  0 ,  b . length ,  config . PORT ,  config . MULTICAST_ADDRESS ) ) 
4344    } ) 
4445
45-   return  socketMessages 
46+   const   onvifScan   =  socketMessages 
4647    . pipe ( 
4748      map ( xmlResponse  =>  xmlResponse 
4849        . map ( xmlString  =>  config . DOM_PARSER . parseFromString ( xmlString ,  'application/xml' ) ) 
@@ -59,6 +60,29 @@ export const probeONVIFDevices = () => reader<Partial<IProbeConfig>, ProbeStream
5960            ] ) ) ) 
6061      } ,  [ ] ) , 
6162      distinctUntilChanged ( ( a ,  b )  =>  MD5 ( a )  ===  MD5 ( b ) ) ) 
63+ 
64+   const  ipScan  =  ( )  =>  timer ( config . PROBE_SAMPLE_START_DELAY_TIME_MS ,  config . PROBE_SAMPLE_TIME_MS ) . pipe ( flatMap ( ( )  =>  ipscan ( ) ) ) 
65+ 
66+   return  ! config . ENABLE_IP_SCANNING 
67+     ? onvifScan 
68+     : combineLatest ( onvifScan ,  ipScan ( ) ,  ( onvifResults ,  ipscanResults )  =>  { 
69+       const  ipDevicesNotInOnvifScan  =  ipscanResults . filter ( a  =>  ! onvifResults . some ( onv  =>  onv . ip  ===  maybeIpAddress ( a ) . valueOrUndefined ( ) ) ) 
70+         . map < IONVIFDevice > ( deviceServiceUri  =>  { 
71+           return  { 
72+             deviceServiceUri, 
73+             name : maybeIpAddress ( deviceServiceUri ) . valueOr ( config . NOT_FOUND_STRING ) , 
74+             hardware : config . NOT_FOUND_STRING , 
75+             location : config . NOT_FOUND_STRING , 
76+             ip : config . NOT_FOUND_STRING , 
77+             metadataVersion : config . NOT_FOUND_STRING , 
78+             urn : config . NOT_FOUND_STRING , 
79+             scopes : [ ] , 
80+             profiles : [ ] , 
81+             xaddrs : [ ] 
82+           } 
83+         } ) 
84+       return  [ ...onvifResults ,  ...ipDevicesNotInOnvifScan ] 
85+     } ) . pipe ( distinctUntilChanged ( ( a ,  b )  =>  MD5 ( a )  ===  MD5 ( b ) ) ) 
6286} ) 
6387
6488export  const  startProbingONVIFDevices  =  ( )  =>  probeONVIFDevices ( ) . run ( { } ) 
@@ -69,4 +93,7 @@ export const startProbingONVIFDevicesCli = () => startProbingONVIFDevices()
6993    console . log ( 'Watching for connected ONVIF devices...' ,  '\n' ) 
7094    console . log ( v ) 
7195  } ) 
72-   
96+ 
97+ probeONVIFDevices ( ) . run ( { 
98+   ENABLE_IP_SCANNING : true 
99+ } ) . subscribe ( console . log ) 
0 commit comments