@mulingai-npm/message-broker 2.1.2 → 2.2.0
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,9 @@
|
|
|
1
|
+
import { RabbitMQClient } from '../rabbitmq-client';
|
|
2
|
+
import { IMulingstreamRoomStatusUpdate } from '@mulingai-npm/web-sockets';
|
|
3
|
+
export declare class MulingstreamRoomStatus {
|
|
4
|
+
private client;
|
|
5
|
+
constructor(client: RabbitMQClient);
|
|
6
|
+
initialize(): Promise<void>;
|
|
7
|
+
publish(data: IMulingstreamRoomStatusUpdate): Promise<void>;
|
|
8
|
+
subscribe(queueName: string, onMessage: (data: IMulingstreamRoomStatusUpdate) => Promise<void> | void): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MulingstreamRoomStatus = void 0;
|
|
4
|
+
const EXCHANGE_NAME = 'mulingstream-room-status';
|
|
5
|
+
const EXCHANGE_TYPE = 'fanout';
|
|
6
|
+
class MulingstreamRoomStatus {
|
|
7
|
+
constructor(client) {
|
|
8
|
+
this.client = client;
|
|
9
|
+
}
|
|
10
|
+
async initialize() {
|
|
11
|
+
const channel = this.client.getChannelOrThrow();
|
|
12
|
+
await channel.assertExchange(EXCHANGE_NAME, EXCHANGE_TYPE, {
|
|
13
|
+
durable: false
|
|
14
|
+
});
|
|
15
|
+
console.log(`MulingstreamRoomStatus exchange '${EXCHANGE_NAME}' asserted.`);
|
|
16
|
+
}
|
|
17
|
+
async publish(data) {
|
|
18
|
+
const channel = this.client.getChannelOrThrow();
|
|
19
|
+
const payload = Buffer.from(JSON.stringify(data));
|
|
20
|
+
channel.publish(EXCHANGE_NAME, '', payload);
|
|
21
|
+
console.log(`[RoomStatus] Published status update for room ${data.roomId}: ${data.status}`);
|
|
22
|
+
}
|
|
23
|
+
async subscribe(queueName, onMessage) {
|
|
24
|
+
const channel = this.client.getChannelOrThrow();
|
|
25
|
+
await channel.assertQueue(queueName, { durable: true });
|
|
26
|
+
await channel.bindQueue(queueName, EXCHANGE_NAME, '');
|
|
27
|
+
await channel.consume(queueName, async (msg) => {
|
|
28
|
+
if (!msg) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const data = JSON.parse(msg.content.toString());
|
|
33
|
+
await onMessage(data);
|
|
34
|
+
channel.ack(msg);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
console.error(`Error in MulingstreamRoomStatus subscription queue ${queueName}:`, error);
|
|
38
|
+
channel.nack(msg);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.MulingstreamRoomStatus = MulingstreamRoomStatus;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mulingai-npm/message-broker",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"repository": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"prepublishOnly": "npm run build"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@mulingai-npm/web-sockets": "^1.
|
|
20
|
+
"@mulingai-npm/web-sockets": "^1.34.0",
|
|
21
21
|
"amqplib": "^0.10.5"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|