0.1.1 • Published 5 years ago

hafas-monitor-departures-ws-server v0.1.1

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

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.