/hafas-live-ws-server

A WebSocket server that sends out live HAFAS data.

Primary LanguageJavaScriptISC LicenseISC

hafas-live-ws-server

A WebSocket server that sends out live HAFAS data.

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

Installation

npm install hafas-live-ws-server

Usage

Server:

const createHafas = require('bvg-hafas')
const {createServer: createHttpServer} = require('http')
const createWebSocketServer = require('hafas-live-ws-server')

const hafas = createHafas('hafas-live-ws-server example')
const httpServer = createHttpServer()
const wsServer = createWebSocketServer(httpServer, hafas)
httpServer.listen(3000)

Client:

const querystring = require('querystring')
const WebSocket = require('ws')

const bbox = querystring.stringify({
	north: 52.51, south: 52.4, west: 13.35, east: 13.38
})
const ws = new WebSocket('http://localhost:3000/stopovers?' + query)
ws.on('error', console.error)
ws.on('message', msg => console.log(JSON.parse(msg)))

Contributing

If you have a question or need support using hafas-live-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.