Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache sounds before running user code #243

Merged
merged 5 commits into from
Apr 17, 2015

Conversation

kevinbarabash
Copy link
Contributor

Attempt to address #223.


if (this.imageCache[file]) {
return loaded();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed so that this.imageCache[file] = img and if (this.imageCache[file]) { use the same file

create loadImage/loadSound methods which return promises,
use $.when to wait for all promises to resolve before calling the callback
… dry-ed out the regex code some more, don't run tests if the validate string is empty
this.results.tests = testResults;
this.phoneHome();
}.bind(this));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessary for resource caching. It should've been included in the scrubber performance pull request. I'm including it here because I don't want to forget about.

…match both getImage() and getSound() with a single regex to create a single array of resource records which are then loaded by loadResource(record) which multiplexes loadImage and loadSound, went back to caching <img> tags instead of PImage instances.

var img = document.createElement("img");
img.onload = function() {
this.cache[filename + ".png"] = img;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted to caching elements. Investigating whether PImages can be cached or not shouldn't hold up a bug fix for loading sounds.

@kevinbarabash
Copy link
Contributor Author

This should be good to go.

return this.getSound(filename);
break;
default:
throw "we can't load '" + type + "' resources yet";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please wrap in $._() for internationalization.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A user should never see this. All of the resources that are matched are either "sounds" or "images"... I was thinking of just doing break; for the default case. Is there a way to log errors that users shouldn't see but might be useful for us back to a server?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, okay. We do automatically send JS errors off to Sentry though we dont necessarily use that information yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a quick search through live-editor and it doesn't look like we're using Sentry anywhere. I'm going to get rid of the throw and put a TODO there instead and track it with a Github issue for add error tracking via Sentry.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I think we're likely hooking in globally on KA through window.onerror or such. Anyway, a break is fine. I'll find out about issues from students and ZenDesk tickets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

break it is.

…ource cache instance, removed a "throw" which will never happen
@pamelafox
Copy link
Collaborator

Is this PR ready to go? I can merge/release it this week if so.

@kevinbarabash
Copy link
Contributor Author

I believe this is good to go.

pamelafox added a commit that referenced this pull request Apr 17, 2015
Cache sounds before running user code
@pamelafox pamelafox merged commit 37bff86 into Khan:master Apr 17, 2015
@kevinbarabash kevinbarabash deleted the audio_oncanplaythrough branch July 6, 2015 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants