index.js
function WebhookPost(webhook, options)
{
  if(!(this instanceof WebhookPost)) return new WebhookPost(webhook, options)

  var self = this

  options = options || {}
  options.objectMode = true

  WebhookPost.super_.call(this, options)


  // Remote ServerSendEvent server
  if(typeof webhook === 'string')
  {
    var eventSource = createEventSource.call(this, webhook, options)

    eventSource.addEventListener('error', function(error)
    {
      if(this.readyState !== EventSource.CLOSED)
        return self.emit('error', error)

      self.push(null)
      eventSource = null
    })
  }

  // Ad-hoc local web server
  else
  {
    if(webhook == null) webhook = {}
    else if(typeof webhook === 'number') webhook = {port: webhook}

    var server = createServer.call(this, webhook)
    .on('close', function()
    {
      self.push(null)
      server = null
    })
  }


  //
  // Public API
  //

  /**
   * Close the connection and stop emitting more data updates
   */
  this.close = function()
  {
    var connection = eventSource || server
    if(!connection) return

    connection.close()
  }
}
function WebhookPost(webhook, options)
{
  if(!(this instanceof WebhookPost)) return new WebhookPost(webhook, options)

  var self = this

  options = options || {}
  options.objectMode = true

  WebhookPost.super_.call(this, options)


  // Remote ServerSendEvent server
  if(typeof webhook === 'string')
  {
    var eventSource = createEventSource.call(this, webhook, options)

    eventSource.addEventListener('error', function(error)
    {
      if(this.readyState !== EventSource.CLOSED)
        return self.emit('error', error)

      self.push(null)
      eventSource = null
    })
  }

  // Ad-hoc local web server
  else
  {
    if(webhook == null) webhook = {}
    else if(typeof webhook === 'number') webhook = {port: webhook}

    var server = createServer.call(this, webhook)
    .on('close', function()
    {
      self.push(null)
      server = null
    })
  }


  //
  // Public API
  //

  /**
   * Close the connection and stop emitting more data updates
   */
  this.close = function()
  {
    var connection = eventSource || server
    if(!connection) return

    connection.close()
  }
}
function WebhookPost ( webhook , options ) { if ( ! ( this instanceof WebhookPost ) ) return new WebhookPost ( webhook , options ) var self = this options = options || { } options . objectMode = true WebhookPost . super_ . call ( this , options ) // Remote ServerSendEvent server if ( typeof webhook === 'string' ) { var eventSource = createEventSource . call ( this , webhook , options ) eventSource . addEventListener ( 'error' , function ( error ) { if ( this . readyState !== EventSource . CLOSED ) return self . emit ( 'error' , error ) self . push ( null ) eventSource = null } ) } // Ad-hoc local web server else { if ( webhook == null ) webhook = { } else if ( typeof webhook === 'number' ) webhook = { port : webhook } var server = createServer . call ( this , webhook ) . on ( 'close' , function ( ) { self . push ( null ) server = null } ) } // // Public API // /**
   * Close the connection and stop emitting more data updates
   */ this . close = function ( ) { var connection = eventSource || server if ( ! connection ) return connection . close ( ) } }
Create a stream of webhook notifications

@constructor

@param {Object|string|Number} [webhook={}]
@param {string} [webhook.hostname='0.0.0.0']
@param {Number} [webhook.port=0]
@param {Object} [options]
@param {Boolean} [options.withCredentials=false]

@emits WebhookPost#open
@emits WebhookPost#data
@emits WebhookPost#error
@emits Readable#end
Create a stream of webhook notifications