Comments (6)
I have the same issue. When connecting, the roster comes back with presence. When resuming, the roster comes back but without presence.
I'm thinking of storing the roster in local storage on each page unload and bringing it back up when a resume happens...
from jsjac.
Sorry but this won't work as you expect. That's because you're not doing a new login upon reconnecting. Thus you have to store the state of the roster on your own and restore it after resuming. Local storage might indeed be an option to handle this.
from jsjac.
Unfortunately, there is one severe issue here, even when storing the roster in local storage for page transitions.
When adding a user to the roster after resuming, you will not receive the new user's presence information, even if they are online.
from jsjac.
How are you adding this new user?
Am 12.04.2012 um 22:48 schrieb Eric Colman [email protected]:
Unfortunately, there is one severe issue here, even when storing the roster in local storage for page transitions.
When adding a user to the roster after resuming, you will not receive the new user's presence information, even if they are online.
Reply to this email directly or view it on GitHub:
#28 (comment)
from jsjac.
Here is the code, basically getting a subscription, gathering all groups the user is going to be in and already in, then sending off IQ msg:
function addUserToGroup(xid, nickname, subscription, groups) {
// subscribe to user
sendSubscribe(xid, 'subscribe');
// setup roster, send IQ msg to change groups for this contact
var iq = new JSJaCIQ();
iq.setType('set');
var query = iq.setQuery('jabber:iq:roster');
var item = query.appendChild(iq.buildNode('item', { 'xmlns': 'jabber:iq:roster', 'jid': xid }));
if (subscription)
item.setAttribute('subscription', subscription);
if (nickname)
item.setAttribute('name', nickname);
// check if groups are in an array, if not, make it one
var g = new Array();
if (groups.constructor.toString().indexOf("Array") != -1) {
g = groups;
} else {
g.push(groups);
}
// append all current groups this user is already in to the groups array
var existing = listGroupsForUser(xid);
for (i = 0; i < existing.length; i++) {
if (jQuery.inArray(existing[i], g) == -1) {
g.push(existing[i]);
}
}
// loop all groups and add them to IQ msg
if (g && g.length) {
for (i in g) {
item.appendChild(iq.buildNode('group', { 'xmlns': 'jabber:iq:roster' }, g[i]));
}
}
this.con.send(iq);
}
function sendSubscribe(to, type) {
sendPresence(to, type, '', status);
}
function sendPresence(to, type, show, status, checksum, limit_history, password, handle) {
if (this.con) {
var priority = '100';
if (show == 'available') show = '';
if (type == 'available') type = '';
if (!checksum || (checksum == 'none')) checksum = '';
// New presence
var presence = new JSJaCPresence();
// Presence headers
if (to) presence.setTo(to);
if (type) presence.setType(type);
if (show) presence.setShow(show);
if (status) presence.setStatus(status);
presence.setPriority(priority);
this.con.send(presence);
}
}
function listGroupsForUser(xid) {
for (i = 0; i < roster.length; i++) {
if (roster[i].xid == xid) {
return roster[i].groups;
}
}
return new Array();
}
from jsjac.
Of course you will receive presence only after the recipient has acknowledged your subscription request. But given those packets were sent correctly this should work then.
Am 13.04.2012 um 16:37 schrieb Eric Colman [email protected]:
Here is the code, basically getting a subscription, gathering all groups the user is going to be in and already in, then sending off IQ msg:
function addUserToGroup(xid, nickname, subscription, groups) {
// subscribe to user
sendSubscribe(xid, 'subscribe');// setup roster, send IQ msg to change groups for this contact
var iq = new JSJaCIQ();
iq.setType('set');
var query = iq.setQuery('jabber:iq:roster');
var item = query.appendChild(iq.buildNode('item', { 'xmlns': 'jabber:iq:roster', 'jid': xid }));if (subscription)
item.setAttribute('subscription', subscription);if (nickname)
item.setAttribute('name', nickname);// check if groups are in an array, if not, make it one
var g = new Array();
if (groups.constructor.toString().indexOf("Array") != -1) {
g = groups;
} else {
g.push(groups);
}// append all current groups this user is already in to the groups array
var existing = listGroupsForUser(xid);
for (i = 0; i < existing.length; i++) {
if (jQuery.inArray(existing[i], g) == -1) {
g.push(existing[i]);
}
}// loop all groups and add them to IQ msg
if (g && g.length) {
for (i in g) {
item.appendChild(iq.buildNode('group', { 'xmlns': 'jabber:iq:roster' }, g[i]));
}
}this.con.send(iq);
}function sendSubscribe(to, type) {
sendPresence(to, type, '', status);
}function sendPresence(to, type, show, status, checksum, limit_history, password, handle) {
if (this.con) {
var priority = '100';
if (show == 'available') show = '';
if (type == 'available') type = '';
if (!checksum || (checksum == 'none')) checksum = '';// New presence var presence = new JSJaCPresence(); // Presence headers if (to) presence.setTo(to); if (type) presence.setType(type); if (show) presence.setShow(show); if (status) presence.setStatus(status); presence.setPriority(priority); this.con.send(presence);
}
}function listGroupsForUser(xid) {
for (i = 0; i < roster.length; i++) {
if (roster[i].xid == xid) {
return roster[i].groups;
}
}return new Array();
}
Reply to this email directly or view it on GitHub:
#28 (comment)
from jsjac.
Related Issues (20)
- unable to use JsJaC facebook chat client library to my web site ........ i read the read me in the JSJAC but have no idea about how to implement this client library in my website..... and how i can use this link to utilize bosh server "https://jappix.com HOT 4
- Unable to connect to OpenFire HOT 16
- Support method chaining for registerHandler
- get roster presence HOT 2
- jsjac simpleclient android app ( via phonegap ) , doesn't support websocket HOT 5
- XEPs and RFCs support page with version HOT 5
- Handle WebSocket stream termination HOT 1
- ondisconnect not being triggered HOT 1
- Latest release HOT 1
- 503 error HOT 1
- Send 'away' status on before unload event HOT 6
- In firefox doesn`t work adding users to roster. HOT 11
- Websockets Prebound session HOT 2
- Possible to not use cookie? HOT 2
- BOSH over websocket not work. HOT 2
- in Chrom v56.0.2924.87 (正式版本) (32 位) XMLHTTPReaust error HOT 1
- How to implement XEP-0163 PEP function in jsjac? HOT 6
- XMPP Core HOT 2
- Synchronous XMLHttpRequest on the main thread is deprecated
- Support XEP-0184: Message Delivery Receipts HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsjac.