Home

Awesome

hafas-monitor-departures 🔭

Pass in a HAFAS client, fetch all departures at any set of stations. (You may get blacklisted.)

If you want to monitor trips/departures in an area, use hafas-monitor-trips. It polls HAFAS more efficiently.

npm version build status ISC-licensed gitter channel support me on Patreon

Installing

npm install hafas-monitor-departures

Usage

As an exampe, we're going to use vbb-hafas, the HAFAS client for Berlin.

const createMonitor = require('hafas-monitor-departures')
const createHafas = require('vbb-hafas')

const stations = ['900000100003'] // array of station ids
const interval = 2 * 60 * 1000 // every two minutes
const duration = 10 // each time, fetch departures for the next 10 min

const hafas = createHafas('my-awesome-program')
const monitor = createMonitor(hafas, stations, {interval, duration})
monitor.on('error', console.error)
monitor.on('departure', console.log)

setTimeout(() => {
	monitor.removeListener('departure', console.log)
}, interval * 3)

hafas.departures() must be compatible with the implementation of hafas-client@5 (or of hafas-client@^4).

Once you listen to any of the departure or stats events, it will automatically start to watch, and stop once you stop listening.

To manually issue a single departures check at a station, use monitor.manual(id). The result will be emitted in a data event like all others.

API

createMonitor(hafasClient, listOfStations, opt = {})

opt overrides the following default values:

{
	interval: interval || 60 * 1000,
	step: step || Math.floor(interval / stations.length),
	duration: duration || Math.ceil(interval / 60 / 1000)
}

Related

Contributing

If you have a question, found a bug or want to propose a feature, have a look at the issues page.