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
Mobile queue fixes #4742
Mobile queue fixes #4742
Changes from 44 commits
ad98cb4
fe5dee0
56afa6f
b196c38
53d24f8
256ce30
e1a7242
eeffeec
dfed2e6
e7c0007
07321dc
0a2e0d6
8bb18a3
69c05ec
b96f303
1f04c52
76b33fc
2442d4e
35a1f4f
4a6a00c
350698a
b9ce360
2120b43
2422d1d
4832121
ffd04ca
29d257b
434546a
7600b69
d905aa0
c9f55d2
3bf4044
6530910
7203c98
dc7437d
457055a
fb8c9f7
d72fe2f
2b1d070
aefe5ed
f2afbc7
32f8c80
bba0688
4989460
67ba7ce
7f09b2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,12 +240,30 @@ | |
id: ++_error_id | ||
}); | ||
let _error_id = -1; | ||
|
||
let user_left_page: boolean = false; | ||
document.addEventListener("visibilitychange", function () { | ||
if (document.visibilityState === "hidden") { | ||
user_left_page = true; | ||
} | ||
}); | ||
|
||
const MESSAGE_QUOTE_RE = /^'([^]+)'$/; | ||
|
||
const DUPLICATE_MESSAGE = | ||
"There is a long queue of requests pending. Duplicate this Space to skip."; | ||
const MOBILE_QUEUE_WARNING = | ||
"On mobile, the connection can break if this tab is unfocused or the device sleeps, losing your position in queue."; | ||
const MOBILE_RECONNECT_MESSAGE = | ||
"Lost connection due to leaving page. Rejoining queue..."; | ||
const SHOW_DUPLICATE_MESSAGE_ON_ETA = 15; | ||
const SHOW_MOBILE_QUEUE_WARNING_ON_ETA = 10; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps also set this to 15 seconds like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I chose 10 seconds specifically because that's how long it seems iPhones break a websocket connection on low power mode. I don't think there's any need for these to match There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That should probably be documented in a comment near the constant :) |
||
const is_mobile_device = | ||
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( | ||
navigator.userAgent | ||
); | ||
let showed_duplicate_message = false; | ||
let showed_mobile_warning = false; | ||
|
||
const trigger_api_call = async ( | ||
dep_index: number, | ||
|
@@ -322,6 +340,18 @@ | |
...messages | ||
]; | ||
} | ||
if ( | ||
!showed_mobile_warning && | ||
is_mobile_device && | ||
status.eta !== undefined && | ||
status.eta > SHOW_MOBILE_QUEUE_WARNING_ON_ETA | ||
) { | ||
showed_mobile_warning = true; | ||
messages = [ | ||
new_message(MOBILE_QUEUE_WARNING, fn_index, "warning"), | ||
...messages | ||
]; | ||
} | ||
|
||
if (status.stage === "complete") { | ||
dependencies.map(async (dep, i) => { | ||
|
@@ -332,8 +362,16 @@ | |
|
||
submission.destroy(); | ||
} | ||
|
||
if (status.stage === "error") { | ||
if (status.broken && is_mobile_device && user_left_page) { | ||
window.setTimeout(() => { | ||
messages = [ | ||
new_message(MOBILE_RECONNECT_MESSAGE, fn_index, "error"), | ||
...messages | ||
]; | ||
}, 0); | ||
trigger_api_call(dep_index, event_data); | ||
user_left_page = false; | ||
} else if (status.stage === "error") { | ||
if (status.message) { | ||
const _message = status.message.replace( | ||
MESSAGE_QUOTE_RE, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this to the correct changelog release section!