UNPKG

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