cubehouse / themeparks

Unofficial API for accessing ride wait times and schedules for Disneyland, Disney World, Universal Studios, and many more parks
MIT License
540 stars 126 forks source link

Add emitted events when ride times change #193

Closed cubehouse closed 3 years ago

cubehouse commented 5 years ago

Proposed example usage:

const PA = new themeparks.Parks.PortAventura();
PA.on('rideStateUpdated', (ride, previousTime, previousStatus) => {
  console.log(`${ride.name} was ${previousTime}, now ${ride.waitTime} (${previousStatus} => ${ride.status})`);
});
PA.StartPolling();

previousTime and previousStatus return undefined if this is the first update of a process run.

This does a few things:

  1. Avoids people manually setting up less-than-ideal timer loops where developers reinstantiate park objects multiple times, or call update too frequently
  2. Encourages developers to not attach GetWaitTimes directly to public API calls (i.e, app HTTP calls are calling GetWaitTimes directly, which has unknown side-effects based on park state, should be returning cached results instead)
  3. Allows live-response parks (WDW & DL) to return park results in real-time, rather than waiting for poll requests by developers to give updated times

Still need to test thoroughly, as now all parks are EventEmitters, which is new. Also need to check over live Disney parks and ensure they flush their temporary cache when live rides come through.