Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
c646879c
Commit
c646879c
authored
Dec 06, 2019
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ping the server when the tab becomes visible
parent
5b507ec7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
5 deletions
+16
-5
src/headless/converse-ping.js
src/headless/converse-ping.js
+16
-5
No files found.
src/headless/converse-ping.js
View file @
c646879c
...
...
@@ -72,6 +72,7 @@ converse.plugins.add('converse-ping', {
},
1000
);
/************************ BEGIN Event Handlers ************************/
const
onConnected
=
function
()
{
// Wrapper so that we can spy on registerPingHandler in tests
registerPongHandler
();
...
...
@@ -81,16 +82,26 @@ converse.plugins.add('converse-ping', {
_converse
.
api
.
listen
.
on
(
'
reconnected
'
,
onConnected
);
function
onWindowStateChanged
(
data
)
{
if
(
data
.
state
===
'
visible
'
&&
_converse
.
api
.
connection
.
connected
())
{
_converse
.
api
.
ping
(
null
,
5000
);
}
}
_converse
.
api
.
listen
.
on
(
'
windowStateChanged
'
,
onWindowStateChanged
);
/************************ END Event Handlers ************************/
/************************ BEGIN API ************************/
Object
.
assign
(
_converse
.
api
,
{
/**
* Pings the service represented by the passed in JID by sending an
* IQ stanza.
* Pings the service represented by the passed in JID by sending an IQ stanza.
* @private
* @method _converse.api.ping
* @param { string } [jid] - The JID of the service to ping
* @param { String } [jid] - The JID of the service to ping
* @param { Integer } [timeout] - The amount of time in
* milliseconds to wait for a response. The default is 10000;
*/
async
ping
(
jid
)
{
async
ping
(
jid
,
timeout
)
{
// XXX: We could first check here if the server advertised that it supports PING.
// However, some servers don't advertise while still responding to pings
//
...
...
@@ -104,7 +115,7 @@ converse.plugins.add('converse-ping', {
'
id
'
:
u
.
getUniqueId
(
'
ping
'
)
}).
c
(
'
ping
'
,
{
'
xmlns
'
:
Strophe
.
NS
.
PING
});
const
result
=
await
_converse
.
api
.
sendIQ
(
iq
,
10000
,
false
);
const
result
=
await
_converse
.
api
.
sendIQ
(
iq
,
timeout
||
10000
,
false
);
if
(
result
===
null
)
{
log
.
warn
(
`Timeout while pinging
${
jid
}
`
);
if
(
jid
===
Strophe
.
getDomainFromJid
(
_converse
.
bare_jid
))
{
...
...
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