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
c4698613
Commit
c4698613
authored
May 27, 2015
by
JC Brand
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #414 from thierrytiti/ping-pong
XEP-0199: XMPP Ping
parents
7c21341d
fb589398
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
173 additions
and
1 deletion
+173
-1
converse.js
converse.js
+53
-0
docs/CHANGES.rst
docs/CHANGES.rst
+1
-0
docs/source/configuration.rst
docs/source/configuration.rst
+11
-0
main.js
main.js
+3
-1
non_amd.html
non_amd.html
+1
-0
src/deps-full.js
src/deps-full.js
+1
-0
src/deps-no-otr.js
src/deps-no-otr.js
+1
-0
src/deps-website-no-otr.js
src/deps-website-no-otr.js
+1
-0
src/deps-website.js
src/deps-website.js
+1
-0
src/strophe.ping.js
src/strophe.ping.js
+100
-0
No files found.
converse.js
View file @
c4698613
...
@@ -276,6 +276,7 @@
...
@@ -276,6 +276,7 @@
keepalive
:
false
,
keepalive
:
false
,
message_carbons
:
false
,
message_carbons
:
false
,
no_trimming
:
false
,
// Set to true for phantomjs tests (where browser apparently has no width)
no_trimming
:
false
,
// Set to true for phantomjs tests (where browser apparently has no width)
ping_interval
:
180
,
//in seconds
play_sounds
:
false
,
play_sounds
:
false
,
sounds_path
:
'
/sounds/
'
,
sounds_path
:
'
/sounds/
'
,
password
:
undefined
,
password
:
undefined
,
...
@@ -663,10 +664,57 @@
...
@@ -663,10 +664,57 @@
},
this
),
200
));
},
this
),
200
));
};
};
this
.
ping
=
function
(
jid
,
success
,
error
,
timeout
){
//var feature = converse.features.findWhere({'var': Strophe.NS.PING});
//if (feature) {
converse
.
lastMessage
=
new
Date
();
if
(
typeof
jid
===
'
undefined
'
||
jid
==
null
)
{
jid
=
converse
.
bare_jid
;
}
if
(
typeof
timeout
===
'
undefined
'
)
{
timeout
=
null
;
}
if
(
typeof
success
===
'
undefined
'
)
{
success
=
null
;
}
if
(
typeof
error
===
'
undefined
'
)
{
error
=
null
;
}
if
(
converse
.
connection
)
{
converse
.
connection
.
ping
.
ping
(
jid
,
success
,
error
,
timeout
);
return
true
};
//}
return
false
;
};
this
.
pong
=
function
(
ping
){
converse
.
lastMessage
=
new
Date
();
converse
.
connection
.
ping
.
pong
(
ping
);
return
true
;
};
this
.
registerPongHandler
=
function
(){
var
feature
=
converse
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
PING
});
if
(
feature
)
{
converse
.
connection
.
disco
.
addFeature
(
Strophe
.
NS
.
PING
);
converse
.
connection
.
ping
.
addPingHandler
(
this
.
pong
);
}
};
this
.
registerPingHandler
=
function
(){
if
(
this
.
ping_interval
>
0
){
//handler on each message : save last message date in order to ping only when needed
converse
.
connection
.
addHandler
(
function
(){
converse
.
lastMessage
=
new
Date
();});
converse
.
connection
.
addTimedHandler
(
1000
,
function
()
{
now
=
new
Date
();
if
(
!
converse
.
lastMessage
)
converse
.
lastMessage
=
now
;
if
((
now
-
converse
.
lastMessage
)
/
1000
>
converse
.
ping_interval
){
return
converse
.
ping
();
}
return
true
;
});
}
};
this
.
onReconnected
=
function
()
{
this
.
onReconnected
=
function
()
{
// We need to re-register all the event handlers on the newly
// We need to re-register all the event handlers on the newly
// created connection.
// created connection.
this
.
initStatus
(
$
.
proxy
(
function
()
{
this
.
initStatus
(
$
.
proxy
(
function
()
{
this
.
registerPongHandler
();
this
.
registerPingHandler
();
this
.
rosterview
.
registerRosterXHandler
();
this
.
rosterview
.
registerRosterXHandler
();
this
.
rosterview
.
registerPresenceHandler
();
this
.
rosterview
.
registerPresenceHandler
();
this
.
chatboxes
.
registerMessageHandler
();
this
.
chatboxes
.
registerMessageHandler
();
...
@@ -713,6 +761,8 @@
...
@@ -713,6 +761,8 @@
this
.
enableCarbons
();
this
.
enableCarbons
();
this
.
initStatus
(
$
.
proxy
(
function
()
{
this
.
initStatus
(
$
.
proxy
(
function
()
{
this
.
registerPingHandler
();
this
.
registerPongHandler
();
this
.
chatboxes
.
onConnected
();
this
.
chatboxes
.
onConnected
();
this
.
giveFeedback
(
__
(
'
Contacts
'
));
this
.
giveFeedback
(
__
(
'
Contacts
'
));
if
(
this
.
callback
)
{
if
(
this
.
callback
)
{
...
@@ -5828,6 +5878,9 @@
...
@@ -5828,6 +5878,9 @@
'
send
'
:
function
(
stanza
)
{
'
send
'
:
function
(
stanza
)
{
converse
.
connection
.
send
(
stanza
);
converse
.
connection
.
send
(
stanza
);
},
},
'
ping
'
:
function
(
jid
)
{
converse
.
ping
(
jid
);
},
'
plugins
'
:
{
'
plugins
'
:
{
'
add
'
:
function
(
name
,
callback
)
{
'
add
'
:
function
(
name
,
callback
)
{
converse
.
plugins
[
name
]
=
callback
;
converse
.
plugins
[
name
]
=
callback
;
...
...
docs/CHANGES.rst
View file @
c4698613
...
@@ -16,6 +16,7 @@ Changelog
...
@@ -16,6 +16,7 @@ Changelog
* I18N: Autodetection of User Locale if no i18n setting is set. [thierrytiti]
* I18N: Autodetection of User Locale if no i18n setting is set. [thierrytiti]
* CSS: Fonts Path: editabable $font-path via sass/variables.scss [thierrytiti]
* CSS: Fonts Path: editabable $font-path via sass/variables.scss [thierrytiti]
* Add offline pretty status to enable translation [thierrytiti]
* Add offline pretty status to enable translation [thierrytiti]
* Add Ping funcionnality and Pong Handler (Fix to issue #144) [thierrytiti]
0.9.3 (2015-05-01)
0.9.3 (2015-05-01)
------------------
------------------
...
...
docs/source/configuration.rst
View file @
c4698613
...
@@ -368,6 +368,17 @@ Specify the locale/language. The language must be in the ``locales`` object. Ref
...
@@ -368,6 +368,17 @@ Specify the locale/language. The language must be in the ``locales`` object. Ref
.. _`play-sounds`:
.. _`play-sounds`:
ping_interval
-------------
* Default: ``300``
Make ping to server in order to keep connection with server killing sessions after idle timeout.
The ping are sent only if no messages are sent in the last ``ping_interval`` seconds
You need to set the value to any positive value to enable this functionality.
If you set this value to ``0`` or any negative value, il will disable this functionality.
play_sounds
play_sounds
-----------
-----------
...
...
main.js
View file @
c4698613
...
@@ -38,6 +38,7 @@ require.config({
...
@@ -38,6 +38,7 @@ require.config({
"
strophe.disco
"
:
"
components/strophejs-plugins/disco/strophe.disco
"
,
"
strophe.disco
"
:
"
components/strophejs-plugins/disco/strophe.disco
"
,
"
strophe.roster
"
:
"
src/strophe.roster
"
,
"
strophe.roster
"
:
"
src/strophe.roster
"
,
"
strophe.vcard
"
:
"
src/strophe.vcard
"
,
"
strophe.vcard
"
:
"
src/strophe.vcard
"
,
"
strophe.ping
"
:
"
src/strophe.ping
"
,
"
text
"
:
'
components/requirejs-text/text
'
,
"
text
"
:
'
components/requirejs-text/text
'
,
"
tpl
"
:
'
components/requirejs-tpl-jcbrand/tpl
'
,
"
tpl
"
:
'
components/requirejs-tpl-jcbrand/tpl
'
,
"
typeahead
"
:
"
components/typeahead.js/index
"
,
"
typeahead
"
:
"
components/typeahead.js/index
"
,
...
@@ -170,7 +171,8 @@ require.config({
...
@@ -170,7 +171,8 @@ require.config({
'
strophe.disco
'
:
{
deps
:
[
'
strophe
'
]
},
'
strophe.disco
'
:
{
deps
:
[
'
strophe
'
]
},
'
strophe.register
'
:
{
deps
:
[
'
strophe
'
]
},
'
strophe.register
'
:
{
deps
:
[
'
strophe
'
]
},
'
strophe.roster
'
:
{
deps
:
[
'
strophe
'
]
},
'
strophe.roster
'
:
{
deps
:
[
'
strophe
'
]
},
'
strophe.vcard
'
:
{
deps
:
[
'
strophe
'
]
}
'
strophe.vcard
'
:
{
deps
:
[
'
strophe
'
]
},
'
strophe.ping
'
:
{
deps
:
[
'
strophe
'
]
}
}
}
});
});
...
...
non_amd.html
View file @
c4698613
...
@@ -35,6 +35,7 @@
...
@@ -35,6 +35,7 @@
<script
type=
"text/javascript"
src=
"src/strophe.roster.js"
></script>
<script
type=
"text/javascript"
src=
"src/strophe.roster.js"
></script>
<script
type=
"text/javascript"
src=
"components/strophejs-plugins/vcard/strophe.vcard.js"
></script>
<script
type=
"text/javascript"
src=
"components/strophejs-plugins/vcard/strophe.vcard.js"
></script>
<script
type=
"text/javascript"
src=
"components/strophejs-plugins/disco/strophe.disco.js"
></script>
<script
type=
"text/javascript"
src=
"components/strophejs-plugins/disco/strophe.disco.js"
></script>
<script
type=
"text/javascript"
src=
"src/strophe.ping.js"
></script>
<script
type=
"text/javascript"
src=
"components/underscore/underscore.js"
></script>
<script
type=
"text/javascript"
src=
"components/underscore/underscore.js"
></script>
<script
type=
"text/javascript"
src=
"components/backbone//backbone.js"
></script>
<script
type=
"text/javascript"
src=
"components/backbone//backbone.js"
></script>
<script
type=
"text/javascript"
src=
"components/backbone.browserStorage/backbone.browserStorage.js"
></script>
<script
type=
"text/javascript"
src=
"components/backbone.browserStorage/backbone.browserStorage.js"
></script>
...
...
src/deps-full.js
View file @
c4698613
...
@@ -6,6 +6,7 @@ define("converse-dependencies", [
...
@@ -6,6 +6,7 @@ define("converse-dependencies", [
"
strophe
"
,
"
strophe
"
,
"
strophe.vcard
"
,
"
strophe.vcard
"
,
"
strophe.disco
"
,
"
strophe.disco
"
,
"
strophe.ping
"
,
"
backbone.browserStorage
"
,
"
backbone.browserStorage
"
,
"
backbone.overview
"
,
"
backbone.overview
"
,
"
jquery.browser
"
,
"
jquery.browser
"
,
...
...
src/deps-no-otr.js
View file @
c4698613
...
@@ -5,6 +5,7 @@ define("converse-dependencies", [
...
@@ -5,6 +5,7 @@ define("converse-dependencies", [
"
strophe
"
,
"
strophe
"
,
"
strophe.vcard
"
,
"
strophe.vcard
"
,
"
strophe.disco
"
,
"
strophe.disco
"
,
"
strophe.ping
"
,
"
backbone.browserStorage
"
,
"
backbone.browserStorage
"
,
"
backbone.overview
"
,
"
backbone.overview
"
,
"
jquery.browser
"
,
"
jquery.browser
"
,
...
...
src/deps-website-no-otr.js
View file @
c4698613
...
@@ -5,6 +5,7 @@ define("converse-dependencies", [
...
@@ -5,6 +5,7 @@ define("converse-dependencies", [
"
strophe
"
,
"
strophe
"
,
"
strophe.vcard
"
,
"
strophe.vcard
"
,
"
strophe.disco
"
,
"
strophe.disco
"
,
"
strophe.ping
"
,
"
bootstrapJS
"
,
// XXX: Can be removed, only for https://conversejs.org
"
bootstrapJS
"
,
// XXX: Can be removed, only for https://conversejs.org
"
backbone.browserStorage
"
,
"
backbone.browserStorage
"
,
"
backbone.overview
"
,
"
backbone.overview
"
,
...
...
src/deps-website.js
View file @
c4698613
...
@@ -7,6 +7,7 @@ define("converse-dependencies", [
...
@@ -7,6 +7,7 @@ define("converse-dependencies", [
"
strophe
"
,
"
strophe
"
,
"
strophe.vcard
"
,
"
strophe.vcard
"
,
"
strophe.disco
"
,
"
strophe.disco
"
,
"
strophe.ping
"
,
"
bootstrapJS
"
,
// XXX: Only for https://conversejs.org
"
bootstrapJS
"
,
// XXX: Only for https://conversejs.org
"
backbone.browserStorage
"
,
"
backbone.browserStorage
"
,
"
backbone.overview
"
,
"
backbone.overview
"
,
...
...
src/strophe.ping.js
0 → 100644
View file @
c4698613
/*
* Based on Ping Strophejs plugins (https://github.com/metajack/strophejs-plugins/tree/master/ping)
* This plugin is distributed under the terms of the MIT licence.
* Please see the LICENCE file for details.
*
* Copyright (c) Markus Kohlhase, 2010
* Refactored by Pavel Lang, 2011
*/
/**
* File: strophe.ping.js
* A Strophe plugin for XMPP Ping ( http://xmpp.org/extensions/xep-0199.html )
*/
/*
* AMD Support added by Thierry
*
*/
(
function
(
root
,
factory
)
{
if
(
typeof
define
===
'
function
'
&&
define
.
amd
)
{
// AMD. Register as an anonymous module.
define
([
"
strophe
"
],
function
(
Strophe
)
{
factory
(
Strophe
.
Strophe
,
Strophe
.
$build
,
Strophe
.
$iq
,
Strophe
.
$msg
,
Strophe
.
$pres
);
return
Strophe
;
});
}
else
{
// Browser globals
factory
(
root
.
Strophe
,
root
.
$build
,
root
.
$iq
,
root
.
$msg
,
root
.
$pres
);
}
}(
this
,
function
(
Strophe
,
$build
,
$iq
,
$msg
,
$pres
)
{
Strophe
.
addConnectionPlugin
(
'
ping
'
,
{
_c
:
null
,
// called by the Strophe.Connection constructor
init
:
function
(
conn
)
{
this
.
_c
=
conn
;
Strophe
.
addNamespace
(
'
PING
'
,
"
urn:xmpp:ping
"
);
},
/**
* Function: ping
*
* Parameters:
* (String) to - The JID you want to ping
* (Function) success - Callback function on success
* (Function) error - Callback function on error
* (Integer) timeout - Timeout in milliseconds
*/
ping
:
function
(
jid
,
success
,
error
,
timeout
)
{
var
id
=
this
.
_c
.
getUniqueId
(
'
ping
'
);
var
iq
=
$iq
({
type
:
'
get
'
,
to
:
jid
,
id
:
id
}).
c
(
'
ping
'
,
{
xmlns
:
Strophe
.
NS
.
PING
});
this
.
_c
.
sendIQ
(
iq
,
success
,
error
,
timeout
);
},
/**
* Function: pong
*
* Parameters:
* (Object) ping - The ping stanza from the server.
*/
pong
:
function
(
ping
)
{
var
from
=
ping
.
getAttribute
(
'
from
'
);
var
id
=
ping
.
getAttribute
(
'
id
'
);
var
iq
=
$iq
({
type
:
'
result
'
,
to
:
from
,
id
:
id
});
this
.
_c
.
sendIQ
(
iq
);
},
/**
* Function: addPingHandler
*
* Parameters:
* (Function) handler - Ping handler
*
* Returns:
* A reference to the handler that can be used to remove it.
*/
addPingHandler
:
function
(
handler
)
{
return
this
.
_c
.
addHandler
(
handler
,
Strophe
.
NS
.
PING
,
"
iq
"
,
"
get
"
);
}
});
}));
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