atmosx-nwws-parser 1.0.181 → 1.0.183

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bootstrap.js CHANGED
@@ -103,6 +103,7 @@ module.exports.settings = {
103
103
  module.exports.cache = {
104
104
  lastStanza: new Date().getTime(),
105
105
  session: null,
106
+ sigHault: false,
106
107
  isConnected: false,
107
108
  attemptingReconnect: false,
108
109
  totalReconnects: 0
package/index.js CHANGED
@@ -135,8 +135,10 @@ class NoaaWeatherWireServiceCore {
135
135
  await loader.static.session.stop().catch(() => {});
136
136
  await loader.static.session.start().catch(() => {});
137
137
  }, 2 * 1000);
138
+ loader.cache.sigHault = true;
138
139
  throw new Error(`rapid-reconnect`);
139
140
  }
141
+ loader.cache.sigHault = false;
140
142
  loader.static.lastConnect = new Date().getTime();
141
143
  loader.cache.isConnected = true;
142
144
  loader.static.session.send(loader.packages.xmpp.xml('presence', { to: `nwws@conference.nwws-oi.weather.gov/${this.metadata.authentication.display}`, xmlns: 'http://jabber.org/protocol/muc' }))
@@ -147,11 +149,12 @@ class NoaaWeatherWireServiceCore {
147
149
  }
148
150
  })
149
151
  loader.static.session.on(`offline`, () => {
150
- loader.static.session.stop().catch(() => {});
151
152
  loader.cache.isConnected = false;
153
+ loader.cache.sigHault = true;
152
154
  throw new Error(`unreachable-host`);
153
155
  })
154
156
  loader.static.session.on(`error`, async (error) => {
157
+ loader.cache.sigHault = true;
155
158
  throw new Error(error.message || `service-error`);
156
159
  })
157
160
  loader.static.session.on(`stanza`, (stanza) => {
@@ -182,7 +185,7 @@ class NoaaWeatherWireServiceCore {
182
185
  */
183
186
 
184
187
  isReconnectEligible = async function(minSeconds=60) {
185
- if (loader.cache.isConnected && loader.static.session) {
188
+ if ((loader.cache.isConnected || loader.cache.sigHault == true) && loader.static.session) {
186
189
  let lastStanza = new Date().getTime() - loader.cache.lastStanza;
187
190
  if (lastStanza > minSeconds * 1000) {
188
191
  if (!loader.cache.attemptingReconnect) {
@@ -190,8 +193,8 @@ class NoaaWeatherWireServiceCore {
190
193
  loader.cache.isConnected = false;
191
194
  loader.cache.totalReconnects += 1;
192
195
  loader.static.events.emit(`onReconnect`, { reconnects: loader.cache.totalReconnects, lastStanza: lastStanza / 1000, lastName: this.metadata.authentication.display});
193
- await loader.static.session.stop().catch(() => {});
194
- await loader.static.session.start().catch(() => {});
196
+ await loader.static.session.stop().catch(() => {})
197
+ await loader.static.session.start().catch(() => {})
195
198
  }
196
199
  }
197
200
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "atmosx-nwws-parser",
3
- "version": "1.0.181",
3
+ "version": "1.0.183",
4
4
  "description": "NOAA Weather Wire Parser",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/events.js CHANGED
@@ -172,7 +172,7 @@ class NoaaWeatherWireServiceEvents {
172
172
  id: `Wire-${vtec.tracking}`,
173
173
  tracking: vtec.tracking,
174
174
  action: vtec.status,
175
- history: [{description: getDescription, action: vtec.status, issued: new Date(vtec.issued)}],
175
+ history: [{description: getDescription, action: vtec.status, issued: new Date(getTempIssue)}],
176
176
  properties: {
177
177
  areaDesc: mUgc.locations.join(`; `) || `N/A`,
178
178
  expires: new Date(vtec.expires) == `Invalid Date` ? new Date(9999, 0, 1) : new Date(vtec.expires),
@@ -226,20 +226,23 @@ class NoaaWeatherWireServiceEvents {
226
226
  let getTornado = loader.packages.mText.getString(msg, `TORNADO...`) || loader.packages.mText.getString(msg, `WATERSPOUT...`)
227
227
  let getHail = loader.packages.mText.getString(msg, `MAX HAIL SIZE...`, [`IN`]) || loader.packages.mText.getString(msg, `HAIL...`, [`IN`]);
228
228
  let getGusts = loader.packages.mText.getString(msg, `MAX WIND GUST...`) || loader.packages.mText.getString(msg, `WIND...`);
229
- let getThreat = loader.packages.mText.getString(msg, `DAMAGE THREAT...`);
229
+ let getThreat = loader.packages.mText.getString(msg, `DAMAGE THREAT...`);
230
+ let getTempIssue = loader.packages.mText.getString(msg, `ISSUED TIME...`);
230
231
  let senderOffice = loader.packages.mText.getOffice(msg) || `NWS`;
231
232
  let getCoordinates = loader.packages.mText.getPolygonCoordinates(msg);
232
233
  let getDescription = loader.packages.mText.getCleanDescription(msg, null);
234
+ let issuedDate = new Date(stanza.attributes.issue) == `Invalid Date` ? getTempIssue ? new Date(getTempIssue) : new Date(stanza.attributes.issue) : new Date(stanza.attributes.issue);
233
235
  let alert = {
234
236
  hitch: `${new Date().getTime() - startTime}ms`,
235
237
  id: `Wire-${defaultWMO ? defaultWMO[0] : `N/A`}-${mUgc.zones.join(`-`)}`,
236
238
  tracking: `${defaultWMO ? defaultWMO[0] : `N/A`}-${mUgc.zones.join(`-`)}`,
237
239
  action: `Issued`,
238
- history: [{description: getDescription, action: `Issued`, issued: new Date(stanza.attributes.issue)}],
240
+ history: [{description: getDescription, action: `Issued`, issued: new Date(getTempIssue)}],
239
241
  properties: {
240
242
  areaDesc: mUgc.locations.join(`; `) || `N/A`,
241
- expires: new Date(new Date().getTime() + 1 * 60 * 60 * 1000),
242
- sent: new Date(stanza.attributes.issue),
243
+ // expieres is based off issuedDate
244
+ expires: new Date(issuedDate.getTime() + 1 * 60 * 60 * 1000),
245
+ sent: issuedDate,
243
246
  messageType: `Issued`,
244
247
  event: `Special Weather Statement`,
245
248
  sender: senderOffice,