@hff-ai/media-processor-client 1.0.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.
- package/README.md +570 -0
- package/dist/MediaProcessor.d.ts +222 -0
- package/dist/MediaProcessor.d.ts.map +1 -0
- package/dist/MediaProcessor.js +731 -0
- package/dist/MediaProcessor.js.map +1 -0
- package/dist/__tests__/integration/mockMediaProcessor.d.ts +80 -0
- package/dist/__tests__/integration/mockMediaProcessor.d.ts.map +1 -0
- package/dist/__tests__/integration/mockMediaProcessor.js +248 -0
- package/dist/__tests__/integration/mockMediaProcessor.js.map +1 -0
- package/dist/__tests__/setup.d.ts +4 -0
- package/dist/__tests__/setup.d.ts.map +1 -0
- package/dist/__tests__/setup.js +13 -0
- package/dist/__tests__/setup.js.map +1 -0
- package/dist/errors.d.ts +134 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +173 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +81 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +107 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +453 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +51 -0
- package/dist/types.js.map +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MediaProcessor - Main client class for communicating with the Media Processor service
|
|
3
|
+
*/
|
|
4
|
+
import { EventEmitter } from 'events';
|
|
5
|
+
import { MediaProcessorConfig, ImageProcessOptions, VideoProcessOptions, ZipProcessOptions, AsyncImageProcessOptions, AsyncVideoProcessOptions, AsyncZipProcessOptions, MediaResultMessage, SystemStatus } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* MediaProcessor client class
|
|
8
|
+
*
|
|
9
|
+
* Provides a stream-like interface for communicating with the Media Processor service.
|
|
10
|
+
* Handles AMQP connections, message publishing, and event emission for processing updates.
|
|
11
|
+
*/
|
|
12
|
+
export declare class MediaProcessor extends EventEmitter {
|
|
13
|
+
private config;
|
|
14
|
+
private options;
|
|
15
|
+
private httpClient;
|
|
16
|
+
private connection;
|
|
17
|
+
private channel;
|
|
18
|
+
private consumerTag;
|
|
19
|
+
private _isConnected;
|
|
20
|
+
private reconnectAttempts;
|
|
21
|
+
private reconnectTimer;
|
|
22
|
+
private isShuttingDown;
|
|
23
|
+
private readonly requestQueue;
|
|
24
|
+
private readonly updatesQueue;
|
|
25
|
+
/** Map of pending async requests, keyed by correlation ID */
|
|
26
|
+
private pendingRequests;
|
|
27
|
+
/**
|
|
28
|
+
* Create a new MediaProcessor instance
|
|
29
|
+
*
|
|
30
|
+
* @param config - Configuration for the media processor connection
|
|
31
|
+
*/
|
|
32
|
+
constructor(config: MediaProcessorConfig);
|
|
33
|
+
/**
|
|
34
|
+
* Validate the configuration object
|
|
35
|
+
*/
|
|
36
|
+
private validateConfig;
|
|
37
|
+
/**
|
|
38
|
+
* Connect to the media processor service
|
|
39
|
+
*
|
|
40
|
+
* This will:
|
|
41
|
+
* 1. Set up the system configuration via REST API
|
|
42
|
+
* 2. Establish AMQP connection
|
|
43
|
+
* 3. Start consuming update messages
|
|
44
|
+
*/
|
|
45
|
+
connect(): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Set up the system configuration via REST API
|
|
48
|
+
*/
|
|
49
|
+
private setupSystem;
|
|
50
|
+
/**
|
|
51
|
+
* Connect to RabbitMQ
|
|
52
|
+
*/
|
|
53
|
+
private connectAmqp;
|
|
54
|
+
/**
|
|
55
|
+
* Set up the consumer for update messages
|
|
56
|
+
*/
|
|
57
|
+
private setupConsumer;
|
|
58
|
+
/**
|
|
59
|
+
* Handle incoming messages from the updates queue
|
|
60
|
+
*
|
|
61
|
+
* Messages are routed based on their correlationId:
|
|
62
|
+
*
|
|
63
|
+
* 1. Has correlationId AND matches pending request → handle via Promise
|
|
64
|
+
* 2. Has correlationId but NO match → orphaned async message → unhandled_message only
|
|
65
|
+
* 3. No correlationId → queue-based message → emit events
|
|
66
|
+
*
|
|
67
|
+
* This ensures:
|
|
68
|
+
* - Clean separation between async and queue API styles
|
|
69
|
+
* - Orphaned async messages (from dead processes) don't pollute event handlers
|
|
70
|
+
* - Queue messages are properly routed to event listeners
|
|
71
|
+
*/
|
|
72
|
+
private handleMessage;
|
|
73
|
+
/**
|
|
74
|
+
* Extract correlation ID from an update message
|
|
75
|
+
*/
|
|
76
|
+
private extractCorrelationId;
|
|
77
|
+
/**
|
|
78
|
+
* Warn if there are no listeners for a message type
|
|
79
|
+
* Helps detect orphaned messages that would otherwise be silently lost
|
|
80
|
+
*/
|
|
81
|
+
private warnIfNoListeners;
|
|
82
|
+
/**
|
|
83
|
+
* Emit progress events
|
|
84
|
+
*/
|
|
85
|
+
private emitProgressEvent;
|
|
86
|
+
/**
|
|
87
|
+
* Emit result events
|
|
88
|
+
*/
|
|
89
|
+
private emitResultEvent;
|
|
90
|
+
/**
|
|
91
|
+
* Emit error events
|
|
92
|
+
*/
|
|
93
|
+
private emitErrorEvent;
|
|
94
|
+
/**
|
|
95
|
+
* Handle connection errors
|
|
96
|
+
*/
|
|
97
|
+
private handleConnectionError;
|
|
98
|
+
/**
|
|
99
|
+
* Handle connection close
|
|
100
|
+
*/
|
|
101
|
+
private handleConnectionClose;
|
|
102
|
+
/**
|
|
103
|
+
* Schedule a reconnection attempt
|
|
104
|
+
*/
|
|
105
|
+
private scheduleReconnect;
|
|
106
|
+
/**
|
|
107
|
+
* Manually trigger a reconnection
|
|
108
|
+
*/
|
|
109
|
+
reconnect(): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Clean up AMQP connections
|
|
112
|
+
*/
|
|
113
|
+
private cleanupConnections;
|
|
114
|
+
/**
|
|
115
|
+
* Disconnect from the media processor service
|
|
116
|
+
*/
|
|
117
|
+
disconnect(): Promise<void>;
|
|
118
|
+
/**
|
|
119
|
+
* Reject all pending async requests (called on disconnect)
|
|
120
|
+
*/
|
|
121
|
+
private rejectAllPendingRequests;
|
|
122
|
+
/**
|
|
123
|
+
* Check if connected to the media processor
|
|
124
|
+
*/
|
|
125
|
+
isConnected(): boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Update the authentication token
|
|
128
|
+
*/
|
|
129
|
+
updateToken(token: string): void;
|
|
130
|
+
/**
|
|
131
|
+
* Get the current system status
|
|
132
|
+
*/
|
|
133
|
+
getSystemStatus(): Promise<SystemStatus>;
|
|
134
|
+
/**
|
|
135
|
+
* Queue an image for processing (fire-and-forget)
|
|
136
|
+
*
|
|
137
|
+
* Use this when you want to handle results via events.
|
|
138
|
+
*
|
|
139
|
+
* @param s3Key - S3 object key of the image to process
|
|
140
|
+
* @param options - Optional processing parameters
|
|
141
|
+
* @returns mediaId - Unique identifier for tracking this job
|
|
142
|
+
*/
|
|
143
|
+
queueS3Image(s3Key: string, options?: ImageProcessOptions): string;
|
|
144
|
+
/**
|
|
145
|
+
* Queue a video for processing (fire-and-forget)
|
|
146
|
+
*
|
|
147
|
+
* Use this when you want to handle results via events.
|
|
148
|
+
*
|
|
149
|
+
* @param s3Key - S3 object key of the video to process
|
|
150
|
+
* @param options - Optional processing parameters
|
|
151
|
+
* @returns mediaId - Unique identifier for tracking this job
|
|
152
|
+
*/
|
|
153
|
+
queueS3Video(s3Key: string, options?: VideoProcessOptions): string;
|
|
154
|
+
/**
|
|
155
|
+
* Queue a zip archive for processing (fire-and-forget)
|
|
156
|
+
*
|
|
157
|
+
* Use this when you want to handle results via events.
|
|
158
|
+
*
|
|
159
|
+
* @param s3Key - S3 object key of the zip file
|
|
160
|
+
* @param options - Optional processing parameters
|
|
161
|
+
* @returns mediaId - Unique identifier for tracking this job
|
|
162
|
+
*/
|
|
163
|
+
queueS3Zip(s3Key: string, options?: ZipProcessOptions): string;
|
|
164
|
+
/**
|
|
165
|
+
* Process an image and wait for the result
|
|
166
|
+
*
|
|
167
|
+
* @param s3Key - S3 object key of the image to process
|
|
168
|
+
* @param options - Optional processing parameters including timeout and progress callback
|
|
169
|
+
* @returns Promise that resolves with the processing result
|
|
170
|
+
* @throws ProcessingError if processing fails
|
|
171
|
+
* @throws ProcessingError with code 'PROCESSING_TIMEOUT' if timeout is exceeded
|
|
172
|
+
*/
|
|
173
|
+
processS3Image(s3Key: string, options?: AsyncImageProcessOptions): Promise<MediaResultMessage>;
|
|
174
|
+
/**
|
|
175
|
+
* Process a video and wait for the result
|
|
176
|
+
*
|
|
177
|
+
* @param s3Key - S3 object key of the video to process
|
|
178
|
+
* @param options - Optional processing parameters including timeout and progress callback
|
|
179
|
+
* @returns Promise that resolves with the processing result
|
|
180
|
+
* @throws ProcessingError if processing fails
|
|
181
|
+
* @throws ProcessingError with code 'PROCESSING_TIMEOUT' if timeout is exceeded
|
|
182
|
+
*/
|
|
183
|
+
processS3Video(s3Key: string, options?: AsyncVideoProcessOptions): Promise<MediaResultMessage>;
|
|
184
|
+
/**
|
|
185
|
+
* Process a zip archive and wait for the result
|
|
186
|
+
*
|
|
187
|
+
* @param s3Key - S3 object key of the zip file
|
|
188
|
+
* @param options - Optional processing parameters including timeout and progress callback
|
|
189
|
+
* @returns Promise that resolves with the processing result
|
|
190
|
+
* @throws ProcessingError if processing fails
|
|
191
|
+
* @throws ProcessingError with code 'PROCESSING_TIMEOUT' if timeout is exceeded
|
|
192
|
+
*/
|
|
193
|
+
processS3Zip(s3Key: string, options?: AsyncZipProcessOptions): Promise<MediaResultMessage>;
|
|
194
|
+
/**
|
|
195
|
+
* Submit an async processing request and return a Promise
|
|
196
|
+
*/
|
|
197
|
+
private submitAsyncProcessingRequest;
|
|
198
|
+
/**
|
|
199
|
+
* Generate a unique correlation ID for request tracking
|
|
200
|
+
*
|
|
201
|
+
* Uses UUID to ensure uniqueness even across process restarts,
|
|
202
|
+
* preventing any possibility of ID collision with orphaned responses.
|
|
203
|
+
*/
|
|
204
|
+
private generateCorrelationId;
|
|
205
|
+
/**
|
|
206
|
+
* Submit a processing request
|
|
207
|
+
*/
|
|
208
|
+
private submitProcessingRequest;
|
|
209
|
+
/**
|
|
210
|
+
* Guess MIME type from file extension
|
|
211
|
+
*/
|
|
212
|
+
private guessMimeType;
|
|
213
|
+
/**
|
|
214
|
+
* Extract filename from S3 key
|
|
215
|
+
*/
|
|
216
|
+
private extractFilename;
|
|
217
|
+
/**
|
|
218
|
+
* Extract file extension from S3 key
|
|
219
|
+
*/
|
|
220
|
+
private extractExtension;
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=MediaProcessor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MediaProcessor.d.ts","sourceRoot":"","sources":["../src/MediaProcessor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAKtC,OAAO,EACL,oBAAoB,EAEpB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EAItB,kBAAkB,EAGlB,YAAY,EAKb,MAAM,SAAS,CAAC;AA8CjB;;;;;GAKG;AACH,qBAAa,cAAe,SAAQ,YAAY;IAC9C,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,UAAU,CAAgB;IAElC,OAAO,CAAC,UAAU,CAA6B;IAC/C,OAAO,CAAC,OAAO,CAAwB;IACvC,OAAO,CAAC,WAAW,CAAuB;IAE1C,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,iBAAiB,CAAK;IAC9B,OAAO,CAAC,cAAc,CAA+B;IACrD,OAAO,CAAC,cAAc,CAAS;IAE/B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IAEtC,6DAA6D;IAC7D,OAAO,CAAC,eAAe,CAA0C;IAEjE;;;;OAIG;gBACS,MAAM,EAAE,oBAAoB;IAwBxC;;OAEG;IACH,OAAO,CAAC,cAAc;IAwCtB;;;;;;;OAOG;IACG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