@@ -27,66 +27,67 @@ module.exports = class POTASpots extends events.EventEmitter {
2727
2828 //continuously poll POTA API, determine new spots and emit those to event listeners
2929 async run ( opts = { } ) {
30- while ( true ) {
31-
32- //Wait for the polling interval
33- await sleepNow ( this . potapollinterval * 1000 ) ;
34-
35- //cache variable
36- let spots = [ ] ;
37-
38- //Try to get data from POTA API
39- try {
40-
41- //fetch api response, 10s timeout
42- const response = await fetch ( 'https://api.pota.app/spot/activator' , { signal : AbortSignal . timeout ( 10000 ) } ) ;
43- if ( ! response . ok ) throw new Error ( 'HTTP error' ) ;
44-
45- //get json from response
46- let rawspots = await response . json ( ) ;
47-
48- //iterate through each spot
49- rawspots . forEach ( ( item , index ) => {
50-
51- // build POTA spot
52- let dxSpot = {
53- spotter : item . spotter ,
54- spotted : item . activator ,
55- frequency : item . frequency ,
56- message : item . mode + ( item . mode != '' ? " " : "" ) + "POTA @ " + item . reference + " " + item . name + " (" + item . locationDesc + ")" ,
57- when : new Date ( ) ,
58- additional_data : {
59- pota_ref : item . reference ,
60- pota_mode : item . mode
61- }
62-
63- }
64-
65- //put spots inside of array to build new
66- spots . push ( dxSpot ) ;
67-
68- //check if the same spot (excluding "when") exists in cache
69- //use an allowed deviation on frequency to catch multiple spots by RBN or PSK-Reporter for FT8, FT4 and CW modes
70- let isNewSpot = ! this . potaspotcache . some ( existingSpot =>
71- existingSpot . spotted === dxSpot . spotted &&
72- Math . abs ( existingSpot . frequency - dxSpot . frequency ) <= this . getalloweddeviation ( item . mode ) &&
73- existingSpot . message === dxSpot . message
74- ) ;
75-
76- //emit spot to event listeners
77- if ( isNewSpot )
78- {
79- this . emit ( 'spot' , dxSpot )
80- }
81- } ) ;
82-
83- //set the potacache to the current state, effectively deleting all old spots
84- this . potaspotcache = spots ;
85-
86- } catch ( error ) {
87- //log error to console
88- console . error ( 'Fetch failed:' , error ) ;
89- }
90- }
30+ while ( true ) {
31+
32+ //Wait for the polling interval
33+ await sleepNow ( this . potapollinterval * 1000 ) ;
34+
35+ //cache variable
36+ let spots = [ ] ;
37+
38+ //Try to get data from POTA API
39+ try {
40+
41+ //fetch api response, 10s timeout
42+ const response = await fetch ( 'https://api.pota.app/spot/activator' , { signal : AbortSignal . timeout ( 10000 ) } ) ;
43+ if ( ! response . ok ) throw new Error ( 'HTTP error' ) ;
44+
45+ //get json from response
46+ let rawspots = await response . json ( ) ;
47+
48+ //iterate through each spot
49+ rawspots . forEach ( ( item , index ) => {
50+ // build POTA spot
51+ let dxSpot = {
52+ spotter : item . spotter ,
53+ spotted : item . activator ,
54+ frequency : item . frequency ,
55+ message : item . mode + ( item . mode != '' ? " " : "" ) + "POTA @ " + item . reference + " " + item . name + " (" + item . locationDesc + ")" ,
56+ when : new Date ( ) ,
57+ additional_data : {
58+ pota_ref : item . reference ,
59+ pota_mode : item . mode
60+ }
61+
62+ }
63+
64+ if ( ! isNaN ( item . frequency ) ) { // ignore POTA-Spots without (valid) frequency
65+ //put spots inside of array to build new
66+ spots . push ( dxSpot ) ;
67+
68+ //check if the same spot (excluding "when") exists in cache
69+ //use an allowed deviation on frequency to catch multiple spots by RBN or PSK-Reporter for FT8, FT4 and CW modes
70+ let isNewSpot = ! this . potaspotcache . some ( existingSpot =>
71+ existingSpot . spotted === dxSpot . spotted &&
72+ Math . abs ( existingSpot . frequency - dxSpot . frequency ) <= this . getalloweddeviation ( item . mode ) &&
73+ existingSpot . message === dxSpot . message
74+ ) ;
75+
76+ //emit spot to event listeners
77+ if ( isNewSpot )
78+ {
79+ this . emit ( 'spot' , dxSpot )
80+ }
81+ }
82+ } ) ;
83+
84+ //set the potacache to the current state, effectively deleting all old spots
85+ this . potaspotcache = spots ;
86+
87+ } catch ( error ) {
88+ //log error to console
89+ console . error ( 'Fetch failed:' , error ) ;
90+ }
91+ }
9192 }
9293} ;
0 commit comments