106
|
1 'use strict';
|
|
2
|
|
3 /**
|
|
4 Copyright (c) 2012, Sonny Piers <sonny at fastmail dot net>
|
|
5
|
|
6 Permission to use, copy, modify, and/or distribute this software for any
|
|
7 purpose with or without fee is hereby granted, provided that the above
|
|
8 copyright notice and this permission notice appear in all copies.
|
|
9
|
|
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
17 */
|
|
18
|
|
19 /*
|
|
20 References:
|
|
21 http://xmpp.org/extensions/xep-0199.html
|
|
22 */
|
|
23
|
|
24 Lightstring.plugins['ping'] = {
|
|
25 namespaces: {
|
|
26 ping: 'urn:xmpp:ping'
|
|
27 },
|
|
28 stanzas: {
|
|
29 ping: function (aTo){
|
|
30 return(
|
|
31 "<iq to='" + aTo + "' type='get'>" +
|
|
32 "<ping xmlns='" + Lightstring.ns.ping + "'/>" +
|
|
33 "</iq>"
|
|
34 );
|
|
35 },
|
|
36 pong: function (aTo){
|
|
37 return "<iq to='" + aTo + "' type='result'/>"
|
|
38 },
|
|
39 },
|
|
40 handlers: {
|
|
41 'iq': function (stanza) {
|
|
42 if (stanza.el.firstChild.localName !== 'ping')
|
|
43 return;
|
|
44
|
|
45 var id = stanza.el.getAttribute('id');
|
|
46 var from = stanza.el.getAttribute('from');
|
|
47 var stanza = Lightstring.stanzas.pong(from);
|
|
48 stanza.setAttribute('id', id);
|
|
49 }
|
|
50 }
|
|
51 }
|
108
|
52 Object.defineProperties(Lightstring.Stanza.prototype, {
|
|
53 'ping': {
|
|
54 get : function() {
|
|
55 return !!(this.el.querySelector('ping'));
|
|
56 },
|
|
57 set: function(aBool) {
|
|
58 if (this.ping)
|
|
59 return;
|
|
60
|
|
61 var pingEl = Lightstring.doc.createElementNS(Lightstring.ns.ping, 'ping');
|
|
62 this.el.appendChild(pingEl);
|
|
63 },
|
|
64 enumerable : true,
|
|
65 configurable : true
|
|
66 },
|
|
67 });
|