NOTE: This repo was forked and modified because neither the npm or yarn registries had the latest dependencies, which was causing an issue with React Native.
Provides JavaScript classes generated from the GTFS-realtime Protocol Buffer specification. These classes will allow you to parse a binary Protocol Buffer GTFS-realtime data feed into JavaScript objects.
These bindings are designed to be used in the Node.js environment, but with some effort, they can probably be used in other JavaScript environments as well.
We use the ProtBuf.js library for JavaScript Protocol Buffer support.
To use the gtfs-realtime-bindings
classes in your own project, you need to
first install our Node.js npm package:
npm install gtfs-realtime-bindings
The following Node.js code snippet demonstrates downloading a GTFS-realtime data feed from a particular URL, parsing it as a FeedMessage (the root type of the GTFS-realtime schema), and iterating over the results.
var GtfsRealtimeBindings = require('gtfs-realtime-bindings');
var request = require('request');
var requestSettings = {
method: 'GET',
url: 'URL OF YOUR GTFS-REALTIME SOURCE GOES HERE',
encoding: null
};
request(requestSettings, function (error, response, body) {
if (!error && response.statusCode == 200) {
var feed = GtfsRealtimeBindings.transit_realtime.FeedMessage.decode(body);
feed.entity.forEach(function(entity) {
if (entity.trip_update) {
console.log(entity.trip_update);
}
});
}
});
For more details on the naming conventions for the Javascript classes generated from the gtfs-realtime.proto, check out the ProtoBuf.js project which we use to handle our Protocol Buffer serialization.