@mulingai-npm/message-broker 2.9.0 → 2.9.2

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,22 @@
1
+ import { RabbitMQClient } from '../rabbitmq-client';
2
+ import { IMulingstreamTranscriptionInterim, IMulingstreamTranscriptionFinal } from '@mulingai-npm/web-sockets';
3
+ /**
4
+ * Message broker manager for real-time transcription events
5
+ *
6
+ * Publishes interim and final transcription events to fanout exchanges.
7
+ * Both speaker-realtime and listener-realtime services subscribe to receive events.
8
+ */
9
+ export declare class MulingstreamTranscriptionRealtime {
10
+ private client;
11
+ constructor(client: RabbitMQClient);
12
+ /** Initialize both exchanges */
13
+ initialize(): Promise<void>;
14
+ /** Publish interim transcription */
15
+ publishInterim(data: IMulingstreamTranscriptionInterim): Promise<void>;
16
+ /** Publish final transcription */
17
+ publishFinal(data: IMulingstreamTranscriptionFinal): Promise<void>;
18
+ /** Subscribe to interim transcriptions */
19
+ subscribeInterim(queueName: string, onMessage: (data: IMulingstreamTranscriptionInterim) => Promise<void> | void): Promise<void>;
20
+ /** Subscribe to final transcriptions */
21
+ subscribeFinal(queueName: string, onMessage: (data: IMulingstreamTranscriptionFinal) => Promise<void> | void): Promise<void>;
22
+ }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MulingstreamTranscriptionRealtime = void 0;
4
+ // Interim transcription exchange (for live captions while speaking)
5
+ const INTERIM_EXCHANGE_NAME = 'mulingstream-transcription-interim';
6
+ // Final transcription exchange (for completed sentences)
7
+ const FINAL_EXCHANGE_NAME = 'mulingstream-transcription-final';
8
+ const EXCHANGE_TYPE = 'fanout';
9
+ /**
10
+ * Message broker manager for real-time transcription events
11
+ *
12
+ * Publishes interim and final transcription events to fanout exchanges.
13
+ * Both speaker-realtime and listener-realtime services subscribe to receive events.
14
+ */
15
+ class MulingstreamTranscriptionRealtime {
16
+ constructor(client) {
17
+ this.client = client;
18
+ }
19
+ /** Initialize both exchanges */
20
+ async initialize() {
21
+ const channel = this.client.getChannelOrThrow();
22
+ await channel.assertExchange(INTERIM_EXCHANGE_NAME, EXCHANGE_TYPE, { durable: false });
23
+ await channel.assertExchange(FINAL_EXCHANGE_NAME, EXCHANGE_TYPE, { durable: false });
24
+ console.log(`MulingstreamTranscriptionRealtime exchanges initialized.`);
25
+ }
26
+ /** Publish interim transcription */
27
+ async publishInterim(data) {
28
+ const channel = this.client.getChannelOrThrow();
29
+ channel.publish(INTERIM_EXCHANGE_NAME, '', Buffer.from(JSON.stringify(data)));
30
+ }
31
+ /** Publish final transcription */
32
+ async publishFinal(data) {
33
+ const channel = this.client.getChannelOrThrow();
34
+ channel.publish(FINAL_EXCHANGE_NAME, '', Buffer.from(JSON.stringify(data)));
35
+ }
36
+ /** Subscribe to interim transcriptions */
37
+ async subscribeInterim(queueName, onMessage) {
38
+ const channel = this.client.getChannelOrThrow();
39
+ await channel.assertQueue(queueName, { durable: false });
40
+ await channel.bindQueue(queueName, INTERIM_EXCHANGE_NAME, '');
41
+ await channel.consume(queueName, async (msg) => {
42
+ if (!msg)
43
+ return;
44
+ try {
45
+ const data = JSON.parse(msg.content.toString());
46
+ await onMessage(data);
47
+ channel.ack(msg);
48
+ }
49
+ catch (err) {
50
+ console.error(`Error in transcription interim queue '${queueName}':`, err);
51
+ channel.nack(msg, false, false);
52
+ }
53
+ });
54
+ }
55
+ /** Subscribe to final transcriptions */
56
+ async subscribeFinal(queueName, onMessage) {
57
+ const channel = this.client.getChannelOrThrow();
58
+ await channel.assertQueue(queueName, { durable: false });
59
+ await channel.bindQueue(queueName, FINAL_EXCHANGE_NAME, '');
60
+ await channel.consume(queueName, async (msg) => {
61
+ if (!msg)
62
+ return;
63
+ try {
64
+ const data = JSON.parse(msg.content.toString());
65
+ await onMessage(data);
66
+ channel.ack(msg);
67
+ }
68
+ catch (err) {
69
+ console.error(`Error in transcription final queue '${queueName}':`, err);
70
+ channel.nack(msg, false, false);
71
+ }
72
+ });
73
+ }
74
+ }
75
+ exports.MulingstreamTranscriptionRealtime = MulingstreamTranscriptionRealtime;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mulingai-npm/message-broker",
3
- "version": "2.9.0",
3
+ "version": "2.9.2",
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.40.1",
20
+ "@mulingai-npm/web-sockets": "^1.44.2",
21
21
  "amqplib": "^0.10.5"
22
22
  },
23
23
  "devDependencies": {