podverse-mq 5.1.4-alpha.0 → 5.1.4-alpha.1

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.
@@ -0,0 +1,3 @@
1
+ import { ActiveMQArtemisService } from '@queue/services/activeMQArtemis';
2
+ export declare const mqRSSRunLiveItemListener: (activeMQArtemisService: ActiveMQArtemisService) => void;
3
+ //# sourceMappingURL=runLiveItemListener.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runLiveItemListener.d.ts","sourceRoot":"","sources":["../../../../src/functions/mq/rss/runLiveItemListener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAe,MAAM,iCAAiC,CAAC;AAMtF,eAAO,MAAM,wBAAwB,GACnC,wBAAwB,sBAAsB,SAoI/C,CAAC"}
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.mqRSSRunLiveItemListener = void 0;
16
+ const podverse_helpers_1 = require("podverse-helpers");
17
+ const podverse_orm_1 = require("podverse-orm");
18
+ const ws_1 = __importDefault(require("ws"));
19
+ const add_1 = require("./add");
20
+ const mqRSSRunLiveItemListener = (activeMQArtemisService) => {
21
+ console.info('starting runLiveItemListener');
22
+ const feedService = new podverse_orm_1.FeedService();
23
+ /*
24
+ Run an interval to keep the node script running forever.
25
+ */
26
+ setInterval(() => {
27
+ console.info('runLiveItemListener interval');
28
+ }, 100000000);
29
+ let openedSocket = null;
30
+ const timeInterval = 5000;
31
+ const url = 'wss://api.livewire.io/ws/podping';
32
+ let connectionIdCount = 0;
33
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
+ const hiveBlocksHandled = {};
35
+ function connect() {
36
+ const client = new ws_1.default(url);
37
+ return new Promise((resolve, reject) => {
38
+ console.info('client try to connect...');
39
+ let connectionId = connectionIdCount;
40
+ client.on('open', () => {
41
+ connectionId = connectionIdCount + 1;
42
+ connectionIdCount++;
43
+ console.info(`WEBSOCKET_OPEN: client connected to server at ${url}, connectionId: ${connectionId}`);
44
+ openedSocket = true;
45
+ resolve(openedSocket);
46
+ });
47
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
48
+ client.on('message', function message(data) {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ try {
51
+ const msg = JSON.parse(data);
52
+ // If the hiveBlock was already processed by our listener, then skip the message.
53
+ if (hiveBlocksHandled[msg.n])
54
+ return;
55
+ const prodPodpingLiveIdRegex = new RegExp('^pp_(.*)_(live|liveEnd)$', 'i');
56
+ if (msg.t === 'podping') {
57
+ hiveBlocksHandled[msg.n] = true;
58
+ for (const p of msg.p) {
59
+ if (prodPodpingLiveIdRegex.test(p.i) &&
60
+ p.p.reason &&
61
+ (p.p.reason.toLowerCase() === 'live' || p.p.reason.toLowerCase() === 'liveend')) {
62
+ console.info(`p.p ${JSON.stringify(p.p)}, p.n Hive block number ${p.n}, connectionId: ${connectionId}`);
63
+ const addRSSObjs = [];
64
+ for (const url of p.p.iris) {
65
+ try {
66
+ if (url === null || url === void 0 ? void 0 : url.startsWith('http')) {
67
+ let feed = null;
68
+ try {
69
+ feed = yield feedService.getByUrl(url);
70
+ }
71
+ catch (error) {
72
+ console.info(`p.p.iris error ${error}, connectionId: ${connectionId}`);
73
+ }
74
+ if (feed === null || feed === void 0 ? void 0 : feed.channel) {
75
+ const { podcast_index_id } = feed.channel;
76
+ const numPodcastIndexId = Number(podcast_index_id);
77
+ if (podcast_index_id)
78
+ addRSSObjs.push({ url, podcast_index_id: numPodcastIndexId });
79
+ }
80
+ else {
81
+ console.info('feed url not found');
82
+ }
83
+ }
84
+ }
85
+ catch (err) {
86
+ console.info(`p.p.iris error ${err}, connectionId: ${connectionId}`);
87
+ }
88
+ }
89
+ const queueType = 'rss-live';
90
+ const mqConstantMessageOptions = podverse_helpers_1.MQ_QUEUES[queueType];
91
+ for (const addRSSObj of addRSSObjs) {
92
+ yield (0, add_1.mqRSSAdd)(activeMQArtemisService, Object.assign(Object.assign({}, mqConstantMessageOptions), { feedUrl: addRSSObj.url, podcastIndexId: addRSSObj.podcast_index_id }));
93
+ }
94
+ }
95
+ }
96
+ }
97
+ }
98
+ catch (err) {
99
+ console.info(`message error: ${err}, connectionId: ${connectionId}`);
100
+ }
101
+ });
102
+ });
103
+ client.on('close', (err) => {
104
+ console.info(`WEBSOCKET_CLOSE: connection closed ${err}, connectionId: ${connectionId}`);
105
+ openedSocket = false;
106
+ reject(err);
107
+ });
108
+ client.on('error', (err) => {
109
+ console.info(`WEBSOCKET_ERROR: Error ${new Error(err.message)}, connectionId: ${connectionId}`);
110
+ openedSocket = false;
111
+ reject(err);
112
+ });
113
+ });
114
+ }
115
+ function reconnect() {
116
+ return __awaiter(this, void 0, void 0, function* () {
117
+ try {
118
+ yield connect();
119
+ }
120
+ catch (err) {
121
+ if (err instanceof Error) {
122
+ console.error(`reconnect error: ${err.message}`);
123
+ }
124
+ else {
125
+ console.error(`reconnect error: ${String(err)}`);
126
+ }
127
+ }
128
+ });
129
+ }
130
+ reconnect();
131
+ // repeat every 5 seconds
132
+ setInterval(() => {
133
+ if (!openedSocket) {
134
+ reconnect();
135
+ }
136
+ }, timeInterval);
137
+ };
138
+ exports.mqRSSRunLiveItemListener = mqRSSRunLiveItemListener;
package/dist/index.d.ts CHANGED
@@ -3,5 +3,6 @@ export { mqRSSAdd } from './functions/mq/rss/add';
3
3
  export { mqRSSAddAll } from './functions/mq/rss/addAll';
4
4
  export { mqRSSAddRecentlyUpdatedFeedsFromPodcastIndex } from './functions/mq/rss/addRecentlyUpdatedFeedsFromPodcastIndex';
5
5
  export { mqRSSRunParser } from './functions/mq/rss/runParser';
6
+ export { mqRSSRunLiveItemListener } from './functions/mq/rss/runLiveItemListener';
6
7
  export { ActiveMQArtemisService, ActiveMQArtemisServiceParams } from './services/activeMQArtemis';
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,uBAAuB,CAAC;AAE/B,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,4CAA4C,EAAE,MAAM,4DAA4D,CAAC;AAC1H,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,EAAE,sBAAsB,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,uBAAuB,CAAC;AAE/B,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,4CAA4C,EAAE,MAAM,4DAA4D,CAAC;AAC1H,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAElF,OAAO,EAAE,sBAAsB,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ActiveMQArtemisService = exports.mqRSSRunParser = exports.mqRSSAddRecentlyUpdatedFeedsFromPodcastIndex = exports.mqRSSAddAll = exports.mqRSSAdd = void 0;
3
+ exports.ActiveMQArtemisService = exports.mqRSSRunLiveItemListener = exports.mqRSSRunParser = exports.mqRSSAddRecentlyUpdatedFeedsFromPodcastIndex = exports.mqRSSAddAll = exports.mqRSSAdd = void 0;
4
4
  require("./module-alias-config");
5
5
  var add_1 = require("./functions/mq/rss/add");
6
6
  Object.defineProperty(exports, "mqRSSAdd", { enumerable: true, get: function () { return add_1.mqRSSAdd; } });
@@ -10,5 +10,7 @@ var addRecentlyUpdatedFeedsFromPodcastIndex_1 = require("./functions/mq/rss/addR
10
10
  Object.defineProperty(exports, "mqRSSAddRecentlyUpdatedFeedsFromPodcastIndex", { enumerable: true, get: function () { return addRecentlyUpdatedFeedsFromPodcastIndex_1.mqRSSAddRecentlyUpdatedFeedsFromPodcastIndex; } });
11
11
  var runParser_1 = require("./functions/mq/rss/runParser");
12
12
  Object.defineProperty(exports, "mqRSSRunParser", { enumerable: true, get: function () { return runParser_1.mqRSSRunParser; } });
13
+ var runLiveItemListener_1 = require("./functions/mq/rss/runLiveItemListener");
14
+ Object.defineProperty(exports, "mqRSSRunLiveItemListener", { enumerable: true, get: function () { return runLiveItemListener_1.mqRSSRunLiveItemListener; } });
13
15
  var activeMQArtemis_1 = require("./services/activeMQArtemis");
14
16
  Object.defineProperty(exports, "ActiveMQArtemisService", { enumerable: true, get: function () { return activeMQArtemis_1.ActiveMQArtemisService; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "podverse-mq",
3
- "version": "5.1.4-alpha.0",
3
+ "version": "5.1.4-alpha.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,16 +18,18 @@
18
18
  "dependencies": {
19
19
  "module-alias": "^2.2.3",
20
20
  "podverse-external-services": "^5.1.4-alpha.0",
21
- "podverse-helpers": "^5.1.4-alpha.0",
22
- "podverse-orm": "^5.1.4-alpha.0",
21
+ "podverse-helpers": "^5.1.4-alpha.1",
22
+ "podverse-orm": "^5.1.4-alpha.1",
23
23
  "podverse-parser": "^5.1.4-alpha.0",
24
- "rhea": "^2.0.6"
24
+ "rhea": "^2.0.6",
25
+ "ws": "^8.18.3"
25
26
  },
26
27
  "devDependencies": {
27
28
  "@eslint/config-array": "^0.21.0",
28
29
  "@eslint/eslintrc": "^3.3.1",
29
30
  "@eslint/js": "^9.35.0",
30
31
  "@types/node": "^24.4.0",
32
+ "@types/ws": "^8.18.1",
31
33
  "eslint": "^9.35.0",
32
34
  "nodemon": "^3.1.10",
33
35
  "ts-node": "^10.9.2",