annotate plugins/ping.js @ 108:5cb4733c5189

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