--
You received this message because you are subscribed to the Google Groups "Strophe" group.
To post to this group, send email to str...@googlegroups.com.
To unsubscribe from this group, send email to strophe+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/strophe?hl=en.
Chat.connection.connect(username+"@"+Chat.DOMAIN, password, function(status){
if (status === Strophe.Status.CONNECTED) {
if(existsData("rooms"))
{
var rooms = selectData("rooms");
var roomArray = rooms.split(",");
var roomLength = roomArray.length;
for(var i = 0; i<roomLength; i++)
{
Chat.joinRoom(roomArray[i]+"@"+Chat.CONFERENCE_SERVICE);
}
}
//setting own presence as online
Chat.connection.send($pres({
from:username+"@"+Chat.DOMAIN
}).c("priority",{}).cnode(Strophe.xmlTextNode("1")).tree());
//Setting variables
Chat.friendlyName = username;
Chat.jid = Chat.connection.jid;
Chat.sid = Chat.connection.sid;
Chat.rid = Chat.connection.rid;
//Setting listener for message, group message, invitation etc
Chat.setUpHandler();
setTimeout(function() {
$('#transparentLoadingGrid').css('display', 'none');
$('#transparentLoadingGrid').css('z-index', '-1');
$('#transparentLoadingGrid').css('visibility', 'hidden');
//$('#attach-options').css('top', '224px');
}, 2000);
User.getFriends();
Chat.addFriends(User.myFriends);
User.setDefaultStatus();
if(callback && typeof(callback)==="function")
{
if(args != null && args != undefined)
{
callback(args)
}
else
{
callback();
}
}
} else if (status === Strophe.Status.DISCONNECTED) {
//alert("ReConnecting again...");
User.getProfile();
Chat.doConnection();
Chat.doLogin(User.userProfileobj.twentyatUserId, User.userProfileobj.email);
//trigger UI to disable chat
setTimeout(function() {
$('#transparentLoadingGrid').css('display', 'none');
$('#transparentLoadingGrid').css('z-index', '-1');
$('#transparentLoadingGrid').css('visibility', 'hidden');
//$('#attach-options').css('top', '224px');
}, 2000);
User.getFriends();
}
If presence is found offline, re-connect before sending the message -
doDisconnect : function()
{
$.ajax({
url: "http://"+Chat.DOMAIN+":9090/plugins/presence/status",
dataType : "jsonp",
contentType: "application/json",
type : "GET",
data : {"jid":User.userProfileobj.twentyatUserId+"@"+Chat.DOMAIN, "type":"json"},
success : function(status)
{
if(status.presence === "offline")
{
Chat.connection == null;
User.getConnection();
}
else
{
if(Chat.connection != null)
{
Chat.connection.sync = true; // Switch to using synchronous requests since this is typically called onUnload.
Chat.connection.disconnect();
Chat.connection.flush();
Chat.connection = null;
}
else
{
Chat.connection == null;
User.getConnection();
}
}
},
error : function(error)
{
if(Chat.connection != null)
{
Chat.connection.sync = true; // Switch to using synchronous requests since this is typically called onUnload.
Chat.connection.disconnect();
Chat.connection.flush();
Chat.connection = null;
}
else
{
Chat.connection == null;
User.getConnection();
}
}
});
On resume disconnect, the connection is done automatically by code in begining -
function onResume()
{
try
{
Chat.doDisconnect();
$('#transparentLoadingGrid').css('display', 'block');
$('#transparentLoadingGrid').css('z-index', '10000');
$('#transparentLoadingGrid').css('visibility', 'visible');
//Chat.connection = null;
//User.getConnection();
}
catch(e)
{
//alert(e);
}
}
Let me know if you have any questions.
Thanks for your help!
BR,
Himanshu
There's an implicit acking mechanism when using BOSH. If the BOSH HTTP
request to the server comes back succesfully, then you can assume that
all stanzas in that request made it to the server. What you can do is
add send/receive hooks into Strophe that will keep track of which
stanzas failed to be sent (add all outgoing stanzas to a list, and
remove them when the response comes back). Then you can re-send
unsuccessful stanzas on reconnection.
Also, there's XEP-0198 that supports acks at the XMPP level, but does
not yet have widespread server support.
Ilya
//alert("ReConnecting again...");
User.getProfile();
Chat.doConnection();
Chat.doLogin(User.userProfileobj.twentyatUserId, User.userProfileobj.email);
Thanks,
Himanshu
--
I don't think there's much you can do about a bad network connection.
The best you can do is to handle frequent disconnects and make sure that
you don't lose any messages. If you like, I can point you to a
connection manager plugin that I wrote that does the BOSH acking that I
described. It works well for us on mobile networks.
> I am sure XMPP and strophe are widely used in production chat
> application on phones too so how is this handled?
> Below is the code, I am talking about -
> if (status === Strophe.Status.DISCONNECTED) {
>
> //alert("ReConnecting again...");
>
> User.getProfile();
>
> Chat.doConnection();
>
> Chat.doLogin(User.userProfileobj.twentyatUserId,
> User.userProfileobj.email);
>
It's not clear to me what your code is doing. It looks like you are
making synchronous calls to functions that should probably be
asynchronous. Do User.getProfile() and Chat.doConnection() make network
calls?
Also, your code to send presence can be simplified to just:
Chat.connection.send($pres().c("priority").t("1").tree());
Ilya
I am sure XMPP and strophe are widely used in production chat application on phones too so how is this handled?
Below is the code, I am talking about -
if (status === Strophe.Status.DISCONNECTED) {
//alert("ReConnecting again...");
User.getProfile();
Chat.doConnection();
Chat.doLogin(User.userProfileobj.twentyatUserId, User.userProfileobj.email);
Ilya
I don't think there's much you can do about a bad network connection. The best you can do is to handle frequent disconnects and make sure that you don't lose any messages. If you like, I can point you to a connection manager plugin that I wrote that does the BOSH acking that I described. It works well for us on mobile networks.
>>>> How to not loose any messages is the main thing ;)??
>>>>Please point me to the connection manager plugin.
It's not clear to me what your code is doing. It looks like you are making synchronous calls to functions that should probably be asynchronous. Do User.getProfile() and Chat.doConnection() make network calls?
I am sure XMPP and strophe are widely used in production chat application on phones too so how is this handled?
Below is the code, I am talking about -
if (status === Strophe.Status.DISCONNECTED) {
//alert("ReConnecting again...");
User.getProfile();
Chat.doConnection();
Chat.doLogin(User.userProfileobj.twentyatUserId, User.userProfileobj.email);
>>>>> None of them make network calls, get profile gets username/password for login and do connection creates a connection object.