fhsav / clock

The clock for Farmington High School.
http://fhsclock.com
Other
12 stars 2 forks source link

Ajax refresh #253

Open ethnt opened 11 years ago

ethnt commented 11 years ago

Use JSON and Ajax to refresh, instead of just refreshing the whole page.

ethnt commented 11 years ago

I'm using the topic branch 253-ajax.

Here's the routing.

/api/theme.json
/api/schedule.json
/api/marquee.json
/api/notices.json

It only returns data for the current values (i.e., the current schedule, etc).

ethnt commented 11 years ago

(Just FYI, WebSockets was borked in iOS 6, so it won't work on those devices.)

gluxon commented 11 years ago

AJAX doesn't use WebSockets. It's basically back and forth POST data using XMLHttpRequest in JavaScript. jQuery has a pretty sweet lobrary for it, and support for passing JSONs.

ethnt commented 11 years ago

The way that the refresh works is that it uses Faye, a library for WebSockets. That's how it's triggered.

ethnt commented 11 years ago

This will help with #247, as we'll just be caching the JSON data.

ethnt commented 11 years ago

As part of #261, we can send JSON data along with the refresh request. Fill the page with the new data (dynamically).

ethnt commented 11 years ago

Here's the plan:

  1. Click Refresh.
  2. Current data (in JSON) sent along to Pusher.
  3. Client receives data, checks to see if anything needs to be changed, and transitions the new data in (fold up then down for schedule, add to end for marquee, dissolve wallpapers, fade in/out notices).
  4. When refreshed, data will be there, cached.
gluxon commented 11 years ago

Does the installation guide include instructions on setting up Padrino? It doesn't look like it, and I don't have a ./bin/safe file after completing the instructions.

ethnt commented 11 years ago

That wiki is quite old, I need to update it.

  1. Padrino is “set up” already, you just need to install it. You can install all of the dependencies by running gem install bundler then bundle install.
  2. The whole /bin directory doesn't exist anymore. Assuming you have MongoDB (sudo mongod) and Redis (redis-server) running, you can just run bundle exec foreman start to start a development server at http://localhost:5000. However, at this point, it won't run without Amazon AWS S3 credentials. I'll explain that tomorrow in school.

I'll update the wiki soon and make it easy to run it in development. Eventually it'll be just running online, with the back up in AV, so maintenance won't be much of an issue.

gluxon commented 11 years ago

Ethan, I apologize for the late work on this. Robotics has been taking up a lot of my time. FRC Build season will end on February 19th, so I will have my life back after that day....

ethnt commented 11 years ago

It's quite alright. Whenever you get around to it, make sure you make it in the topic branch 253-ajax off of the branch refactor. I'll start working on this soon (this could be related to #296 — perhaps this will reduce the CPU load).

gluxon commented 11 years ago

I'm at the AWS issue now. :(

/home/gluxon/.rvm/gems/ruby-1.9.3-p385/gems/fog-1.9.0/lib/fog/core/service.rb:208:in `validate_options': Missing required arguments: aws_access_key_id, aws_secret_access_key (ArgumentError)

ethnt commented 11 years ago

Ah, you need to create a .env file with your S3 credentials:

S3_ID=YOUR-ID
S3_SECRET=YOUR-SECRET
S3_BUCKET=BUCKET

To get the ID and SECRET, create an AWS Access Key.

ethnt commented 11 years ago

You also need to do the same for Pusher, except with PUSHER_ID, PUSHER_KEY, and PUSHER_SECRET.

gluxon commented 11 years ago

What's your preferred method of communication? GTalk? IRC? I have questions and don't want to spam this issue.

ethnt commented 11 years ago

GTalk, ethan.turkeltaub@gmail.com.

gluxon commented 11 years ago

Here's how I want to implement this.

  1. Get /api/status/status.json at an interval we can argue later (3 sec?).
  2. Check last_update_key and compare with a previously obtained key
  3. If the keys are different, grab a json of the new schedule/marquees/notices
ethnt commented 11 years ago

I think that we should just latch onto what we're currently using for refreshes (Pusher). Since you can pass any data along with the request to Pusher, we can put the current data in there. We then check that against what is currently on the clock and figure out what needs to be changed.

On Tuesday, June 25, 2013, Brandon Cheng wrote:

Here's how I want to implement this.

  1. Get /api/status/status.json at an interval we can argue later (3 sec?).
  2. Check last_update_key and compare with a previously obtained key
  3. If the keys are different, grab a json of the new schedule/marquees/notices

— Reply to this email directly or view it on GitHubhttps://github.com/fhsav/clock/issues/253#issuecomment-19994000 .

Ethan Turkeltaub http://ethnt.me @ethnt http://twitter.com/ethnt

gluxon commented 11 years ago

Meh, I kind of want to remove this external dependency on Pusher.

ethnt commented 11 years ago

Requesting a page every n seconds puts too much load on the server. PubSub (like Pusher) is made for this. Another library like it is Faye, but I'm not sure if it'll work on Heroku.

On Tuesday, June 25, 2013, Brandon Cheng wrote:

Meh, I kind of want to remove this external dependency on Pusher.

— Reply to this email directly or view it on GitHubhttps://github.com/fhsav/clock/issues/253#issuecomment-19994308 .

Ethan Turkeltaub http://ethnt.me @ethnt http://twitter.com/ethnt

ethnt commented 11 years ago

In fact, we don't need to have any of the logic that determines what needs to be changed on the client-side—that can be handled server-side and then only the new data is sent along with the Pusher/Faye request.

On Tuesday, June 25, 2013, Ethan Turkeltaub wrote:

Requesting a page every n seconds puts too much load on the server. PubSub (like Pusher) is made for this. Another library like it is Faye, but I'm not sure if it'll work on Heroku.

On Tuesday, June 25, 2013, Brandon Cheng wrote:

Meh, I kind of want to remove this external dependency on Pusher.

— Reply to this email directly or view it on GitHubhttps://github.com/fhsav/clock/issues/253#issuecomment-19994308 .

Ethan Turkeltaub http://ethnt.me @ethnt http://twitter.com/ethnt

Ethan Turkeltaub http://ethnt.me @ethnt http://twitter.com/ethnt

gluxon commented 11 years ago

Faye and Pusher are still checking for new data every n seconds. Is there a reason why Faye hasn't replaced Pusher in the code then?

ethnt commented 11 years ago

Infrastructure (Heroku has some trouble with it, so does Passenger). You can look at some previous commits to see how Faye was implemented before (look at v0.4.0 in the tags, maybe).

On Tuesday, June 25, 2013, Brandon Cheng wrote:

Faye and Pusher are still checking for new data every n seconds. Is there a reason why Faye hasn't replaced Pusher in the code then?

— Reply to this email directly or view it on GitHubhttps://github.com/fhsav/clock/issues/253#issuecomment-19995425 .

Ethan Turkeltaub http://ethnt.me @ethnt http://twitter.com/ethnt