@kaltura-sdk/rtc-avatar 1.32.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,15 @@
1
+ type RequestType = string;
2
+ type Payload = Record<string, unknown>;
3
+ type RequestExecutor<T = unknown> = (payload: Payload) => Promise<T>;
4
+ interface Request<T = unknown> {
5
+ type: RequestType;
6
+ payload: Payload;
7
+ requestExecutor: RequestExecutor<T>;
8
+ }
9
+ export declare class RequestsDebouncer {
10
+ private requests;
11
+ addRequest<T>(request: Request<T>): Promise<T | undefined>;
12
+ private executeRequest;
13
+ private resolveRequest;
14
+ }
15
+ export {};
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Streaming gzip logger that compresses log messages on-the-fly using CompressionStream API.
3
+ * Uses a producer-consumer pattern where write() writes to the compression stream and
4
+ * pumpReader() continuously reads compressed chunks into memory.
5
+ *
6
+ * @example
7
+ * const buffer = new CompressedLogger();
8
+ * buffer.write('User action\n');
9
+ * const blob = await buffer.snapshot(); // Get compressed logs and reset
10
+ * await buffer.close(); // Clean up resources
11
+ */
12
+ /**
13
+ * Captured at module load, before any console patching. Used throughout the logging
14
+ * pipeline to avoid re-entering addLog() from internal code paths (infinite loop risk).
15
+ * Lives here because compressedLogger is the bottom of the import chain, ensuring
16
+ * the capture happens before LogsCollector patches console methods.
17
+ */
18
+ export declare const originalConsole: {
19
+ readonly log: {
20
+ (...data: any[]): void;
21
+ (message?: any, ...optionalParams: any[]): void;
22
+ };
23
+ readonly info: {
24
+ (...data: any[]): void;
25
+ (message?: any, ...optionalParams: any[]): void;
26
+ };
27
+ readonly warn: {
28
+ (...data: any[]): void;
29
+ (message?: any, ...optionalParams: any[]): void;
30
+ };
31
+ readonly error: {
32
+ (...data: any[]): void;
33
+ (message?: any, ...optionalParams: any[]): void;
34
+ };
35
+ readonly debug: {
36
+ (...data: any[]): void;
37
+ (message?: any, ...optionalParams: any[]): void;
38
+ };
39
+ };
40
+ export declare class CompressedLogger {
41
+ private readonly encoder;
42
+ private current;
43
+ private currentReadDone;
44
+ /**
45
+ * Next stream, active during snapshot() drain.
46
+ * log() routes here while the old stream is closing, eliminating any buffering window.
47
+ * Null outside of snapshot().
48
+ */
49
+ private next;
50
+ constructor();
51
+ private createStream;
52
+ /**
53
+ * Continuously reads compressed chunks from the stream into the given state object.
54
+ * Runs asynchronously in the background until the stream is closed.
55
+ */
56
+ private pumpReader;
57
+ /**
58
+ * Writes a pre-formatted line into the active compression stream.
59
+ * If snapshot() is in progress, routes to the next stream to avoid any buffering window.
60
+ *
61
+ * @param line - A fully formatted log line (caller is responsible for timestamps, formatting, etc.)
62
+ */
63
+ write(line: string): void;
64
+ /**
65
+ * Closes the compression stream, flushing any remaining data and writing the gzip footer.
66
+ * After closing, log() calls are ignored. Safe to call multiple times.
67
+ */
68
+ close(): Promise<void>;
69
+ /**
70
+ * Returns a Blob containing all compressed chunks collected so far.
71
+ * @returns Blob with 'text/plain' MIME type so that it works with sendBeacon()
72
+ */
73
+ getCompressedBlob(): Blob;
74
+ /**
75
+ * Returns the total size of compressed data in bytes.
76
+ */
77
+ getCompressedSize(): number;
78
+ /**
79
+ * Returns the total size of uncompressed data written so far, in bytes.
80
+ * Updates synchronously on every log() call, unlike getCompressedSize() which lags
81
+ * behind due to the async compression stream.
82
+ */
83
+ getUncompressedSize(): number;
84
+ /**
85
+ * Closes the current compression stream, returns compressed logs as a Blob,
86
+ * then reinitializes for continued logging. Useful for periodic log uploads.
87
+ *
88
+ * A new stream is created before the old one closes, so log() calls during
89
+ * the async drain go directly to the next stream with no buffering.
90
+ *
91
+ * @param contextLine - Optional context line to write at the start of the new buffer
92
+ * @returns Blob containing all logs since last snapshot (or construction)
93
+ */
94
+ snapshot(contextLine?: string): Promise<Blob>;
95
+ }
@@ -0,0 +1,47 @@
1
+ import { originalConsole } from './compressedLogger';
2
+ export { originalConsole };
3
+ /**
4
+ * Maximum payload size for sendBeacon (64KB).
5
+ */
6
+ export declare const MAX_PAYLOAD_SIZE: number;
7
+ /**
8
+ * Fraction of MAX_PAYLOAD_SIZE at which logs are automatically flushed and sent.
9
+ */
10
+ export declare const SEND_COMPRESSED_THRESHOLD: number;
11
+ /**
12
+ * Conservative estimate of the minimum gzip compression ratio for log text.
13
+ * Used as a fallback threshold on the uncompressed buffer size, since getCompressedSize()
14
+ * lags behind due to the async compression stream. Real-world log compression is typically 5–10x.
15
+ */
16
+ export declare const SEND_UNCOMPRESSED_THRESHOLD: number;
17
+ /**
18
+ * Owns the dual-buffer (compressed + uncompressed) and threshold logic.
19
+ * Wraps CompressedLogger for gzip streaming and maintains a parallel plain-text
20
+ * buffer as an uncompressed fallback.
21
+ */
22
+ export declare class LogBuffer {
23
+ private readonly compressedLogger;
24
+ private uncompressedBuffer;
25
+ constructor();
26
+ /**
27
+ * Single source of truth for log line format across both the compressed and uncompressed buffers.
28
+ */
29
+ private static formatLine;
30
+ /**
31
+ * Appends a pre-serialized log entry to both the compressed and uncompressed buffers.
32
+ * Returns true when a size threshold is exceeded, signaling the caller to flush.
33
+ */
34
+ addLog(level: string, message: string): boolean;
35
+ /**
36
+ * Atomically swaps out both buffers, closes the current compression stream,
37
+ * and returns the compressed blob alongside the captured uncompressed logs.
38
+ * The uncompressed buffer is swapped synchronously before the first await so
39
+ * that any logs written during the async drain go into the fresh buffer.
40
+ *
41
+ * @param contextLine - Optional context written at the start of the next compressed buffer.
42
+ */
43
+ flush(contextLine?: string): Promise<{
44
+ blob: Blob;
45
+ uncompressedLogs: string[];
46
+ }>;
47
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Configuration for the logs collector.
3
+ */
4
+ export interface LogsCollectorConfig {
5
+ clientID: string;
6
+ flowID: string;
7
+ logsEndpoint: string;
8
+ socketID: string;
9
+ additionalContext?: Record<string, unknown>;
10
+ }
11
+ /**
12
+ * Initializes the logs collector with the provided configuration.
13
+ * This is the main entry point for using the logs collector.
14
+ *
15
+ * @param config - Configuration including clientID, flowID, and logsEndpoint
16
+ */
17
+ export declare function initializeLogsCollector(config: LogsCollectorConfig): void;
18
+ /**
19
+ * Manually sends logs to the server.
20
+ *
21
+ * @param preventMoreSends - If true, cleans up the collector after sending (no more logs will be sent)
22
+ */
23
+ export declare function sendLogs(preventMoreSends: boolean): void;
24
+ /**
25
+ * Cleans up the logs collector: removes event listeners, unsubscribes interceptors, and resets state.
26
+ * Intended for use in tests.
27
+ */
28
+ export declare function cleanupLogsCollector(): void;
@@ -0,0 +1,10 @@
1
+ import { UnisphereLoggerType } from '@unisphere/core';
2
+ /**
3
+ * Retry a promise-returning function with a delay between attempts.
4
+ *
5
+ * @param fn - Async function to call (use a closure to capture arguments)
6
+ * @param logger - Logger for retry error messages
7
+ * @param timeoutDuration - Delay in ms between retries (default: 3000)
8
+ * @param retriesNumber - Max number of attempts (default: 3)
9
+ */
10
+ export declare function runWithRetry<T>(fn: () => Promise<T>, logger: UnisphereLoggerType, timeoutDuration?: number, retriesNumber?: number): Promise<T>;
@@ -0,0 +1,2 @@
1
+ export declare function tryDecompress(blob: Blob): Promise<string>;
2
+ export declare function decompress(blob: Blob): Promise<string>;