1 | import RAL from './ral';
|
2 | import { Event } from './events';
|
3 | import { Message } from './messages';
|
4 | import { ContentDecoder, ContentTypeDecoder } from './encoding';
|
5 | import { Disposable } from './api';
|
6 |
|
7 |
|
8 |
|
9 | export interface DataCallback {
|
10 | (data: Message): void;
|
11 | }
|
12 | export interface PartialMessageInfo {
|
13 | readonly messageToken: number;
|
14 | readonly waitingTime: number;
|
15 | }
|
16 |
|
17 | export interface MessageReader {
|
18 |
|
19 | readonly onError: Event<Error>;
|
20 |
|
21 | readonly onClose: Event<void>;
|
22 | |
23 |
|
24 |
|
25 |
|
26 | readonly onPartialMessage: Event<PartialMessageInfo>;
|
27 | |
28 |
|
29 |
|
30 |
|
31 | listen(callback: DataCallback): Disposable;
|
32 |
|
33 | dispose(): void;
|
34 | }
|
35 | export declare namespace MessageReader {
|
36 | function is(value: any): value is MessageReader;
|
37 | }
|
38 | export declare abstract class AbstractMessageReader implements MessageReader {
|
39 | private errorEmitter;
|
40 | private closeEmitter;
|
41 | private partialMessageEmitter;
|
42 | constructor();
|
43 | dispose(): void;
|
44 | get onError(): Event<Error>;
|
45 | protected fireError(error: any): void;
|
46 | get onClose(): Event<void>;
|
47 | protected fireClose(): void;
|
48 | get onPartialMessage(): Event<PartialMessageInfo>;
|
49 | protected firePartialMessage(info: PartialMessageInfo): void;
|
50 | private asError;
|
51 | abstract listen(callback: DataCallback): Disposable;
|
52 | }
|
53 | export interface MessageReaderOptions {
|
54 | charset?: RAL.MessageBufferEncoding;
|
55 | contentDecoder?: ContentDecoder;
|
56 | contentDecoders?: ContentDecoder[];
|
57 | contentTypeDecoder?: ContentTypeDecoder;
|
58 | contentTypeDecoders?: ContentTypeDecoder[];
|
59 | }
|
60 | export declare class ReadableStreamMessageReader extends AbstractMessageReader {
|
61 | private readable;
|
62 | private options;
|
63 | private callback;
|
64 | private nextMessageLength;
|
65 | private messageToken;
|
66 | private buffer;
|
67 | private partialMessageTimer;
|
68 | private _partialMessageTimeout;
|
69 | private readSemaphore;
|
70 | constructor(readable: RAL.ReadableStream, options?: RAL.MessageBufferEncoding | MessageReaderOptions);
|
71 | set partialMessageTimeout(timeout: number);
|
72 | get partialMessageTimeout(): number;
|
73 | listen(callback: DataCallback): Disposable;
|
74 | private onData;
|
75 | private clearPartialMessageTimer;
|
76 | private setPartialMessageTimer;
|
77 | }
|