Mercurial > eldonilo > lightstring
comparison plugins/presence.js @ 31:fbb08a31921d
Improve the presence plugin.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sat, 28 Jan 2012 02:58:45 +0100 |
parents | 1506992c33e2 |
children | 8b739d4e094b |
comparison
equal
deleted
inserted
replaced
30:1506992c33e2 | 31:fbb08a31921d |
---|---|
1 'use strict'; | 1 'use strict'; |
2 | 2 |
3 /** | 3 /** |
4 Copyright (c) 2011, Sonny Piers <sonny at fastmail dot net> | 4 Copyright (c) 2011, Sonny Piers <sonny at fastmail dot net> |
5 Copyright (c) 2012, Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | |
5 | 6 |
6 Permission to use, copy, modify, and/or distribute this software for any | 7 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 purpose with or without fee is hereby granted, provided that the above |
8 copyright notice and this permission notice appear in all copies. | 9 copyright notice and this permission notice appear in all copies. |
9 | 10 |
17 */ | 18 */ |
18 | 19 |
19 //////////// | 20 //////////// |
20 //Presence// http://xmpp.org/rfcs/rfc6121.html#presence | 21 //Presence// http://xmpp.org/rfcs/rfc6121.html#presence |
21 //////////// | 22 //////////// |
22 Lightstring.stanza.presence = function(aPriority) { | 23 (function() { |
23 if(aPriority) | 24 var legal_types = ['error', 'probe', 'subscribe', 'subscribed', 'unavailable', 'unsubscribe', 'unsubscribed']; |
24 return "<presence><priority>"+aPriority+"</priority></presence>"; | 25 |
25 else | 26 Lightstring.stanza.presence = function(object) { |
26 return "<presence/>"; | 27 var aPriority, aShow, aStatus; |
27 }; | 28 var payloads = ""; |
28 Lightstring.presence = function(aConnection, aPriority) { | 29 var attributs = ""; |
29 aConnection.send(Lightstring.stanza.presence(aPriority)); | 30 |
30 }; | 31 if (object.type && legal_types.indexOf(object.type) !== -1) |
32 attributs += " type='" + object.type + "'"; | |
33 | |
34 if (object.priority) | |
35 payloads += "<priority>" + object.priority + "</priority>"; | |
36 | |
37 if (object.show) | |
38 payloads += "<show>" + object.show + "</show>"; | |
39 | |
40 if (object.status) | |
41 payloads += "<status>" + object.status + "</status>"; | |
42 | |
43 if (object.payload) | |
44 payloads += object.payload; | |
45 | |
46 if (payloads) | |
47 return "<presence" + attributs + ">" + payloads + "</presence>"; | |
48 else | |
49 return "<presence" + attributs + "/>"; | |
50 }; | |
51 | |
52 Lightstring.presence = function(aConnection, aPriority) { | |
53 aConnection.send(Lightstring.stanza.presence(aPriority)); | |
54 }; | |
55 })(); |