Wednesday, 26 April 2017

nodejs control a bidirectional playback of geo-coded json data from mongodb or file

I have a js frontend, to a backend WAMP router, that has a nodejs app that publishes JSON encoded geo-coded data in real time to a WAMP topic. The frontend subscribes to that WAMP topic and visualizes the moving geo-coded targets on a map. That data is also stored on the backend within MongoDB.

I need to add a function whereby the user can request, play, stop, rewind, and fast-forward through archived data. I have a backend nodejs function that receives the begin/end times for the query from the frontend, makes the MongoDB query and uses the MongoDB db.find.stream() interface to publish the data to a WAMP topic in realtime. The stream.on("data", ...) method pauses/resumes the stream to playback the data in time-step. This works fine for playback and stop. But, I don't know how to handle rewind and fast-forward. Based on what I've seen, you can't rewind or iterate backwards on a stream.

My brute force approach would be to load the entire huge query result into an in memory array and have methods the frontend calls to control the increment/decrement of the array pointer depending on if they are playing or rewinding so that they can see the targets moving on the map and find what they are looking for.

Is there an API or library that would allow me to accomplish rewind without loading the array into memory? Possibly storing the result into a file and moving back and forth through it?



via user7632232

No comments:

Post a Comment