atmosx-nwws-parser 1.0.182 → 1.0.184

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.182",
3
+ "version": "1.0.184",
4
4
  "description": "NOAA Weather Wire Parser",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/events.js CHANGED
@@ -172,11 +172,11 @@ 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(getTempIssue)}],
175
+ history: [{description: getDescription, action: vtec.status, issued: 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),
179
- sent: new Date(vtec.issued) == `Invalid Date` ? getTempIssue ? new Date(getTempIssue) : new Date(vtec.issued) : new Date(vtec.issued),
179
+ sent: new Date(vtec.issued) == `Invalid Date` ? getTempIssue : new Date(vtec.issued),
180
180
  messageType: vtec.status,
181
181
  event: vtec.event || `Unknown Event`,
182
182
  sender: senderOffice,
@@ -227,20 +227,22 @@ class NoaaWeatherWireServiceEvents {
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
229
  let getThreat = loader.packages.mText.getString(msg, `DAMAGE THREAT...`);
230
- let getTempIssue = loader.packages.mText.getString(msg, `ISSUED TIME...`) || new Date();
230
+ let getTempIssue = loader.packages.mText.getString(msg, `ISSUED TIME...`);
231
231
  let senderOffice = loader.packages.mText.getOffice(msg) || `NWS`;
232
232
  let getCoordinates = loader.packages.mText.getPolygonCoordinates(msg);
233
233
  let getDescription = loader.packages.mText.getCleanDescription(msg, null);
234
+ let issuedDate = new Date(stanza.attributes.issue) == `Invalid Date` ? getTempIssue : new Date(stanza.attributes.issue);
234
235
  let alert = {
235
236
  hitch: `${new Date().getTime() - startTime}ms`,
236
237
  id: `Wire-${defaultWMO ? defaultWMO[0] : `N/A`}-${mUgc.zones.join(`-`)}`,
237
238
  tracking: `${defaultWMO ? defaultWMO[0] : `N/A`}-${mUgc.zones.join(`-`)}`,
238
239
  action: `Issued`,
239
- history: [{description: getDescription, action: `Issued`, issued: new Date(getTempIssue)}],
240
+ history: [{description: getDescription, action: `Issued`, issued: getTempIssue}],
240
241
  properties: {
241
242
  areaDesc: mUgc.locations.join(`; `) || `N/A`,
242
- expires: new Date(new Date().getTime() + 1 * 60 * 60 * 1000),
243
- sent: new Date(getTempIssue) == `Invalid Date` ? new Date(stanza.attributes.issue) : new Date(getTempIssue),
243
+ // expieres is based off issuedDate
244
+ expires: new Date(issuedDate.getTime() + 1 * 60 * 60 * 1000),
245
+ sent: issuedDate,
244
246
  messageType: `Issued`,
245
247
  event: `Special Weather Statement`,
246
248
  sender: senderOffice,