UNPKG

2.71 kBTypeScriptView Raw
1export = StreamClient;
2/**
3 * Connect to the Twitter API v2 sampled stream endpoint and emit events for processing<br/>
4 * For additional information see
5 * [Twitter Sampled Stream]{@link https://developer.twitter.com/en/docs/twitter-api/tweets/sampled-stream/introduction}
6 * @extends EventEmitter
7 * @fires StreamClient#tweet
8 * @fires StreamClient#connected
9 * @fires StreamClient#reconnect
10 * @fires StreamClient#disconnected
11 * @fires StreamClient#close
12 * @fires StreamClient#stream-error
13 * @fires StreamClient#api-errors
14 * @fires StreamClient#heartbeat
15 * @fires StreamClient#other
16 */
17declare class StreamClient {
18 /**
19 * Initializes the client
20 * @param {Object} config Configuration for client
21 * @param {number} config.timeout Set request and response timeout
22 * @param {string} config.token Set [OAUTH Bearer token]{@link https://developer.twitter.com/en/docs/authentication/oauth-2-0} from developer account
23 */
24 constructor({ token, timeout, stream_timeout }: {
25 timeout: number;
26 token: string;
27 });
28 timeout: number;
29 twitrClient: any;
30 stream_timeout: any;
31 /**
32 * Connect to twitter stream and emit events.
33 * @param {Object} config Configuration for connection
34 * @param {number} config.params Set any filter parameters for stream, etc.
35 * @param {string} config.max_reconnects Specify max number of reconnects. Default: -1 (infinity)
36 * @returns {(Promise<object>|Promise<Error>)} Promise that resolves on [disconnect]{@link StreamClient#disconnect}
37 * -- the Promise rejects if the number of reconnects exceeds the max or an irrecoverable error occurs
38 * -- the Promise resolves with that last error returned. Error object defines .reconnects if reconnects are exceeded
39 * @see retriableStatus
40 */
41 connect({ params, max_reconnects, writeable_stream }?: {
42 params: number;
43 max_reconnects: string;
44 }): (Promise<object> | Promise<Error>);
45 /**
46 * Disconnects an active request if any
47 * @returns {boolean} Returns true if there is a request to disconnect
48 */
49 disconnect(): boolean;
50 cancelToken: any;
51 /**
52 * Build Promises for handling data stream in [.buildConnection]{@link StreamClient#buildConnection}
53 * @private
54 * @returns {Promise} Promise that initiates HTTP streaming
55 */
56 private buildStreamPromise;
57 /**
58 * Connect to twitter stream and emit events. Errors unhandled.
59 * @private
60 * @returns {Promise} Promise that resolves on [disconnect]{@link StreamClient#disconnect}
61 * -- the Promise chain is unhandled so consider using [.connect]{@link StreamClient#connect}
62 */
63 private buildConnection;
64}