SignalR Line Rooms

Hi everyone.

I have a question about the WebSocket protocol for receiving live predictions as outlined towards the end of this article: https://blog.tfl.gov.uk/2015/12/07/unified-api-part-5-aot-arrivals-of-things/

The JS code includes the addition of line rooms as a way to subscribe to specific events. { "LineId": "northern", "NaptanId": "940GZZLUODS" }, for example.

However, when I tried to subscribe to this line room: {“LineId": “453”, “VehicleId: “LTZ1868”}, SignalR ignored the VehicleId constraint and served all 453 bus arrival predictions regardless of vehicle Id.

I am wondering if anyone knows which attributes can be used to filter the predictions that are being sent, besides LineId and NaptanId.

Thank you,

Max

I’m not sure if this is possible however, you can always filter the data you get back from the API in JavaScript itself.

let data = "DATA FROM API"
data = data.filter(x => x.vehicleId == "LTZ1868")

data will then only contain arrivals from this specific vehicle. This is somewhat wasteful in terms of pulling all data. Maybe somebody over at TfL could look into adding this parameter so that you can specify it in the URI.

2 Likes

I see. Thank you for your reply.

I am also curious if there is a shortcut way to subscribe to all bus lines without needing to add all of them into the line rooms.

That’s a question for somebody else because personally I’ve never used SignalR