1 | import { Disposable, DisposableCollection } from '../disposable';
|
2 | import { Emitter, Event } from '../event';
|
3 | import { ReadBuffer, WriteBuffer } from './message-buffer';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | export interface Channel {
|
10 | |
11 |
|
12 |
|
13 | onClose: Event<ChannelCloseEvent>;
|
14 | |
15 |
|
16 |
|
17 | onError: Event<unknown>;
|
18 | |
19 |
|
20 |
|
21 | onMessage: Event<MessageProvider>;
|
22 | |
23 |
|
24 |
|
25 | getWriteBuffer(): WriteBuffer;
|
26 | |
27 |
|
28 |
|
29 | close(): void;
|
30 | }
|
31 |
|
32 |
|
33 |
|
34 | export interface ChannelCloseEvent {
|
35 | reason: string;
|
36 | code?: number;
|
37 | }
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | export declare type MessageProvider = () => ReadBuffer;
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | export declare abstract class AbstractChannel implements Channel {
|
50 | onCloseEmitter: Emitter<ChannelCloseEvent>;
|
51 | get onClose(): Event<ChannelCloseEvent>;
|
52 | onErrorEmitter: Emitter<unknown>;
|
53 | get onError(): Event<unknown>;
|
54 | onMessageEmitter: Emitter<MessageProvider>;
|
55 | get onMessage(): Event<MessageProvider>;
|
56 | protected toDispose: DisposableCollection;
|
57 | constructor();
|
58 | close(): void;
|
59 | abstract getWriteBuffer(): WriteBuffer;
|
60 | }
|
61 | /**
|
62 | * A very basic {@link AbstractChannel} implementation which takes a function
|
63 | * for retrieving the {@link WriteBuffer} as constructor argument.
|
64 | */
|
65 | export declare class BasicChannel extends AbstractChannel {
|
66 | protected writeBufferProvider: () => WriteBuffer;
|
67 | constructor(writeBufferProvider: () => WriteBuffer);
|
68 | getWriteBuffer(): WriteBuffer;
|
69 | }
|
70 | /**
|
71 | * Helper class to implement the single channels on a {@link ChannelMultiplexer}. Simply forwards write requests to
|
72 | * the given write buffer source i.e. the main channel of the {@link ChannelMultiplexer}.
|
73 | */
|
74 | export declare class ForwardingChannel extends AbstractChannel {
|
75 | readonly id: string;
|
76 | protected readonly closeHandler: () => void;
|
77 | protected readonly writeBufferSource: () => WriteBuffer;
|
78 | constructor(id: string, closeHandler: () => void, writeBufferSource: () => WriteBuffer);
|
79 | getWriteBuffer(): WriteBuffer;
|
80 | close(): void;
|
81 | }
|
82 | /**
|
83 | * The different message types used in the messaging protocol of the {@link ChannelMultiplexer}
|
84 | */
|
85 | export declare enum MessageTypes {
|
86 | Open = 1,
|
87 | Close = 2,
|
88 | AckOpen = 3,
|
89 | Data = 4
|
90 | }
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 | export declare class ChannelMultiplexer implements Disposable {
|
97 | protected readonly underlyingChannel: Channel;
|
98 | protected pendingOpen: Map<string, (channel: ForwardingChannel) => void>;
|
99 | protected openChannels: Map<string, ForwardingChannel>;
|
100 | protected readonly onOpenChannelEmitter: Emitter<{
|
101 | id: string;
|
102 | channel: Channel;
|
103 | }>;
|
104 | get onDidOpenChannel(): Event<{
|
105 | id: string;
|
106 | channel: Channel;
|
107 | }>;
|
108 | protected toDispose: DisposableCollection;
|
109 | constructor(underlyingChannel: Channel);
|
110 | protected handleError(error: unknown): void;
|
111 | onUnderlyingChannelClose(event?: ChannelCloseEvent): void;
|
112 | protected handleMessage(buffer: ReadBuffer): void;
|
113 | protected handleAckOpen(id: string): void;
|
114 | protected handleOpen(id: string): void;
|
115 | protected handleClose(id: string): void;
|
116 | protected handleData(id: string, data: ReadBuffer): void;
|
117 | protected createChannel(id: string): ForwardingChannel;
|
118 | protected prepareWriteBuffer(id: string): WriteBuffer;
|
119 | protected closeChannel(id: string): void;
|
120 | open(id: string): Promise<Channel>;
|
121 | getOpenChannel(id: string): Channel | undefined;
|
122 | dispose(): void;
|
123 | }
|
124 | //# sourceMappingURL=channel.d.ts.map |
\ | No newline at end of file |