Help
Ask questions about how to do or fix things in Arrowchat
User avatar
zoxtrix
Customer
 
Posts: 74
Joined: 29 Jun 2019, 19:31

 

by zoxtrix 01 Aug 2019, 12:04

I've made a new discovery relevant to the bug. If I change line 461 of the arrowchat_mobile.js fiile from ...
Code: Select all
if (c_push_engine != 1) {
-TO-
Code: Select all
if (c_push_engine != 0) {
... it completely eliminates the message failures. That is, they will no longer occur no matter what I do or how many hundreds of test messages I send to the mobile test device. The drawback is that once I make this change, the mobile tab ceases to receive alert notifications for new user-to-user messages. This suggests to me that the message delivery failure bug is somehow connected with the push service coding and the notification alert mechanism. Hopefully this information may help ArrowChat isolate and fix the bug.

And by the way, my continued testing indicates that the best workaround adjustment value set for line 460 may be 9000 * 3 (this value set produces the lowest failure frequency of any I've tried so far). A value set of 27000 * 1 may produce an equal result.
User avatar
zoxtrix
Customer
 
Posts: 74
Joined: 29 Jun 2019, 19:31

 

by zoxtrix 01 Aug 2019, 18:35

** I HAVE FINALLY COME UP WITH A REAL SOLUTION **

I've discovered a way to eliminate 100% of the user-to-user incoming message failures on mobile devices (when ArrowChat's push service is not utilized) and retain the mobile tab alert functionality. You can consider this one a FIX if you like.

I've tested this solution fairly stringently. Still, it makes good sense to be mindful that there could be unintended behaviors I may have missed. Moreover, ArrowChat may wish to clean up my code adjustments or even provide a different, better way to resolve the bug that my effort here addresses. I will say, however, that I've done enough testing today to feel confident telling you that this solution genuinely seems to work.

Here's what I did. I removed all of the code pertaining to the push service in the arrowchat_mobile.js file. I then adjusted parts of the remaining code so it doesn't look for or expect the push service code. Obviously this solution is directed toward ArrowChat customers who don't intend to subscribe to the push service. If you're using the push service I don't believe you're likely to encounter the mobile message failures anyway.

Instructions

1. If you wish to implement this fix, find the following file in your /arrowchat directory:

/includes/js/arrowchat_mobile.js

2. Rename the file to something that denotes its new status as a backup in case you need to roll things back as they were (e.g., you can simply rename it to arrowchat_mobile.js.bak).

3. Next, create a new file named arrowchat_mobile.js in the same directory.

4. Finally, paste the following code in its entirety into the newly created arrowchat_mobile.js file and save it.
Code: Select all
if(typeof(jqac) === 'undefined') {
	jqac = jQuery;
}

/*!
  jQuery Cookie Plugin v1.4.0
  https://github.com/carhartl/jquery-cookie
 */
(function(factory){if(typeof define==='function'&&define.amd){define(['jqac'],factory);}else{factory(jqac);}}(function($){var pluses=/\+/g;function encode(s){return config.raw?s:encodeURIComponent(s);}
function decode(s){return config.raw?s:decodeURIComponent(s);}
function stringifyCookieValue(value){return encode(config.json?JSON.stringify(value):String(value));}
function parseCookieValue(s){if(s.indexOf('"')===0){s=s.slice(1,-1).replace(/\\"/g,'"').replace(/\\\\/g,'\\');}
try{s=decodeURIComponent(s.replace(pluses,' '));return config.json?JSON.parse(s):s;}catch(e){}}
function read(s,converter){var value=config.raw?s:parseCookieValue(s);return $.isFunction(converter)?converter(value):value;}
var config=$.cookie=function(key,value,options){if(value!==undefined&&!$.isFunction(value)){options=$.extend({},config.defaults,options);if(typeof options.expires==='number'){var days=options.expires,t=options.expires=new Date();t.setDate(t.getDate()+days);}
return(document.cookie=[encode(key),'=',stringifyCookieValue(value),options.expires?'; expires='+options.expires.toUTCString():'',options.path?'; path='+options.path:'',options.domain?'; domain='+options.domain:'',options.secure?'; secure':''].join(''));}
var result=key?undefined:{};var cookies=document.cookie?document.cookie.split('; '):[];for(var i=0,l=cookies.length;i<l;i++){var parts=cookies[i].split('=');var name=decode(parts.shift());var cookie=parts.join('=');if(key&&key===name){result=read(cookie,value);break;}
if(!key&&(cookie=read(cookie))!==undefined){result[name]=cookie;}}
return result;};config.defaults={};$.removeCookie=function(key,options){if($.cookie(key)===undefined){return false;}
$.cookie(key,'',$.extend({},options,{expires:-1}));return!$.cookie(key);};}));

(function (a) {
	a.arrowchat = function () {
	
		// Cache frequently used jQuery objects;
		var $body = a('body');
		
		function runarrowchat() {
			if (c_enable_mobile == 1) {
				if (a.cookie('ac_hide_mobile') != 1) {
					$body.append('<div id="arrowchat_mobiletab"><div id="arrowchat_mobiletab_new"><span class="arrowchat_mobiletab_new_count">0</span></div>' + lang[145] + ' (<span id="arrowchat_mobiletab_count">0</span>)</div>');
					$body.append('<div class="arrowchat_notify_box"><div class="arrowchat_notify_box_wrapper"><div class="arrowchat_notify_avatar"></div><div class="arrowchat_notify_info_wrapper"><div class="arrowchat_notify_username"></div><div class="arrowchat_notify_msg"></div></div><div class="arrowchat_clearfix"></div></div></div>');
					a("#arrowchat_mobiletab_new").hide();
					
					loadBuddyList();
					receiveCore();
					
					a("#arrowchat_mobiletab").click(function () {
						window.open(c_ac_path + 'public/mobile/', 'mobiletab', '_blank');
					});
				}
			}
		}
		
		function stripslashes(str) {
			str=str.replace(/\\'/g,'\'');
			str=str.replace(/\\"/g,'"');
			str=str.replace(/\\0/g,'\0');
			str=str.replace(/\\\\/g,'\\');
			return str;
		}
		function receiveMessage(id, from, message, sent, self, old) {
			if (from != u_id && typeof(uc_name[from]) != "undefined") {
				message = stripslashes(message);
				a(".arrowchat_notify_avatar").html('<img src="' + uc_avatar[from] + '" alt="" />');
				a(".arrowchat_notify_username").html(uc_name[from]);
				a(".arrowchat_notify_msg").html(message);
				clearTimeout(message_timeout);
				a(".arrowchat_notify_box").show("slide", { direction: "up"}, 250);
				message_timeout = setTimeout(function () {
					a(".arrowchat_notify_box").hide("slide", { direction: "up"}, 250);
				}, 5000);
				a(".arrowchat_notify_box").unbind('click');
				a(".arrowchat_notify_box").click(function() {
					clearTimeout(message_timeout);
					a(".arrowchat_notify_box").hide();
					window.open(c_ac_path + 'public/mobile/#chatwith-' + from, 'mobiletab', '_blank');
				});
			}
		}
		function addToCount(number) {
			var count = parseInt(a(".arrowchat_mobiletab_new_count").html()) + number;
			var fontSize = parseInt(a('#arrowchat_mobiletab').css('font-size'), 10);
			a("#arrowchat_mobiletab_new").css("line-height", a("#arrowchat_mobiletab").css("font-size"));
			a("#arrowchat_mobiletab_new").css("top", "-" + fontSize/2 + "px");
			a("#arrowchat_mobiletab_new").css("right", fontSize/2 + "px");
			a(".arrowchat_mobiletab_new_count").html(count);
			a("#arrowchat_mobiletab_new").show();
		}
		function loadBuddyList() {
			clearTimeout(Z);
			a.ajax({
				url: c_ac_path + "includes/json/receive/receive_buddylist.php?mobile=1",
				cache: false,
				type: "get",
				dataType: "json",
				success: function (b) {
					buildBuddyList(b);
				}
			});
			if (typeof c_list_heart_beat != "undefined") {
				var BLHT = c_list_heart_beat * 1000;
			} else {
				var BLHT = 60000;
			}
			Z = setTimeout(function () {
				loadBuddyList()			
			}, BLHT)
		}
		function cancelJSONP() {
			if (typeof CHA != "undefined") {
				clearTimeout(CHA);
			}
			if (typeof xOptions != "undefined") {
				xOptions.abort();
			}
		}
		function receiveCore() {
			cancelJSONP();
			var url = c_ac_path + "includes/json/receive/receive_core.php?hash=" + u_hash_id + "&init=" + acsi + "&room=0";
			xOptions = a.ajax({
				url: url,
				dataType: "jsonp",
				success: function (b) {
					var new_messages = 0;
					if (b && b != null) {
						a.each(b, function (e, l) {
							if (e == "messages") {
								a.each(l, function (f, h) {
									if (acsi != 1)
										receiveMessage(h.id, h.from, h.message, h.sent, h.self, 1);
									new_messages++;
								});
							}
						});
					}
					acsi++;
					
					if (new_messages > 0) {
						addToCount(new_messages);
					}
				}
			});
			var CHT = c_heart_beat * 9000 * 3;

                        Z = setTimeout(function () {
                                receiveCore()
                        }, CHT)
			}
		function buildBuddyList(b) {
			var onlineNumber = 0;
			b && a.each(b, function (i, e) {
				if (i == "buddylist") {
					a.each(e, function (l, f) {
						if (f.s == "available" || f.s == "away" || f.s == "busy") 
							onlineNumber++;
                        uc_status[f.id] = f.s;
                        uc_name[f.id] = f.n;
                        uc_avatar[f.id] = f.a;
                        uc_link[f.id] = f.l
					});
					a("#arrowchat_mobiletab_count").html(onlineNumber);
				}
			})
		}
		function scaletab() {
			var zoomFactor = window.innerWidth/document.documentElement.clientWidth;

			if (zoomFactor < 1) {
				a("#arrowchat_mobiletab").hide();
				a(".arrowchat_notify_box").hide();
			} else {
				a("#arrowchat_mobiletab").show();
			}
			
			var fontSize = parseInt(a('#arrowchat_mobiletab').css('font-size'), 10);
			a("#arrowchat_mobiletab_new").css("line-height", a("#arrowchat_mobiletab").css("font-size"));
			a("#arrowchat_mobiletab_new").css("top", "-" + fontSize/2 + "px");
			a("#arrowchat_mobiletab_new").css("right", fontSize/2 + "px");
		}
		
		window.onresize = window.onscroll = function() {
			scaletab();
		};
		window.onload = function() {
			scaletab();
		};
		
		var Z,
			CHT,
			zoomFactor2 = window.innerWidth/document.documentElement.clientWidth,
			message_timeout,
			push_room = {},
			push_uid,
			push_arrowchat,
			acsi = 1;
			
		arguments.callee.chatWith = function (b) {
			window.open(c_ac_path + 'public/mobile/#chatwith-' + b, 'mobiletab', '_blank');
		};
		arguments.callee.runarrowchat = runarrowchat;
	}
})(jqac);

jqac(document).ready(function () {
	if (u_logged_in != 1 && c_disable_arrowchat != 1) {
		jqac.arrowchat();
		jqac.arrowchat.runarrowchat()
	}
});
Your done. That's all there is to it.
User avatar
zoxtrix
Customer
 
Posts: 74
Joined: 29 Jun 2019, 19:31

 

by zoxtrix 02 Aug 2019, 09:48

Some final thoughts...

There's one thing I forgot to mention that may or may not be important. That is, for my testing sessions I had the Message Heart Beat value in the admin panel set to 0.5 seconds. My server handles that setting fine, maintaining extremely low core loads and load averages. After yesterday's modification, I tested for message failures by sending over 500 consecutive messages to mobile devices using both slow and rapid submission rates. I couldn't generate a single message delivery failure during the session - i.e., every message transferred dependably - and I haven't experienced any since.

I'm not feeling up to testing other message heart beat settings or anything else right now. I may however run some additional tests, such as that one, sometime soon. My system currently works and I've decided to take a break from this issue for a bit. If anyone would like to test anything at all related to the bug and report the results in this thread, please do so. I very much think the modification I described yesterday may be beneficial for some of you. Best of luck!
User avatar
lsgdominic
Customer
 
Posts: 7
Joined: 12 Dec 2017, 01:41

 

by lsgdominic 05 Aug 2019, 22:27

Hi Zoxtrix
Thanks for investigating and keeping us updated.

We tried to change the heartbeat to 23000. I tested with my user account, my mobile device and my collegue Content Manager, in 3 blocks, we sent more than 100 messages, each numbered to be able to follow the flow. NO lost messages. Waw!

Next, for the weekend, friday evening and night, and saturday, several chat users reported NO missing messages anymore.
Sunday evening, we got report of 2 users they were waiting some messages, and finally left, because of no chat signs.
There is an average of 5 - 10 users online.

Despite the sunday report, this was / is a huge improvement.

For now, I replaced the arrowchat_mobile.js file following your instructions, that is: the file without references to the push service.

We continue to follow up.

Thanks again for your work! We do appreciate it!
User avatar
zoxtrix
Customer
 
Posts: 74
Joined: 29 Jun 2019, 19:31

 

by zoxtrix 05 Aug 2019, 23:12

Hi Zoxtrix
Thanks for investigating and keeping us updated.

We tried to change the heartbeat to 23000. I tested with my user account, my mobile device and my collegue Content Manager, in 3 blocks, we sent more than 100 messages, each numbered to be able to follow the flow. NO lost messages. Waw!

Next, for the weekend, friday evening and night, and saturday, several chat users reported NO missing messages anymore.
Sunday evening, we got report of 2 users they were waiting some messages, and finally left, because of no chat signs.
There is an average of 5 - 10 users online.

Despite the sunday report, this was / is a huge improvement.

For now, I replaced the arrowchat_mobile.js file following your instructions, that is: the file without references to the push service.

We continue to follow up.

Thanks again for your work! We do appreciate it!
lsgdominic, you are quite welcome. I'm glad to hear my methods have reduced your failure rate.

If you still notice an occasional missed message after changing the code in the arrowchat_mobile.js file to my modified code, try changing the message heart beat in the admin panel to 0.5 to see if that fully eliminates the message failures as it has for me.

Best of luck! And please keep us updated on what is and isn't working for you.
User avatar
lsgdominic
Customer
 
Posts: 7
Joined: 12 Dec 2017, 01:41

 

by lsgdominic 12 Oct 2019, 23:38

Hi


We had the CHT set to 9000*3.
A huge improvement, but not error-free.

We've set this morning to 13000 * 1.
We'll monitor, watch, ask chat users to inform us.
I keep you updated.
User avatar
zoxtrix
Customer
 
Posts: 74
Joined: 29 Jun 2019, 19:31

 

by zoxtrix 15 Oct 2019, 16:42

Hi

We had the CHT set to 9000*3.
A huge improvement, but not error-free.

We've set this morning to 13000 * 1.
We'll monitor, watch, ask chat users to inform us.
I keep you updated.
Hi lsgdominic,

Did you try setting the message heartbeat to 0.5 in the admin cp? Doing so seems to make a huge improvement. In my case it has entirely eliminated the delivery failures for messages sent to mobile devices. Plus I believe that 13000 * 1 is the same as 6500 * 2, which also means that it's much less than 9000 * 3. The value 9000 * 3 should be the same as 27000 *1. So you might be worse off now than when you had it set to 9000 * 3. My recommendation would be to set it back to 9000 * 3 and set your message heartbeat in the admin cp to 0.5 then run a long series of test sends to a mobile device and see if you still notice delivery failures. As mentioned, I haven't encountered a single delivery failure since I made the described adjustments.

Also, make sure that you've replaced the contents of the arrowchat_mobile.js file in its entirety with the code I've supplied above. Just rename the current file for backup purposes then create a new arrowchat_mobile.js file and paste the code into it.

I'll be interested to know how the steps above work for you.
User avatar
Jason
Customer
 
Posts: 2329
Joined: 12 Dec 2009, 16:06

 

by Jason 23 Apr 2020, 16:15

I've done a lot of testing on this issue.

It appears this is most likely caused by having multiple instances of ArrowChat open. ArrowChat will sync across the same browser, but it cannot sync across all devices and browsers everywhere it is open. Full syncing is only available when using the push service due to the nature of polling.
User avatar
zoxtrix
Customer
 
Posts: 74
Joined: 29 Jun 2019, 19:31

 

by zoxtrix 26 Apr 2020, 11:14

I've done a lot of testing on this issue.

It appears this is most likely caused by having multiple instances of ArrowChat open. ArrowChat will sync across the same browser, but it cannot sync across all devices and browsers everywhere it is open. Full syncing is only available when using the push service due to the nature of polling.
I appreciate your testing effort, Jason. But I don't think that's the causal factor - unless of course merely two instances of ArrowChat running is too many. I had conducted my own fairly extensive testing sessions and the intermittency issue proved to be consistently repeatable with only two browsers at a time running ArrowChat on my test network. My code modifications combined with the heartbeat value change (which I've described) effectively fixed the issue for me and kept it away. Because I've not yet switched to v3.0, I'm yet unsure whether the issue will persist once it has been installed. Once I install and test it - not sure when that will be - I'll report back here.

Thanks
User avatar
Jason
Customer
 
Posts: 2329
Joined: 12 Dec 2009, 16:06

 

by Jason 26 Apr 2020, 12:00

I should add that I only tested on v3.0.