Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Small Technology Foundation web site
spikes
patronage
Commits
43459568
Verified
Commit
43459568
authored
Aug 04, 2019
by
Aral Balkan
Browse files
Add client-side connection sanity check before firing a send message
parent
d5dab7d4
Changes
1
Hide whitespace changes
Inline
Side-by-side
.dynamic/client/patron.js
View file @
43459568
...
...
@@ -3,8 +3,6 @@ window.addEventListener('load', _ => {
$
=
document
.
querySelector
.
bind
(
document
)
const
Modal
=
Swal
const
socket
=
new
WebSocket
(
`wss://
${
window
.
location
.
hostname
}
/patron`
)
// Handle connectivity.
...
...
@@ -120,6 +118,13 @@ window.addEventListener('load', _ => {
itemId
}
// Sanity check: socket must be open.
// (Note: our validation should have caught this by this stage and it’s a bug if it hasn’t.)
if
(
socket
.
readyState
!==
WebSocket
.
OPEN
)
{
Modal
.
fire
(
'
Not connected
'
,
`Sorry, we cannot
${
command
.
action
}
your patronage right now as we cannot connect to the server.`
,
'
error
'
)
return
}
if
(
commandName
===
'
update
'
)
{
command
.
amount
=
$
(
'
#patronageAmount
'
).
value
$
(
'
#update-button
'
).
value
=
'
Updating…
'
...
...
@@ -145,7 +150,12 @@ window.addEventListener('load', _ => {
$
(
'
#cancel-button
'
).
value
=
'
Cancelling…
'
}
socket
.
send
(
JSON
.
stringify
(
command
))
try
{
socket
.
send
(
JSON
.
stringify
(
command
))
}
catch
(
error
)
{
console
.
log
(
'
Cannot send message
'
,
error
)
Modal
.
fire
(
'
Cannot send message
'
,
error
,
'
error
'
)
}
})
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment