Skip to content
This repository has been archived by the owner on Jun 9, 2019. It is now read-only.

derhuerst/hafas-monitor-departures-ws-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hafas-monitor-departures-ws-server

A WebSocket server wrapping hafas-monitor-departures.

Deprecated. Use hafas-live-ws-server instead.

npm version build status ISC-licensed chat with me on Gitter support me on Patreon

Installing

npm install hafas-monitor-departures-ws-server

Usage

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)
	}
})

Contributing

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.