Mercurial > eldonilo > lightstring
comparison plugins/presence.js @ 34:6ce66fba0242
Merging.
author | Sonny Piers <sonny.piers@gmail.com> |
---|---|
date | Sat, 28 Jan 2012 04:39:03 +0100 |
parents | 8b739d4e094b |
children | a118a7822410 |
comparison
equal
deleted
inserted
replaced
29:1e6d2ca2daae | 34:6ce66fba0242 |
---|---|
1 'use strict'; | |
2 | |
3 /** | |
4 Copyright (c) 2011, Sonny Piers <sonny at fastmail dot net> | |
5 Copyright (c) 2012, Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | |
6 | |
7 Permission to use, copy, modify, and/or distribute this software for any | |
8 purpose with or without fee is hereby granted, provided that the above | |
9 copyright notice and this permission notice appear in all copies. | |
10 | |
11 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
12 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
13 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
14 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
15 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
16 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
17 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
18 */ | |
19 | |
20 //////////// | |
21 //Presence// http://xmpp.org/rfcs/rfc6121.html#presence | |
22 //////////// | |
23 (function() { | |
24 var legal_types = ['error', 'probe', 'subscribe', 'subscribed', 'unavailable', 'unsubscribe', 'unsubscribed']; | |
25 | |
26 Lightstring.stanza.presence = function(object) { | |
27 if (object) { | |
28 var payloads = ""; | |
29 var attributs = ""; | |
30 if (object.type && legal_types.indexOf(object.type) !== -1) | |
31 attributs += " type='" + object.type + "'"; | |
32 | |
33 if (object.priority) | |
34 payloads += "<priority>" + object.priority + "</priority>"; | |
35 | |
36 if (object.show) | |
37 payloads += "<show>" + object.show + "</show>"; | |
38 | |
39 if (object.status) | |
40 payloads += "<status>" + object.status + "</status>"; | |
41 | |
42 if (object.payload) | |
43 payloads += object.payload; | |
44 | |
45 if (payloads) | |
46 return "<presence" + attributs + ">" + payloads + "</presence>"; | |
47 else | |
48 return "<presence" + attributs + "/>"; | |
49 | |
50 } else | |
51 return "<presence/>"; | |
52 }; | |
53 | |
54 Lightstring.presence = function(aConnection, aObject) { | |
55 aConnection.send(Lightstring.stanza.presence(aObject)); | |
56 }; | |
57 })(); |