A WebSocket server wrapping hafas-monitor-departures
.
Deprecated. Use hafas-live-ws-server
instead.
npm install hafas-monitor-departures-ws-server
const createHafas = require('vbb-hafas')
const http = require('http')
const createMonitorServer = require('.')
const stations = [ // array of station ids
'900000100003' // alexanderplatz
]
const interval = 5 * 1000 // every 5 seconds
const httpServer = http.createServer()
const hafas = createHafas('my-awesome-program')
createMonitorServer(httpServer, hafas, stations, interval)
httpServer.listen(3000)
Let a client receive the data:
const WebSocket = require('ws')
const client = new WebSocket('ws://localhost:3000/')
client.on('message', (msg) => {
try {
const departure = JSON.parse(msg)
console.log(departure)
} catch (err) {
console.error(err)
}
})
If you have a question or have difficulties using hafas-monitor-departures-ws-server
, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, refer to the issues page.