StreamClient

StreamClient

Connect to the Twitter API v2 sampled stream endpoint and emit events for processing
For additional information see Twitter Sampled Stream

Constructor

new StreamClient(config)

Source:

Initializes the client

Parameters:
Name Type Description
config Object

Configuration for client

Properties
Name Type Description
timeout number

Set request and response timeout

token string

Set OAUTH Bearer token from developer account

Fires:

Extends

  • EventEmitter

Methods

(async) connect(config) → {Promise.<void>}

Source:
See:
  • retriableStatus

Connect to twitter stream and emit events.

Parameters:
Name Type Description
config Object

Configuration for connection

Properties
Name Type Description
params number

Set any filter parameters for stream, etc.

max_reconnects number

Specify max number of reconnects. Default: -1 (infinity)

Returns:

Promise that resolves on disconnect -- the Promise rejects if the number of reconnects exceeds the max or an irrecoverable error occurs -- the Promise resolves with that last error returned. Error object defines .reconnects if reconnects are exceeded

Type
Promise.<void>

disconnect() → {boolean}

Source:

Disconnects an active request if any

Returns:

Returns true if there is a request to disconnect

Type
boolean

Events

tweet

Source:

Triggered upon connected stream receiving a tweet

Type:
  • Object

heartbeat

Source:

Triggered upon connected stream receiving a heartbeat

stream-error

Source:

Triggered when on api-level stream errors (misformatted JSON, etc.)

Type:
  • Object

api-errors

Source:

Provides twitter error messages as JSON objects

Type:
  • Object

other

Source:

Triggered upon connected stream receiving unexpected JSON

Type:
  • Object

connected

Source:

Triggered on stream connection

reconnect

Source:

Triggered before stream reconnect and provides the wait time till reconnect

Type:
  • number

disconnected

Source:

Triggered when manually disconnecting client stream