SignalR - Bus arrival data not arriving at once!

Hi,

I’m trying to put together a relatively basic app which simply shows the upcoming buses from a single bus stop. The issue, is that the data seems to be retrieved in 2 parts.

For example, using the JSFiddle example from the TFL site: TfL SignalR Predictions Demo - JSFiddle - Code Playground - the example using the Northern line retrieves the next 10 or so trains at once.

However, if I put in the bus stop I’m concerned with (line: R70, Naptan: 490012527S ) - the retrieved data comes back in two parts, normally a single bus (sometimes it’s the 2nd one due, sometimes the first), and then another 2 buses are retrieved.

As I’m simply changing the ID’s in the existing code, I can’t really see what’s wrong and causing this. Is there a way of retrieving all the bus arrival data at once?

Cheers,
Lloyd

It looks like Signalr is Push technology - the server will send the data when the data is ready, and different data is ready at different times.

It sounds like you’re actually after Pull technology, where the client opens connection, grabs what it cans, then closes. The API call for your example would include: https://api.tfl.gov.uk/StopPoint/490012527S/arrivals

To use your example, at http://eztfl.pectw.net/bus/73116 I only use Pull, and only ever see (and expect) the one response.

Yes exactly - the JSFiddle example is over-simplified for demonstration purposes. It really needs to have more persistence to work correctly, by doing an “update or insert” operation on the new prediction as it is pushed from SignalR rather than simply clearing down the whole board each time.

Our preferred option for developers is to call the “pull” API e.g. https://api.tfl.gov.uk/StopPoint/490012527S/arrivals to get the initial arrivals board, then subscribe to SignalR push notifications to receive each update as necessary. This avoids the need for developers to repeatedly poll the arrivals API.