annotate plugins/presence.js @ 38:d38597574322

add the websocket protocol RFC in the references
author Sonny Piers <sonny.piers@gmail.com>
date Tue, 31 Jan 2012 01:17:55 +0100
parents 8b739d4e094b
children a118a7822410
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() {
fbb08a31921d Improve the presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 30
diff changeset
24 var legal_types = ['error', 'probe', 'subscribe', 'subscribed', 'unavailable', 'unsubscribe', 'unsubscribed'];
fbb08a31921d Improve the presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 30
diff changeset
25
fbb08a31921d Improve the presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 30
diff changeset
26 Lightstring.stanza.presence = function(object) {
32
8b739d4e094b [presence] Don’t require the object to be passed.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 31
diff changeset
27 if (object) {
8b739d4e094b [presence] Don’t require the object to be passed.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 31
diff changeset
28 var payloads = "";
8b739d4e094b [presence] Don’t require the object to be passed.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 31
diff changeset
29 var attributs = "";
8b739d4e094b [presence] Don’t require the object to be passed.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 31
diff changeset
30 if (object.type && legal_types.indexOf(object.type) !== -1)
8b739d4e094b [presence] Don’t require the object to be passed.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 31
diff changeset
31 attributs += " type='" + object.type + "'";
31
fbb08a31921d Improve the presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 30
diff changeset
32
32
8b739d4e094b [presence] Don’t require the object to be passed.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 31
diff changeset
33 if (object.priority)
8b739d4e094b [presence] Don’t require the object to be passed.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 31
diff changeset
34 payloads += "<priority>" + object.priority + "</priority>";
31
fbb08a31921d Improve the presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 30
diff changeset
35
32
8b739d4e094b [presence] Don’t require the object to be passed.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 31
diff changeset
36 if (object.show)
8b739d4e094b [presence] Don’t require the object to be passed.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 31
diff changeset
37 payloads += "<show>" + object.show + "</show>";
31
fbb08a31921d Improve the presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 30
diff changeset
38
32
8b739d4e094b [presence] Don’t require the object to be passed.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 31
diff changeset
39 if (object.status)
8b739d4e094b [presence] Don’t require the object to be passed.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 31
diff changeset
40 payloads += "<status>" + object.status + "</status>";
31
fbb08a31921d Improve the presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 30
diff changeset
41
32
8b739d4e094b [presence] Don’t require the object to be passed.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 31
diff changeset
42 if (object.payload)
8b739d4e094b [presence] Don’t require the object to be passed.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 31
diff changeset
43 payloads += object.payload;
31
fbb08a31921d Improve the presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 30
diff changeset
44
32
8b739d4e094b [presence] Don’t require the object to be passed.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 31
diff changeset
45 if (payloads)
8b739d4e094b [presence] Don’t require the object to be passed.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 31
diff changeset
46 return "<presence" + attributs + ">" + payloads + "</presence>";
8b739d4e094b [presence] Don’t require the object to be passed.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 31
diff changeset
47 else
8b739d4e094b [presence] Don’t require the object to be passed.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 31
diff changeset
48 return "<presence" + attributs + "/>";
31
fbb08a31921d Improve the presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 30
diff changeset
49
32
8b739d4e094b [presence] Don’t require the object to be passed.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 31
diff changeset
50 } else
8b739d4e094b [presence] Don’t require the object to be passed.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 31
diff changeset
51 return "<presence/>";
31
fbb08a31921d Improve the presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 30
diff changeset
52 };
fbb08a31921d Improve the presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 30
diff changeset
53
32
8b739d4e094b [presence] Don’t require the object to be passed.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 31
diff changeset
54 Lightstring.presence = function(aConnection, aObject) {
8b739d4e094b [presence] Don’t require the object to be passed.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 31
diff changeset
55 aConnection.send(Lightstring.stanza.presence(aObject));
31
fbb08a31921d Improve the presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 30
diff changeset
56 };
fbb08a31921d Improve the presence plugin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 30
diff changeset
57 })();