@atmosx/event-product-parser 3.0.4 → 3.0.7
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/{CONTRIBUTING.md → .github/CONTRIBUTING.md} +1 -1
- package/.github/SUPPORTED_EVENTS.md +370 -0
- package/.github/docs/docs-functions.md +30 -0
- package/.github/docs/docs-general-configurations.md +199 -0
- package/.github/docs/docs-integrations.md +38 -0
- package/.github/docs/docs-listeners.md +28 -0
- package/.github/docs/docs-source-configuration.md +218 -0
- package/.github/docs/docs-technical.md +50 -0
- package/.github/logo.png +0 -0
- package/.github/samples/SAMPLE_EAS_GENERATION.wav +0 -0
- package/.github/samples/SAMPLE_GEOJSON.json +204 -0
- package/.github/samples/SAMPLE_TEXT_PRODUCT.txt +119 -0
- package/README.md +157 -337
- package/dist/cjs/index.cjs +24125 -15815
- package/dist/esm/index.mjs +24144 -15839
- package/package.json +56 -53
- package/pnpm-workspace.yaml +4 -0
- package/src/bootstrap.ts +83 -43
- package/src/building/CreateEvent.ts +54 -0
- package/src/{@building/building.clean.ts → building/GetCleanedEvent.ts} +4 -4
- package/src/building/GetEventAttachments.ts +88 -0
- package/src/building/GetEventDirection.ts +28 -0
- package/src/{@building/building.enhance.ts → building/GetEventEnhancedName.ts} +13 -17
- package/src/{@building/building.geometry.ts → building/GetEventGeometry.ts} +19 -13
- package/src/{@building/building.headers.ts → building/GetEventHeader.ts} +13 -13
- package/src/{@building/building.polygon.ts → building/GetEventNodes.ts} +26 -22
- package/src/{@building/building.office.ts → building/GetEventOffice.ts} +14 -14
- package/src/building/GetEventProperties.ts +105 -0
- package/src/{@building/building.signature.ts → building/GetEventSignature.ts} +16 -17
- package/src/{@core/core.createListener.ts → building/GetEventTags.ts} +11 -6
- package/src/building/GetEventTheme.ts +26 -0
- package/src/building/GetEventTracking.ts +64 -0
- package/src/components/audio/GenerateAudioMessage.ts +149 -0
- package/src/components/audio/components/GetCleanDescription.ts +91 -0
- package/src/{@modules/@eas/eas.getFloatPCM16.ts → components/audio/components/GetFloatPCM16.ts} +3 -3
- package/src/{@modules/@eas/eas.getMergedPCM16.ts → components/audio/components/GetMergedPCM16.ts} +3 -3
- package/src/{@modules/@eas/eas.getPCM16.ts → components/audio/components/GetPCM16.ts} +13 -8
- package/src/{@modules/@eas/eas.getPCMToFloat.ts → components/audio/components/GetPCMToFloat.ts} +3 -3
- package/src/{@modules/@eas/eas.getSampledPCM16.ts → components/audio/components/GetSampledPCM16.ts} +14 -8
- package/src/components/audio/components/GetTTS.ts +61 -0
- package/src/{@modules/@eas/eas.getWavPCM16.ts → components/audio/components/GetWavPCM16.ts} +8 -8
- package/src/{@modules/@eas/eas.setAFSK.ts → components/audio/components/SetAFSK.ts} +12 -8
- package/src/{@modules/@eas/eas.setAsciiToBits.ts → components/audio/components/SetAsciiToBits.ts} +3 -4
- package/src/{@modules/@eas/eas.setAttentionTone.ts → components/audio/components/SetAttentionTone.ts} +11 -6
- package/src/{@modules/@eas/eas.setNoise.ts → components/audio/components/SetNoise.ts} +14 -8
- package/src/{@modules/@eas/eas.setRadioEffect.ts → components/audio/components/SetRadioEffect.ts} +14 -8
- package/src/{@modules/@eas/eas.setSameHeader.ts → components/audio/components/SetSameHeader.ts} +22 -15
- package/src/{@modules/@utilities/utilities.setWarning.ts → components/database/CreateQuery.ts} +18 -13
- package/src/{@modules/@database/database.cache.ts → components/database/GetCachedEvents.ts} +19 -14
- package/src/components/database/ImportBoundaries.ts +168 -0
- package/src/components/database/ImportBroadcastify.ts +60 -0
- package/src/components/database/ImportCities.ts +87 -0
- package/src/{@modules/@database/database.shapefiles.ts → components/database/ImportShapefiles.ts} +31 -37
- package/src/components/database/ImportStanza.ts +43 -0
- package/src/components/database/InitializeDatabase.ts +71 -0
- package/src/components/images/GenerateGraphic.ts +234 -0
- package/src/components/images/components/CreateRectangle.ts +22 -0
- package/src/components/images/components/CreateText.ts +22 -0
- package/src/components/images/modules/CreateSVG.ts +37 -0
- package/src/components/images/modules/GetGeographicalBoundaries.ts +72 -0
- package/src/components/images/modules/GetGeographicalCities.ts +58 -0
- package/src/components/images/modules/GetGeographicalEvents.ts +48 -0
- package/src/components/images/modules/GetGeometryBounds.ts +82 -0
- package/src/components/images/modules/GetParsedBoundary.ts +58 -0
- package/src/components/images/modules/GetSVGPath.ts +53 -0
- package/src/components/images/modules/NormalizePolygon.ts +57 -0
- package/src/{@modules/@stanza/stanza.getAwipsType.ts → components/stanza/GetAwipsType.ts} +19 -18
- package/src/components/stanza/ValidateStanza.ts +62 -0
- package/src/components/utilities/CreateHttp.ts +83 -0
- package/src/{@modules/@utilities/utilities.getFormattedTime.ts → components/utilities/GetFormattedTime.ts} +3 -3
- package/src/components/utilities/GetLatestIssuance.ts +32 -0
- package/src/components/utilities/GetMatched.ts +38 -0
- package/src/{@modules/@utilities/utilities.getShapeNearestPoint.ts → components/utilities/GetShapeNearestPoint.ts} +24 -19
- package/src/components/utilities/GetUnionPolygon.ts +36 -0
- package/src/components/utilities/QueueManager.ts +70 -0
- package/src/components/utilities/SetCronSchedule.ts +98 -0
- package/src/{@core/core.clearEvents.ts → components/utilities/SetDebug.ts} +17 -12
- package/src/components/utilities/SetEventEmit.ts +42 -0
- package/src/{@modules/@utilities/utilities.setSettings.ts → components/utilities/SetSettings.ts} +7 -7
- package/src/{@modules/@utilities/utilities.setSleep.ts → components/utilities/SetSleep.ts} +5 -5
- package/src/components/utilities/SetTimeoutAction.ts +64 -0
- package/src/components/utilities/SetWarning.ts +47 -0
- package/src/{@modules/@xmpp/xmpp.xDeploy.ts → components/xmpp/DeployXMPP.ts} +26 -27
- package/src/components/xmpp/ErrorXMPP.ts +27 -0
- package/src/{@modules/@xmpp/xmpp.xError.ts → components/xmpp/OfflineXMPP.ts} +17 -9
- package/src/{@modules/@xmpp/xmpp.xOnline.ts → components/xmpp/OnlineXMPP.ts} +21 -20
- package/src/components/xmpp/ReconnectXMPP.ts +64 -0
- package/src/components/xmpp/StanzaXMPP.ts +63 -0
- package/src/{@building/building.tags.ts → core/ClearEvents.ts} +12 -5
- package/src/{@core/core.getVersion.ts → core/GetEvents.ts} +5 -6
- package/src/core/GetNodes.ts +24 -0
- package/src/{@core/core.getNodes.ts → core/GetRandomEvent.ts} +5 -6
- package/src/core/GetVersion.ts +24 -0
- package/src/core/ManualEvent.ts +55 -0
- package/src/core/QueryStanza.ts +40 -0
- package/src/core/SetNode.ts +87 -0
- package/src/core/StartService.ts +62 -0
- package/src/core/StopService.ts +32 -0
- package/src/enums/AWIPS.ts +366 -0
- package/src/{@dictionaries/dictionaries.eventActions.ts → enums/Actions.ts} +3 -3
- package/src/{@dictionaries/dictionaries.eventCancelMessages.ts → enums/Cancellation.ts} +4 -3
- package/src/{@dictionaries/dictionaries.eventCauses.ts → enums/Causes.ts} +3 -3
- package/src/{@dictionaries/dictionaries.statusCorrelationText.ts → enums/Correlations.ts} +3 -3
- package/src/enums/Enhanced.ts +70 -0
- package/src/{@dictionaries/dictionaries.eventTypes.ts → enums/Events.ts} +3 -3
- package/src/{@dictionaries/dictionaries.regExp.ts → enums/Expressions.ts} +5 -4
- package/src/{@core/core.getEvents.ts → enums/GlobalFilter.ts} +7 -8
- package/src/{@dictionaries/dictionaries.hailStrings.ts → enums/Hail.ts} +9 -4
- package/src/{@dictionaries/dictionaries.officeICAOs.ts → enums/ICAO.ts} +5 -3
- package/src/enums/Matches.ts +60 -0
- package/src/{@dictionaries/dictionaries.eventProducts.ts → enums/Products.ts} +3 -3
- package/src/{@dictionaries/dictionaries.eventRecords.ts → enums/Records.ts} +3 -3
- package/src/{@dictionaries/dictionaries.eventSeverity.ts → enums/Severity.ts} +3 -3
- package/src/{@dictionaries/dictionaries.shapefileLinks.ts → enums/Shapefiles.ts} +3 -3
- package/src/enums/States.ts +136 -0
- package/src/{@dictionaries/dictionaries.eventStatus.ts → enums/Status.ts} +3 -3
- package/src/enums/Strings.ts +22 -0
- package/src/enums/Tags.ts +172 -0
- package/src/{@dictionaries/dictionaries.testSignatures.ts → enums/Testing.ts} +5 -4
- package/src/enums/Themes.ts +70 -0
- package/src/events/ParseAPI.ts +129 -0
- package/src/{@events/events.text.ts → events/ParseText.ts} +32 -23
- package/src/{@events/events.ugc.ts → events/ParseUGC.ts} +36 -26
- package/src/events/ParseVTEC.ts +88 -0
- package/src/index.ts +60 -38
- package/src/manager/MakeEvents.ts +110 -0
- package/src/manager/RemoveEvent.ts +74 -0
- package/src/{@manager/manager.setHash.ts → manager/SetHash.ts} +19 -15
- package/src/manager/UpdateEvents.ts +35 -0
- package/src/manager/UpdateNode.ts +62 -0
- package/src/manager/ValidateEvents.ts +144 -0
- package/src/{@parsers/@hvtec/hvtec.extract.ts → parsers/hvtec/HVExtract.ts} +13 -13
- package/src/parsers/text/GetDescriptionFromProduct.ts +59 -0
- package/src/parsers/text/GetEmbededText.ts +57 -0
- package/src/parsers/text/GetPolygonFromProduct.ts +71 -0
- package/src/parsers/text/GetStringText.ts +58 -0
- package/src/{@parsers/@text/text.getTextFromProduct.ts → parsers/text/GetTextFromProduct.ts} +12 -12
- package/src/parsers/ugc/GetCache.ts +24 -0
- package/src/{@parsers/@ugc/ugc.expiry.ts → parsers/ugc/GetExpiry.ts} +3 -3
- package/src/{@parsers/@ugc/ugc.header.ts → parsers/ugc/GetHeader.ts} +6 -6
- package/src/parsers/ugc/GetLocations.ts +57 -0
- package/src/parsers/ugc/GetZonePolygon.ts +73 -0
- package/src/{@parsers/@ugc/ugc.zones.ts → parsers/ugc/GetZones.ts} +3 -3
- package/src/{@modules/@utilities/utilities.setListener.ts → parsers/ugc/SetCache.ts} +13 -10
- package/src/{@parsers/@ugc/ugc.extract.ts → parsers/ugc/UGCExtract.ts} +15 -15
- package/src/{@parsers/@pvtec/pvtec.expires.ts → parsers/vtec/GetExpiry.ts} +3 -3
- package/src/parsers/vtec/VTECExtract.ts +49 -0
- package/src/{@types/types.attributes.ts → static/Attributes.ts} +2 -3
- package/src/{@types/type.event.ts → static/Event.ts} +11 -8
- package/src/{@types/type.properties.ts → static/Properties.ts} +17 -10
- package/src/{@types/types.stanza.ts → static/Stanza.ts} +2 -2
- package/src/tasks/CreateTasks.ts +123 -0
- package/src/{@core/core.stop.ts → tasks/TaskGenerateJSON.ts} +14 -12
- package/src/tasks/TaskGenerateText.ts +34 -0
- package/src/tasks/TaskSendNTFY.ts +97 -0
- package/src/tasks/TaskSendWebhook.ts +107 -0
- package/src/types/Actions.ts +37 -0
- package/src/{@types/types.hvtec.ts → types/HVTEC.ts} +6 -6
- package/src/{@types/types.hash.ts → types/Hash.ts} +5 -5
- package/src/types/Nodes.ts +29 -0
- package/src/{@types/types.settings.ts → types/Settings.ts} +42 -10
- package/src/{@types/types.compiled.ts → types/StanzaCompiled.ts} +15 -14
- package/src/{@types/types.ugc.ts → types/UGC.ts} +5 -5
- package/src/{@modules/@utilities/utilities.getSettings.ts → types/VTEC.ts} +12 -7
- package/tools/build.js +47 -0
- package/tsconfig.json +28 -1
- package/dist/index.d.mts +0 -239
- package/dist/index.d.ts +0 -239
- package/src/@building/building.create.ts +0 -42
- package/src/@building/building.properties.ts +0 -89
- package/src/@building/building.tracking.ts +0 -68
- package/src/@building/building.validate.ts +0 -147
- package/src/@core/core.getRandomEvent.ts +0 -25
- package/src/@core/core.setNode.ts +0 -81
- package/src/@core/core.start.ts +0 -61
- package/src/@dictionaries/dictionaries.betterEventNames.ts +0 -99
- package/src/@dictionaries/dictionaries.eventAwipAbreviations.ts +0 -364
- package/src/@dictionaries/dictionaries.eventTags.ts +0 -93
- package/src/@dictionaries/dictionaries.eventsMatchText.ts +0 -36
- package/src/@dictionaries/dictionaries.transcribedMessageReplacements.ts +0 -68
- package/src/@events/events.api.ts +0 -113
- package/src/@events/events.vtec.ts +0 -87
- package/src/@manager/manager.mkEvent.ts +0 -96
- package/src/@manager/manager.rmEvent.ts +0 -49
- package/src/@manager/manager.updateEvents.ts +0 -35
- package/src/@manager/manager.updateNodes.ts +0 -55
- package/src/@manager/manager.updateWebhooks.ts +0 -50
- package/src/@modules/@database/database.init.ts +0 -45
- package/src/@modules/@database/database.stanza.ts +0 -48
- package/src/@modules/@eas/eas.setEasTone.ts +0 -137
- package/src/@modules/@stanza/stanza.validate.ts +0 -50
- package/src/@modules/@utilities/utilities.createHttp.ts +0 -85
- package/src/@modules/@utilities/utilities.createWebhook.ts +0 -115
- package/src/@modules/@utilities/utilities.setCronSchedule.ts +0 -65
- package/src/@modules/@utilities/utilities.setEventEmit.ts +0 -41
- package/src/@modules/@utilities/utilities.setTimeoutAction.ts +0 -59
- package/src/@modules/@xmpp/xmpp.xOffline.ts +0 -38
- package/src/@modules/@xmpp/xmpp.xReconnect.ts +0 -64
- package/src/@modules/@xmpp/xmpp.xStanza.ts +0 -63
- package/src/@parsers/@pvtec/pvtec.extract.ts +0 -49
- package/src/@parsers/@text/text.getDescriptionFromProduct.ts +0 -53
- package/src/@parsers/@text/text.getPolygonFromProduct.ts +0 -32
- package/src/@parsers/@text/text.getXML.ts +0 -61
- package/src/@parsers/@ugc/ugc.coordinates.ts +0 -110
- package/src/@parsers/@ugc/ugc.locations.ts +0 -29
- package/src/@types/types.pvtec.ts +0 -30
- package/src/@types/types.webhook.ts +0 -27
- package/test.js +0 -91
- package/tsup.config.ts +0 -16
- /package/{CODE_OF_CONDUCT.md → .github/CODE_OF_CONDUCT.md} +0 -0
- /package/{LICENSE → .github/LICENSE} +0 -0
- /package/{SECURITY.md → .github/SECURITY.md} +0 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ _ _ __ __
|
|
3
|
+
/\ | | | | (_) \ \ / /
|
|
4
|
+
/ \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
|
|
5
|
+
/ /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
|
|
6
|
+
/ ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
|
|
7
|
+
/_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
|
|
8
|
+
| |
|
|
9
|
+
|_|
|
|
10
|
+
|
|
11
|
+
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
|
+
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
|
+
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
|
+
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { TypeSettings } from "Types/Settings"
|
|
22
|
+
import { ReconnectXMPP } from "@XMPP/ReconnectXMPP"
|
|
23
|
+
import { Bootstrap } from "@Bootstrap"
|
|
24
|
+
import { CreateHttp } from "@Utilities/CreateHttp"
|
|
25
|
+
import { SetEventEmit } from "@Utilities/SetEventEmit"
|
|
26
|
+
import { CreateEvent } from "@Building/CreateEvent"
|
|
27
|
+
import { readdirSync, unlinkSync, statSync, rmdirSync, existsSync } from "fs"
|
|
28
|
+
import { join } from "path"
|
|
29
|
+
|
|
30
|
+
export const SetCronSchedule = async (): Promise<void> => {
|
|
31
|
+
const settings = Bootstrap.Settings as TypeSettings;
|
|
32
|
+
|
|
33
|
+
const TTL = settings.GlobalSettings.ArchiveSettings.TTL
|
|
34
|
+
const TTLCUT = Date.now() - TTL * 1000;
|
|
35
|
+
|
|
36
|
+
const walk = (dir: string, deleteFolder?: boolean): void => {
|
|
37
|
+
if (existsSync(dir)) {
|
|
38
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
39
|
+
for (const entry of entries) {
|
|
40
|
+
const fullPath = join(dir, entry.name);
|
|
41
|
+
if (entry.isDirectory()) { walk(fullPath, deleteFolder); continue; }
|
|
42
|
+
const stats = statSync(fullPath);
|
|
43
|
+
if (stats.mtime.getTime() < TTLCUT) {
|
|
44
|
+
try {
|
|
45
|
+
unlinkSync(fullPath);
|
|
46
|
+
} catch (err) {
|
|
47
|
+
console.error(`Failed to delete ${fullPath}:`, err);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (deleteFolder && readdirSync(dir).length === 0) {
|
|
51
|
+
rmdirSync(dir);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
walk(settings.GlobalSettings.ArchiveSettings.TextDirectory)
|
|
57
|
+
walk(settings.GlobalSettings.ArchiveSettings.AudioDirectory)
|
|
58
|
+
walk(settings.GlobalSettings.ArchiveSettings.JSONDirectory)
|
|
59
|
+
walk(settings.GlobalSettings.ArchiveSettings.ImageDirectory, true)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
if (settings.EnableWireService) {
|
|
64
|
+
if (settings.NOAAWeatherWireServiceSettings.ReconnectionSettings.Enabled) {
|
|
65
|
+
void ReconnectXMPP(settings.NOAAWeatherWireServiceSettings.ReconnectionSettings.ReconnectionInterval)
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
const response = await CreateHttp({
|
|
69
|
+
URL: settings.NationalWeatherServiceSettings.EventsEndpoint,
|
|
70
|
+
Headers: {
|
|
71
|
+
"User-Agent": "@atmosx/event-product-parser"
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
if (response.error) {
|
|
75
|
+
return SetEventEmit({
|
|
76
|
+
Event: `onServiceStatus`,
|
|
77
|
+
Metadata: {
|
|
78
|
+
type: "fetch-api",
|
|
79
|
+
message: `Failed to fetch latest events from National Weather Service API - ${response.message}`,
|
|
80
|
+
data: {},
|
|
81
|
+
error: true
|
|
82
|
+
},
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
SetEventEmit({
|
|
86
|
+
Event: `onServiceStatus`,
|
|
87
|
+
Metadata: {
|
|
88
|
+
Message: `Fetched latest events from National Weather Service API`,
|
|
89
|
+
Data: {},
|
|
90
|
+
Type: "fetch-api",
|
|
91
|
+
Error: false
|
|
92
|
+
},
|
|
93
|
+
})
|
|
94
|
+
await CreateEvent({ Message: response.message, NWWS: false })
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
|
|
@@ -11,22 +11,27 @@
|
|
|
11
11
|
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
12
|
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
13
|
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
-
Documentation:
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
17
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
20
|
+
import { TypeSettings } from "Types/Settings"
|
|
21
|
+
import { Bootstrap } from "@Bootstrap"
|
|
22
22
|
|
|
23
|
+
interface SetDebugOptions {
|
|
24
|
+
Title?: string
|
|
25
|
+
Message: string
|
|
26
|
+
}
|
|
23
27
|
|
|
24
|
-
export const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
metadata: bootstrap.cache.events,
|
|
30
|
-
message: `Manually cleared event cache.`
|
|
28
|
+
export const SetDebug = ({ Title, Message }: SetDebugOptions): void => {
|
|
29
|
+
const settings = Bootstrap.Settings as TypeSettings;
|
|
30
|
+
Bootstrap.Listener.emit(`debug`, {
|
|
31
|
+
message: Message,
|
|
32
|
+
function: Title ?? `debug`,
|
|
31
33
|
})
|
|
32
|
-
|
|
34
|
+
if (settings.EnableDebugging) {
|
|
35
|
+
console.log(`[${Bootstrap.Colors.Blue}${Title ?? `debug`}${Bootstrap.Colors.Reset}] ${Message}`)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ _ _ __ __
|
|
3
|
+
/\ | | | | (_) \ \ / /
|
|
4
|
+
/ \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
|
|
5
|
+
/ /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
|
|
6
|
+
/ ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
|
|
7
|
+
/_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
|
|
8
|
+
| |
|
|
9
|
+
|_|
|
|
10
|
+
|
|
11
|
+
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
|
+
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
|
+
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
|
+
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
|
+
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { Bootstrap } from "@Bootstrap"
|
|
21
|
+
import { SetTimeoutAction } from "@Utilities/SetTimeoutAction"
|
|
22
|
+
import { SetWarning } from "@Utilities/SetWarning"
|
|
23
|
+
|
|
24
|
+
interface SetEventEmitOptions {
|
|
25
|
+
Event: string
|
|
26
|
+
Metadata: any
|
|
27
|
+
Message?: string
|
|
28
|
+
Limited?: boolean
|
|
29
|
+
Tree?: string[]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const SetEventEmit = ({ Event, Metadata, Message, Limited, Tree }: SetEventEmitOptions): void => {
|
|
33
|
+
if (Limited) {
|
|
34
|
+
const isTimeout = SetTimeoutAction({ Identifier: `event.${Event}`, AddTime: true, Max: 1, Interval: 1 })
|
|
35
|
+
if (isTimeout.Limited) return;
|
|
36
|
+
}
|
|
37
|
+
Bootstrap.Listener.emit(Event, Metadata)
|
|
38
|
+
if (Event != `log`) { Bootstrap.Listener.emit(`*`, {event: Event, data: Metadata}) }
|
|
39
|
+
if (Message) {
|
|
40
|
+
SetWarning({ Message: Message, Tree: Tree })
|
|
41
|
+
}
|
|
42
|
+
}
|
package/src/{@modules/@utilities/utilities.setSettings.ts → components/utilities/SetSettings.ts}
RENAMED
|
@@ -11,17 +11,17 @@
|
|
|
11
11
|
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
12
|
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
13
|
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
-
Documentation:
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
17
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
import { TypeSettings } from
|
|
21
|
-
import {
|
|
20
|
+
import { TypeSettings } from "Types/Settings"
|
|
21
|
+
import { Bootstrap } from "@Bootstrap"
|
|
22
22
|
|
|
23
|
-
export const
|
|
24
|
-
const settings =
|
|
23
|
+
export const SetSettings = (imported: TypeSettings): TypeSettings => {
|
|
24
|
+
const settings = Bootstrap.Settings as Record<string, unknown>;
|
|
25
25
|
const merge = (target: Record<string, unknown>, source: Record<string, unknown>) => {
|
|
26
26
|
for (const key in source) {
|
|
27
27
|
if (!Object.prototype.hasOwnProperty.call(source, key)) continue;
|
|
@@ -37,6 +37,6 @@ export const setSettings = (newSettings: TypeSettings): TypeSettings => {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
|
-
merge(settings,
|
|
40
|
+
merge(settings, imported as Record<string, unknown>);
|
|
41
41
|
return settings as TypeSettings;
|
|
42
42
|
}
|
|
@@ -11,22 +11,22 @@
|
|
|
11
11
|
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
12
|
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
13
|
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
-
Documentation:
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
interface SetSleepOptions {
|
|
22
|
-
|
|
22
|
+
Timeout: number
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export const
|
|
25
|
+
export const SetSleep = async ({ Timeout }: SetSleepOptions): Promise<void> => {
|
|
26
26
|
return new Promise((resolve) => {
|
|
27
27
|
setTimeout(() => {
|
|
28
28
|
resolve();
|
|
29
|
-
},
|
|
29
|
+
}, Timeout);
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ _ _ __ __
|
|
3
|
+
/\ | | | | (_) \ \ / /
|
|
4
|
+
/ \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
|
|
5
|
+
/ /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
|
|
6
|
+
/ ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
|
|
7
|
+
/_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
|
|
8
|
+
| |
|
|
9
|
+
|_|
|
|
10
|
+
|
|
11
|
+
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
|
+
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
|
+
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
|
+
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
|
+
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { Bootstrap } from "@Bootstrap"
|
|
21
|
+
|
|
22
|
+
interface SetTimeoutActionOptions {
|
|
23
|
+
Identifier: string
|
|
24
|
+
AddTime?: boolean
|
|
25
|
+
Max?: number
|
|
26
|
+
Interval?: number
|
|
27
|
+
Expire?: boolean
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type SetTimeoutActionResponse = {
|
|
31
|
+
Limited: boolean
|
|
32
|
+
Remaining?: number
|
|
33
|
+
Response?: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const SetTimeoutAction = ({ Identifier, AddTime, Max, Interval, Expire }: SetTimeoutActionOptions): SetTimeoutActionResponse => {
|
|
37
|
+
let target = Bootstrap?.Ratelimits?.[Identifier];
|
|
38
|
+
if (!target) {
|
|
39
|
+
Bootstrap.Ratelimits[Identifier] = [];
|
|
40
|
+
target = Bootstrap.Ratelimits[Identifier];
|
|
41
|
+
}
|
|
42
|
+
if (Expire) {
|
|
43
|
+
delete Bootstrap.Ratelimits[Identifier];
|
|
44
|
+
return { Limited: false };
|
|
45
|
+
}
|
|
46
|
+
if (target?.length > 0) {
|
|
47
|
+
Bootstrap.Ratelimits[Identifier] = target.filter((ts: number) => Date.now() - ts < Interval * 1000);
|
|
48
|
+
target = Bootstrap.Ratelimits[Identifier];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const oldestTimestamp = target?.[0];
|
|
52
|
+
const getWait = oldestTimestamp ? Math.ceil((Interval * 1000) - (Date.now() - oldestTimestamp)) : 0;
|
|
53
|
+
const max = Max ?? 1;
|
|
54
|
+
|
|
55
|
+
if (target?.length >= max && getWait > 0) {
|
|
56
|
+
return {
|
|
57
|
+
Limited: true,
|
|
58
|
+
Remaining: getWait,
|
|
59
|
+
Response: `You are being rate limited, please wait ${(getWait / 1e3).toFixed(1)} second(s) before performing this action again.`
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
Bootstrap.Ratelimits[Identifier].push(Date.now());
|
|
63
|
+
return { Limited: false };
|
|
64
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ _ _ __ __
|
|
3
|
+
/\ | | | | (_) \ \ / /
|
|
4
|
+
/ \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
|
|
5
|
+
/ /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
|
|
6
|
+
/ ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
|
|
7
|
+
/_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
|
|
8
|
+
| |
|
|
9
|
+
|_|
|
|
10
|
+
|
|
11
|
+
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
|
+
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
|
+
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
|
+
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
|
+
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { Bootstrap } from "@Bootstrap"
|
|
21
|
+
import { TypeSettings } from "Types/Settings"
|
|
22
|
+
|
|
23
|
+
interface SetWarningOptions {
|
|
24
|
+
Title?: string
|
|
25
|
+
Message: string
|
|
26
|
+
Tree?: string[]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const SetWarning = ({ Title, Message, Tree }: SetWarningOptions): void => {
|
|
30
|
+
const settings = Bootstrap.Settings as TypeSettings;
|
|
31
|
+
const title = Title ?? (`[${Bootstrap.Colors.Yellow}@atmosx/event-product-parser${Bootstrap.Colors.Reset}]`);
|
|
32
|
+
const log = (message: string): void => {
|
|
33
|
+
Bootstrap.Listener.emit(`log`, message);
|
|
34
|
+
if (settings.EnableJournal) { console.log(message); }
|
|
35
|
+
};
|
|
36
|
+
log(`${title} ${Message}`);
|
|
37
|
+
|
|
38
|
+
if (!Tree?.length) return;
|
|
39
|
+
|
|
40
|
+
const cleanTitle = title.replace(/\x1b\[[0-9;]*m/g, ``);
|
|
41
|
+
const padding = ` `.repeat(cleanTitle.length + 1);
|
|
42
|
+
const entries = Tree.filter((entry): entry is NonNullable<typeof entry> => entry !== undefined && entry !== null);
|
|
43
|
+
entries.forEach((entry, index) => {
|
|
44
|
+
const prefix = index === entries.length - 1 ? `└─` : `├─`;
|
|
45
|
+
log(`${padding}${prefix} ${entry}`);
|
|
46
|
+
});
|
|
47
|
+
};
|
|
@@ -11,47 +11,46 @@
|
|
|
11
11
|
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
12
|
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
13
|
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
-
Documentation:
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
17
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import { setEventEmit } from '../@utilities/utilities.setEventEmit';
|
|
20
|
+
import { TypeSettings } from "Types/Settings"
|
|
21
|
+
import { Bootstrap } from "@Bootstrap"
|
|
22
|
+
import { OnlineXMPP } from "@XMPP/OnlineXMPP"
|
|
23
|
+
import { OfflineXMPP } from "@XMPP/OfflineXMPP"
|
|
24
|
+
import { ErrorXMPP } from "@XMPP/ErrorXMPP"
|
|
25
|
+
import { StanzaXMPP } from "@XMPP/StanzaXMPP"
|
|
26
|
+
import { SetEventEmit } from "@Utilities/SetEventEmit"
|
|
27
|
+
import { client } from "@XMPP/client"
|
|
29
28
|
|
|
30
|
-
export const
|
|
29
|
+
export const DeployXMPP = async (): Promise<void> => {
|
|
31
30
|
let session;
|
|
32
|
-
const settings =
|
|
31
|
+
const settings = Bootstrap.Settings as TypeSettings
|
|
33
32
|
settings.NOAAWeatherWireServiceSettings.CredentialSettings.Nickname
|
|
34
33
|
??= settings.NOAAWeatherWireServiceSettings.CredentialSettings.Username;
|
|
35
|
-
session =
|
|
34
|
+
session = Bootstrap.Session = client({
|
|
36
35
|
service: 'xmpp://nwws-oi.weather.gov',
|
|
37
36
|
domain: 'nwws-oi.weather.gov',
|
|
38
|
-
username: settings.NOAAWeatherWireServiceSettings.CredentialSettings.Username,
|
|
39
|
-
password: settings.NOAAWeatherWireServiceSettings.CredentialSettings.Password
|
|
37
|
+
username: settings.NOAAWeatherWireServiceSettings.CredentialSettings.Username as string,
|
|
38
|
+
password: settings.NOAAWeatherWireServiceSettings.CredentialSettings.Password as string
|
|
40
39
|
})
|
|
41
40
|
try {
|
|
42
|
-
await
|
|
43
|
-
await
|
|
44
|
-
await
|
|
45
|
-
await
|
|
41
|
+
await OfflineXMPP();
|
|
42
|
+
await ErrorXMPP();
|
|
43
|
+
await StanzaXMPP();
|
|
44
|
+
await OnlineXMPP();
|
|
46
45
|
await session.start()
|
|
47
46
|
} catch (error) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
SetEventEmit({
|
|
48
|
+
Event: `onServiceStatus`,
|
|
49
|
+
Metadata: {
|
|
50
|
+
Message: `Error occured while starting XMPP Session: ${error}`,
|
|
51
|
+
Data: {},
|
|
52
|
+
Type: `error`,
|
|
53
|
+
Error: true
|
|
55
54
|
},
|
|
56
55
|
})
|
|
57
56
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ _ _ __ __
|
|
3
|
+
/\ | | | | (_) \ \ / /
|
|
4
|
+
/ \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
|
|
5
|
+
/ /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
|
|
6
|
+
/ ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
|
|
7
|
+
/_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
|
|
8
|
+
| |
|
|
9
|
+
|_|
|
|
10
|
+
|
|
11
|
+
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
|
+
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
|
+
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
|
+
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
|
+
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { Bootstrap } from "@Bootstrap"
|
|
21
|
+
|
|
22
|
+
export const ErrorXMPP = () => {
|
|
23
|
+
Bootstrap.Session.on(`error`, async () => {
|
|
24
|
+
Bootstrap.Cache.Connected = false;
|
|
25
|
+
Bootstrap.Cache.Hault = true;
|
|
26
|
+
})
|
|
27
|
+
}
|
|
@@ -11,19 +11,27 @@
|
|
|
11
11
|
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
12
|
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
13
|
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
-
Documentation:
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
17
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import { setWarning } from "../@utilities/utilities.setWarning";
|
|
20
|
+
import { Bootstrap } from "@Bootstrap"
|
|
21
|
+
import { SetEventEmit } from "@Utilities/SetEventEmit"
|
|
23
22
|
|
|
24
|
-
export const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
export const OfflineXMPP = () => {
|
|
24
|
+
Bootstrap.Session.on(`offline`, async () => {
|
|
25
|
+
Bootstrap.Cache.Connected = false;
|
|
26
|
+
Bootstrap.Cache.Hault = true;
|
|
27
|
+
SetEventEmit({
|
|
28
|
+
Event: `onServiceStatus`,
|
|
29
|
+
Metadata: {
|
|
30
|
+
Message: `Client has gone offline`,
|
|
31
|
+
Data: {},
|
|
32
|
+
Type: `offline`,
|
|
33
|
+
Error: true
|
|
34
|
+
},
|
|
35
|
+
})
|
|
28
36
|
})
|
|
29
37
|
}
|
|
@@ -11,35 +11,36 @@
|
|
|
11
11
|
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
12
|
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
13
|
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
-
Documentation:
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
17
|
|
|
18
18
|
*/
|
|
19
|
-
import { xml } from '@xmpp/client'
|
|
20
|
-
import { bootstrap } from "../../bootstrap";
|
|
21
|
-
import { setSleep } from "../@utilities/utilities.setSleep";
|
|
22
|
-
import { setEventEmit } from '../@utilities/utilities.setEventEmit';
|
|
23
19
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
import { Bootstrap } from "@Bootstrap"
|
|
21
|
+
import { SetEventEmit } from "@Utilities/SetEventEmit"
|
|
22
|
+
import { xml } from "@XMPP/client"
|
|
23
|
+
|
|
24
|
+
export const OnlineXMPP = () => {
|
|
25
|
+
const settings = Bootstrap.Settings;
|
|
26
|
+
Bootstrap.Session.on(`online`, async () => {
|
|
27
|
+
Bootstrap.Cache.Hault = false;
|
|
28
|
+
Bootstrap.Cache.Connected = true;
|
|
29
|
+
Bootstrap.Cache.TotalReconnects = 0;
|
|
30
30
|
const nickname = settings.NOAAWeatherWireServiceSettings.CredentialSettings.Nickname;
|
|
31
|
-
|
|
31
|
+
Bootstrap.Session.send(xml('presence', {
|
|
32
32
|
to: `nwws@conference.nwws-oi.weather.gov/${nickname}`,
|
|
33
33
|
xmlns: 'http://jabber.org/protocol/muc',
|
|
34
34
|
}))
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
SetEventEmit({
|
|
36
|
+
Event: `onServiceStatus`,
|
|
37
|
+
Metadata: {
|
|
38
|
+
Message: `Succesfully connected to NOAA Weather Wire Service as "${nickname}"`,
|
|
39
|
+
Data: {},
|
|
40
|
+
Type: `online`,
|
|
41
|
+
Error: false
|
|
42
42
|
},
|
|
43
|
+
Message: `Succesfully connected to NOAA Weather Wire Service as "${nickname}"`,
|
|
43
44
|
})
|
|
44
45
|
})
|
|
45
46
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ _ _ __ __
|
|
3
|
+
/\ | | | | (_) \ \ / /
|
|
4
|
+
/ \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
|
|
5
|
+
/ /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
|
|
6
|
+
/ ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
|
|
7
|
+
/_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
|
|
8
|
+
| |
|
|
9
|
+
|_|
|
|
10
|
+
|
|
11
|
+
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
|
+
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
|
+
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
|
+
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
|
+
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { TypeSettings } from "Types/Settings"
|
|
21
|
+
import { Bootstrap } from "@Bootstrap"
|
|
22
|
+
import { SetEventEmit } from "@Utilities/SetEventEmit"
|
|
23
|
+
import { SetWarning } from "@Utilities/SetWarning"
|
|
24
|
+
|
|
25
|
+
export const ReconnectXMPP = async (interval: number): Promise<void> => {
|
|
26
|
+
const settings = Bootstrap.Settings as TypeSettings;
|
|
27
|
+
const last = Date.now() - Bootstrap.Cache.LastStanzaTime
|
|
28
|
+
if (interval < 15) {
|
|
29
|
+
SetWarning({ Message: `Reconnection interval of ${interval} seconds is too low, setting to 15 seconds` })
|
|
30
|
+
interval = 15;
|
|
31
|
+
Bootstrap.Settings.NOAAWeatherWireServiceSettings.ReconnectionSettings.ReconnectionInterval = 15;
|
|
32
|
+
}
|
|
33
|
+
const reconnectThreshold = interval * 1e3
|
|
34
|
+
if ((!Bootstrap.Cache.Connected && !Bootstrap.Cache.Hault) || !Bootstrap.Session) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (last > reconnectThreshold) {
|
|
38
|
+
if (!Bootstrap.Cache.Reconnecting) {
|
|
39
|
+
Bootstrap.Cache.Reconnecting = true;
|
|
40
|
+
Bootstrap.Cache.Connected = false;
|
|
41
|
+
Bootstrap.Cache.TotalReconnects += 1;
|
|
42
|
+
try {
|
|
43
|
+
SetEventEmit({
|
|
44
|
+
Event: `onServiceStatus`,
|
|
45
|
+
Metadata: {
|
|
46
|
+
Message: `Attempting to reconnect to XMPP Service (Reconnect Attempt ${Bootstrap.Cache.TotalReconnects})`,
|
|
47
|
+
Data: {
|
|
48
|
+
Last: last,
|
|
49
|
+
Nickname: settings.NOAAWeatherWireServiceSettings.CredentialSettings.Nickname
|
|
50
|
+
},
|
|
51
|
+
Type: `reconnect`,
|
|
52
|
+
Error: true
|
|
53
|
+
}, Message: `Attempting to reconnect to XMPP Service (Reconnect Attempt ${Bootstrap.Cache.TotalReconnects})`,
|
|
54
|
+
})
|
|
55
|
+
await Bootstrap.Session.stop().catch(() => {});
|
|
56
|
+
await Bootstrap.Session.start().catch(() => {});
|
|
57
|
+
} catch (error) {
|
|
58
|
+
SetWarning({ Message: `XMPP Reconnect Failed - ${(error as Error).message}` })
|
|
59
|
+
} finally {
|
|
60
|
+
Bootstrap.Cache.Reconnecting = false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|