Poll for the shot image, since drawing is now asynchronous
This commit is contained in:
parent
8a3324be31
commit
61210c6640
1 changed files with 26 additions and 3 deletions
29
script.html
29
script.html
|
|
@ -184,9 +184,32 @@ function wire(locked) {
|
|||
photo_id: ph ? ph.value : undefined });
|
||||
b.disabled = true; b.textContent = "Drawing…";
|
||||
var r = await api("make_shot_image", { email: email, project_id: pid, index: idx });
|
||||
b.disabled = false;
|
||||
if (!r.ok) { b.textContent = "Try again"; showMsg("msg", r.error || "Could not make that frame."); return; }
|
||||
load();
|
||||
if (!r.ok) {
|
||||
b.disabled = false; b.textContent = "Try again";
|
||||
showMsg("msg", r.error || "Could not make that frame.");
|
||||
return;
|
||||
}
|
||||
// Drawing takes about half a minute and runs on the server, so the call
|
||||
// above returns straight away. Watch the shot until the frame appears.
|
||||
var waited = 0;
|
||||
var tick = setInterval(async function () {
|
||||
waited += 4;
|
||||
var g = await api("get_project", { email: email, project_id: pid });
|
||||
var seg = (g.ok && g.script && g.script.segments || []).filter(function (x) {
|
||||
return parseInt(x.index, 10) === idx; })[0];
|
||||
if (seg && seg.draw_error) {
|
||||
clearInterval(tick);
|
||||
b.disabled = false; b.textContent = "Try again";
|
||||
showMsg("msg", "That frame did not draw: " + seg.draw_error);
|
||||
return;
|
||||
}
|
||||
if (seg && seg.plate_url) { clearInterval(tick); load(); return; }
|
||||
if (waited > 120) {
|
||||
clearInterval(tick);
|
||||
b.disabled = false; b.textContent = "Try again";
|
||||
showMsg("msg", "That frame is taking unusually long. Try again in a moment.");
|
||||
}
|
||||
}, 4000);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue