Sponsored Content
The Lounge What is on Your Mind? PubNub Live Chat Beta Testing Post 303034833 by Neo on Tuesday 7th of May 2019 10:14:51 PM
Old 05-07-2019
Hi Craig,

Thanks for your reply here at unix.com.

Regarding debounce(), this is from the npm debounce package (currently showing over 500K weekly downloads - a shout out to that achievement) here:

Code:
https://www.npmjs.com/package/debounce

where:

Code:
debounce(fn, wait, [ immediate || false ])

Quote:
Creates and returns a new debounced version of the passed function that will postpone its execution until after wait milliseconds have elapsed since the last time it was invoked.

Pass true for the immediate parameter to cause debounce to trigger the function on the leading edge instead of the trailing edge of the wait interval. Useful in circumstances like preventing accidental double-clicks on a "submit" button from firing a second time.

The debounced function returned has a property 'clear' that is a function that will clear any scheduled future executions of your function.

The debounced function returned has a property 'flush' that is a function that will immediately execute the function if and only if execution is scheduled, and reset the execution timer for subsequent invocations of the debounced function.
But in the case of our beta Vue.js live chat component we are working with; in the Vue.js updated() lifecycle hook:

Code:
 updated() {
    debounce(this.getHereNow, 300, false);
  },

When false, the
Code:
this.getHereNow()

function is not executed (according to Chrome DevTools and console.log()) because the updated() lifecycle hook is faster than 300 ms and false sets the function to fire at the trailing edge of the 300ms.

Hence, this line of code, as written does not fire (I assume you noticed that and hence that is why you were asking) because at 300 ms, the function instance does not exist anymore due to the speed of the Vue lifecycle (it's like a gaming loop, if you are familiar with game programming, which I assume you are)..

I was mainly experimenting with it (debouncing in the updated lifecycle hook) and how changes and updates in the Vue lifecycle might be used to effect pubnub HereNow updates. I will remove this line of code soon because, I guess.

Regarding your remark, "Would like to see the app running to investigate further," this is running live here:

Code:
https://community.unix.com/

The current version is 0.7602 (bottom right in the page) and if you see an earlier version, best to clear your JS files from the cache and insure you have the latest version; but I am sure you know that being a JS person!

This app needs more tweaking, as I still not running the API as efficiently as it should be, and the presence (hereNow) is not working (in the Vue.js app) as well as I would like. Basically, I want the list of folks viewing live chat to remain current without a page reload and without excess API polling; so I have tried to update this during changes in the app, for example (1) when a message is received, the occupancy and names will update; and I was experimenting with the Vue.js lifecycle to update occupancy and the uuid list when someone interacts with app, but that is not working as well as I would like (the update() - debounce() ) idea.

Ideally, it seems to be that PubNub should add a configuration parameter to the subscribe() API as follows;

Code:
pubnub.subscribe({
      channels: ["ch1", "control"],
      withPresence: true,
     presenceInterval:   10000 // milliseconds
    });

I notice PubNub often (mostly) uses seconds in API configuration parameters in the SDK. I think it would be better and more consistent to change it to milliseconds (in all PubNub API configuration params) like Javascript interval timers, but then again, I am not a great Javascript developer, or even a good one, so I need to be careful what I am recommending.

I am just a "wannabe" great Javascript developer and "wannabe" expert on PubNub Javascript SDK so I can use PubNub in more sophisticated cybersecurity applications. This live chat app is just getting my feet wet and is not the end goal. It is just a humble beginning.
 

4 More Discussions You Might Find Interesting

1. Solaris

Live Chat For Solaris?

Does anyone know of any online live chat discussion groups for Solaris? If so, please let me know... Thanks! Rob Sandifer (3 Replies)
Discussion started by: RobSand
3 Replies

2. What is on Your Mind?

A Quick Video Overview of PubNub Live Chat @UNIX.com (version 0.7614)

A number of people have asked me to make some videos, so I just got my first condenser microphone and so I can make some amateurish screen casts. I will try to do better in the future. A quick overview of PubNub Live Chat @unix.com The video is best is you set the Quality to HD 1080. The... (0 Replies)
Discussion started by: Neo
0 Replies

3. What is on Your Mind?

Live Chat (Alpha) in UserCP SF 0.7517

Interesting.... I am still working on the kinks for Live Chat here at unix.com using a publish-subscribe API from PubNub. Two days ago while working on it, a new user joined the live chat and asked about how to post a new thread in the forum. Then today, one of the members of the PubNub team... (23 Replies)
Discussion started by: Neo
23 Replies

4. What is on Your Mind?

Update: UserCP Screeching Frog 0.7641 - Changed Live Chat to Live Updates

Update: UserCP Screeching Frog 0.7641 - Changed Live Chat to Live Updates In this version of the UserCP, I have changed "Live Chat" to "Live Updates" by disabling the ability to post in the "live chat" area and changed the name to "Live Updates" The reason for this change is that experienced... (6 Replies)
Discussion started by: Neo
6 Replies
All times are GMT -4. The time now is 04:49 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy