Options
All
  • Public
  • Public/Protected
  • All
Menu

Class StreamClient

Client used for twitter stream api, different from normal rest Client

param ClientOrOptions

tweets.ts Client or a Object with all the authorization fields accepts both

example

Using a Tweets.ts Client (recommended)

import { StreamClient, Client } from 'tweets.ts'

const client = new Client(...Ur Client options here)
// client is a tweets.ts Client
const streamclient = new StreamClient(client);
example

Using a Object with authorization values

import { StreamClient } from 'tweets.ts'
// version is optional and defaults to "1"
const streamclient = new StreamClient({
version: '1',
authorization: {
consumer_key: '1221112321',
consumer_secret: 'some-value',
access_token: 'access token here',
access_token_secret: 'access token secret here'
}
});

Hierarchy

  • EventEmitter
    • StreamClient

Index

Constructors

constructor

  • new StreamClient(ClientOrOptions: Client | { authorization: { access_token: null | string; access_token_secret: null | string; consumer_key: null | string; consumer_secret: null | string } & { access_token: null | string; access_token_secret: null | string; consumer_key: null | string; consumer_secret: null | string }; autoReconnect: boolean; version: string }): StreamClient
  • Parameters

    • ClientOrOptions: Client | { authorization: { access_token: null | string; access_token_secret: null | string; consumer_key: null | string; consumer_secret: null | string } & { access_token: null | string; access_token_secret: null | string; consumer_key: null | string; consumer_secret: null | string }; autoReconnect: boolean; version: string }

    Returns StreamClient

Events

Static Readonly connected

connected: "connected" = 'connected'

Emitted when the streamClient is connected to the given endPoint

Static Readonly error

error: "error" = 'error'

Emitted when any type of error occurs after stream is connected (some errors might get thrown), while connecting errors are thrown (error will be a param of the event)

Static Readonly ping

ping: "ping" = 'ping'

Nothing important, twitter api sent us a ping event

Static Readonly raw

raw: "raw" = 'raw'

every data received from the twitter api, params include RawPacket data (buffer) and parsed json data

Static Readonly tweet

tweet: "tweet" = 'tweet'

Emitted when a tweet gets deleted, with a Tweet as a param

Static Readonly tweetDelete

tweetDelete: "tweetDelete" = 'tweetDelete'

Emitted when a tweet gets deleted, with a Tweet as a param

Static Readonly warning

warning: "warning" = 'warning'

Emitted When A warning from the twitter api is received

Properties

connection

connection: any

endPoint

endPoint: null | string

reconnect

reconnect: boolean

Methods

Private _debug

  • _debug(msg: string): any

Private _parsePacket

  • _parsePacket(packetData: Buffer): any

Private _resolveHeaders

  • _resolveHeaders(endPoint?: null | string, body: any): { buildData: { method: string; url: string }; headers: any }
  • Parameters

    • endPoint: null | string = ...
    • body: any

    Returns { buildData: { method: string; url: string }; headers: any }

    • buildData: { method: string; url: string }
      • method: string
      • url: string
    • headers: any

destroy

  • destroy(): any

end

  • end this stream

    example
    streamClient.end('We got everything we need from this stream')
    

    Parameters

    • reason: string = 'No reason'

      reason to end this stream

    • clearEndpoint: boolean

      Weather to set this.endPoint to null

    Returns StreamClient

Private onEnd

Private onPacket

  • onPacket(packetData: Buffer): any

stream

  • Attach A stream to this Stream Client

    example

    Creating a Stream to '/statuses/filter'

    const body = {
    follow: "1238451949000888322",
    }

    streamClient.stream({ endPoint: '/statuses/filter', body: body });

    streamClient.on('connected', () => console.log('connected'))

    // ... rest of the events here

    Parameters

    • options: Object

      Stream options

    • reconnect: boolean = ...

      Weather autoReconnect is enabled

    Returns StreamClient

Generated using TypeDoc