-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
183 lines (183 loc) · 5.49 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/// <reference types="node" />
import { EventEmitter } from 'events';
import Client from './Client';
import * as Constants from './Constants';
import * as RTT from './helpers/RTT';
import * as JID from './JID';
import * as Jingle from './jingle';
import * as JXT from './jxt';
import * as LibSASL from './lib/sasl';
import StrictEventEmitter from './lib/StrictEventEmitter';
import * as Namespaces from './Namespaces';
import * as Stanzas from './protocol';
import { CSI, IQ, Message, Presence, SASL, Stream, StreamError, StreamFeatures, StreamManagement } from './protocol';
import SM from './StreamManagement';
import * as Utils from './Utils';
export * from './StreamManagement';
export interface TopLevelElements {
message: Message;
iq: IQ;
presence: Presence;
error: StreamError;
sasl: SASL;
features: StreamFeatures;
sm: StreamManagement;
csi: CSI;
}
export interface AgentEvents {
message: Stanzas.ReceivedMessage;
presence: Stanzas.ReceivedPresence;
iq: Stanzas.ReceivedIQ;
features: Stanzas.StreamFeatures;
stanza: Stanzas.Message | Stanzas.Presence | Stanzas.IQ;
'stream:start': Stanzas.Stream;
'stream:end': void;
'stream:error': (streamError: Stanzas.StreamError, error?: Error) => void;
'stream:data': (json: any, kind: string) => void;
'message:sent': (msg: Stanzas.Message, viaCarbon: boolean) => void;
'message:error': Stanzas.Message;
chat: Stanzas.ReceivedMessage;
groupchat: Stanzas.ReceivedMessage;
available: Stanzas.ReceivedPresence;
unavailable: Stanzas.ReceivedPresence;
'session:started': string | void;
'session:prebind': string;
'session:bound': string;
'session:end': undefined;
'stanza:failed': {
kind: 'message';
stanza: Stanzas.Message;
} | {
kind: 'presence';
stanza: Stanzas.Presence;
} | {
kind: 'iq';
stanza: Stanzas.IQ;
};
'stanza:acked': {
kind: 'message';
stanza: Stanzas.Message;
} | {
kind: 'presence';
stanza: Stanzas.Presence;
} | {
kind: 'iq';
stanza: Stanzas.IQ;
};
'raw:incoming': string;
'raw:outgoing': string;
'raw:*': (direction: 'incoming' | 'outgoing', data: string) => void;
raw: (direction: 'incoming' | 'outgoing', data: string) => void;
connected: void;
disconnected?: Error;
'bosh:terminate': any;
'*': (...args: any[]) => void;
}
export interface Agent extends StrictEventEmitter<EventEmitter, AgentEvents> {
jid: string;
config: AgentConfig;
transport?: Transport;
sm: SM;
sasl: LibSASL.Factory;
stanzas: JXT.Registry;
sessionStarted: boolean;
use(plugin: (agent: Agent, registry: JXT.Registry, config: AgentConfig) => void): void;
nextId(): string;
connect(opts?: AgentConfig): void;
disconnect(): void;
send<T extends keyof TopLevelElements>(path: T, data: TopLevelElements[T]): void;
sendIQ<T = IQ, R = T>(iq: T & IQ): Promise<IQ & R>;
sendIQResult(orig: IQ, result?: Partial<IQ>): void;
sendIQError(orig: IQ, err?: Partial<IQ>): void;
sendMessage(msg: Message): void;
sendPresence(pres?: Presence): void;
sendStreamError(err: StreamError): void;
}
export interface AgentConfig {
/**
* User JID
*/
jid?: string;
/**
* Server Domain Name
*
* Set the expected name of the server instead of using domain in the provided JID.
*/
server?: string;
/**
* Connection Resource
*
* Optionally request for the server to bind a specific resource for the connection.
*
* Note that the server is allowed ignore the request.
*/
resource?: string;
/**
* IQ Timeout
*
* The number of seconds to wait before timing out IQ requests.
*
* @default 15
*/
timeout?: number;
/**
* Transport Configurations
*
* Limit the transport types that will be used, or specify connection
* URLs to use without needing to use auto-discovery.
*
* If a transport is set to <code>false</code>, it will be disabled.
*
* If a transport is set to a string, that will be used as the connection URL.
*
* If a transport is set to an object, it MUST include a <code>url</code> value for
* the connection URL.
*
* @default { websocket: true, bosh: true }
*/
transports?: {
[key: string]: boolean | string | Partial<TransportConfig>;
};
/**
* Account Password
*
* Equivalent to using <code>credentials: { password: '*****' }</code>.
*/
password?: string;
/**
* User Language
*
* The associated language code for content created by the user.
*/
lang?: string;
/**
* Accepted Languages
*
* A list of language codes acceptable to the user.
*/
acceptLanguages?: string[];
}
export interface Transport {
hasStream?: boolean;
stream?: Stream;
authenticated?: boolean;
connect(opts: TransportConfig): void;
disconnect(): void;
restart(): void;
send(name: string, data?: object): void;
}
export interface TransportConfig {
lang?: string;
acceptLanguages?: string[];
server: string;
url: string;
jid: string;
sid?: string;
rid?: number;
maxRetries?: number;
wait?: number;
}
export { Client, Constants, JXT, JID, Namespaces, Stanzas, Jingle, Utils, RTT, LibSASL as SASL };
export declare const VERSION = "__STANZAJS_VERSION__";
export * from './plugins';
export declare function createClient(opts: AgentConfig): Agent;