annotate plugins/presence.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
30
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 'use strict';
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 /**
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 Copyright (c) 2011, Sonny Piers <sonny at fastmail dot net>
31
fbb08a31921d Improve the presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 30
diff changeset
5 Copyright (c) 2012, Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
30
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 Permission to use, copy, modify, and/or distribute this software for any
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 purpose with or without fee is hereby granted, provided that the above
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9 copyright notice and this permission notice appear in all copies.
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18 */
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20 ////////////
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21 //Presence// http://xmpp.org/rfcs/rfc6121.html#presence
1506992c33e2 Split plugins.js into multiple plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22 ////////////
31
fbb08a31921d Improve the presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 30
diff changeset
23 (function() {
106
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 84
diff changeset
24 var legal_types = [
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 84
diff changeset
25 'error',
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 84
diff changeset
26 'probe',
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 84
diff changeset
27 'subscribe',
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 84
diff changeset
28 'subscribed',
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 84
diff changeset
29 'unavailable',
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 84
diff changeset
30 'unsubscribe',
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 84
diff changeset
31 'unsubscribed'
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 84
diff changeset
32 ];
31
fbb08a31921d Improve the presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 30
diff changeset
33
48
a118a7822410 Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
34 Lightstring.plugins['presence'] = {
a118a7822410 Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
35 stanzas: {
69
03ccf507ecda Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 48
diff changeset
36 out: function(object) {
48
a118a7822410 Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
37 if (object) {
a118a7822410 Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
38 var payloads = "";
a118a7822410 Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
39 var attributs = "";
a118a7822410 Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
40 if (object.type && legal_types.indexOf(object.type) !== -1)
a118a7822410 Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
41 attributs += " type='" + object.type + "'";
31
fbb08a31921d Improve the presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 30
diff changeset
42
108
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
43 if (object.to)
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
44 attributs += " to='" + object.to + "'";
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
45
48
a118a7822410 Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
46 if (object.priority)
a118a7822410 Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
47 payloads += "<priority>" + object.priority + "</priority>";
31
fbb08a31921d Improve the presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 30
diff changeset
48
48
a118a7822410 Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
49 if (object.show)
a118a7822410 Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
50 payloads += "<show>" + object.show + "</show>";
a118a7822410 Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
51
a118a7822410 Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
52 if (object.status)
a118a7822410 Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
53 payloads += "<status>" + object.status + "</status>";
31
fbb08a31921d Improve the presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 30
diff changeset
54
48
a118a7822410 Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
55 if (object.payload)
a118a7822410 Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
56 payloads += object.payload;
31
fbb08a31921d Improve the presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 30
diff changeset
57
48
a118a7822410 Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
58 if (payloads)
a118a7822410 Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
59 return "<presence" + attributs + ">" + payloads + "</presence>";
a118a7822410 Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
60 else
a118a7822410 Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
61 return "<presence" + attributs + "/>";
31
fbb08a31921d Improve the presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 30
diff changeset
62
48
a118a7822410 Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
63 } else
a118a7822410 Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
64 return "<presence/>";
a118a7822410 Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
65 },
a118a7822410 Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
66 },
a118a7822410 Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
67 methods: {
69
03ccf507ecda Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 48
diff changeset
68 send: function(aObject) {
03ccf507ecda Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 48
diff changeset
69 this.send(Lightstring.stanzas.presence.out(aObject));
48
a118a7822410 Fix presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 32
diff changeset
70 }
108
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
71 },
31
fbb08a31921d Improve the presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 30
diff changeset
72 };
108
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
73
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
74 Object.defineProperties(Lightstring.Stanza.prototype, {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
75 'show': {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
76 get : function() {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
77 return this.el.getAttribute('show');
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
78 },
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
79 enumerable : true,
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
80 configurable : true
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
81 },
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
82 'priority': {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
83 get : function() {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
84 return this.el.getAttribute('priority');
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
85 },
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
86 enumerable : true,
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
87 configurable : true
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
88 },
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
89 'status': {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
90 get : function() {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
91 return this.el.getAttribute('status');
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
92 },
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
93 enumerable : true,
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
94 configurable : true
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
95 },
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
96 })
84
7f4e43d6cb15 My mistake.
Sonny Piers <sonny.piers@gmail.com>
parents: 83
diff changeset
97 })();