Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The likeCount limited to 15 likes. #76

Closed
richjr93 opened this issue Oct 20, 2022 · 15 comments
Closed

The likeCount limited to 15 likes. #76

richjr93 opened this issue Oct 20, 2022 · 15 comments

Comments

@richjr93
Copy link

Hi, I have an issue with the like likeCount. it only logs up to 15 likes. How can I make it so that it doesn't stop at 15? It shouldn't be displaying the likeCount before the user stops tapping the screen. It should only show the final likeCount amount after the user stops tapping. Hope you can help me out with this. Thank you in advance!

@bslkh
Copy link

bslkh commented Oct 20, 2022

TikTok sends maximum 15 likes to the pool

You can store each pool per user and calculate the total when you need it.

@richjr93
Copy link
Author

Hi, thanks for the reply. Would you mind to show me the exact way to do that? I'm afraid I have not much knowledge on coding😅

@bslkh
Copy link

bslkh commented Oct 21, 2022

Do you always need to show likes right after the user finishes their streak, or do you have an event after which you need to show the number of likes?

@richjr93
Copy link
Author

Yes, I do want it to show the total likes from each respective user right after they finish their streak/screen tapping. Just to be clear, let's say they tapped 100 times non-stop and then they end their streak, it will show that they've sent 100 likes. If they tapped for 5000 times non-stop and then stopped, it will show that they've sent 5000 likes.

@bslkh
Copy link

bslkh commented Oct 21, 2022

I think until TikTok adds marks the start and end of the streak, it is difficult to determine with high accuracy, but you can choose your interval

I'm afraid I don't have much knowledge about coding either

example piece of code for server

var list_users_likes = new Object();
tiktokLiveConnection.on('like', data => {
	if (list_users_likes.hasOwnProperty(data.uniqueId)) {
		list_users_likes[data.uniqueId].addTime();
		list_users_likes[data.uniqueId].up(data.likeCount);
	} else {
		list_users_likes[data.uniqueId] = {
			total: 0,
			uniqueId: data.uniqueId,
			dropLikes(total) {
				console.log(this.uniqueId, total); //do something you need
				this.timeoutID = undefined;
				delete list_users_likes[this.uniqueId];
			},
			addTime() {
				clearTimeout(this.timeoutID);
			},
			up(like) {
				this.total += like;
				this.timeoutID = setTimeout((total) => {
					this.dropLikes(total);
				}, 4000, this.total) //4 seconds interval
			}
		};
		list_users_likes[data.uniqueId].up(data.likeCount);
	}
})

@richjr93
Copy link
Author

richjr93 commented Oct 21, 2022

Thanks for the code example. Do I just copy and paste or I still have to modify anything? If I were to replace a code from my file, do I replace the following code?:

tiktokLiveConnection.on('like', data => {
    console.log(`${data.uniqueId} sent ${data.likeCount} likes, total likes: ${data.totalLikeCount}`);
})

@bslkh
Copy link

bslkh commented Oct 21, 2022

Other than the lines where there is a comment (11, 22), it is better not to change anything

Yes, this part of your code should be replaced to avoid duplicate

@richjr93
Copy link
Author

Okay, I actually have a few differences in my code which make me kind of confused about what exactly my code should look like, I thought I could add your code just like that with a little bit of modification, but it didn't work out. Maybe you could modify the code based on what I currently have if you don't mind 😅.

Alright so I have a function addMessageLike, created to display the output:

function addMessageLike(data) {
        // Check setting
        if (confLike) {
            // Add
            addContent(`${data.uniqueId} sent ${data.likeCount} likes, total likes: ${data.totalLikeCount}`);

            // Sound
            playSound(1);
        }
        
    }

In the above function, I have a condition called confLike to proceed if only it's true.
I also have the addContent, which is just another function for where and how to display the content and the content is inside the bracket.
The following image is the current result(which is the issue I currently have where it only records up to 15 likes at a time, and then displays another 15, and so on.):
image

Here is my actual code for the connection:

connection.on('like', (data) => {
    if (typeof data.likeCount === 'number') {
            // Check setting
        if (confLike) {
        addMessageLike(data);
        }
    }
})

I also put the whole code here in case you want to have a look.
Hope those could help you more. Thanks!

@bslkh
Copy link

bslkh commented Oct 21, 2022

Show me how you set up data transfer from the code of server

@richjr93
Copy link
Author

richjr93 commented Oct 21, 2022

I'm not sure which file do I show for the data transfer set up 😅.
I actually downloaded the project from here, if you mean the server.js file, it will be there as well. I think it will be easier for you to understand the code if you can see it all. The code I've shown in my previous reply is from the app.js file that you can find inside /public/assets/js. But of course, I modified the app.js just a little bit. Originally it doesn't display the number of likes at all.

@bslkh
Copy link

bslkh commented Oct 21, 2022

Yes, I need to see how you change server.js and implemented the code I wrote earlier

@richjr93
Copy link
Author

Oh. I didn't change anything in the server.js but what I did in app.js from the code you suggested earlier is:

  1. From this code:
connection.on('like', (data) => {
    if (typeof data.likeCount === 'number') {
            // Check setting
        if (confLike) {
        addMessageLike(data);
        }
    }
})

I changed to this:

var list_users_likes = new Object();
connection.on('like', data => {
if (confLike) {
	if (list_users_likes.hasOwnProperty(data.uniqueId)) {
		list_users_likes[data.uniqueId].addTime();
		list_users_likes[data.uniqueId].up(data.likeCount);
	} else {
		list_users_likes[data.uniqueId] = {
			total: 0,
			uniqueId: data.uniqueId,
			dropLikes(total) {
				addMessage(this.uniqueId, total); //do something you need
				this.timeoutID = undefined;
				delete list_users_likes[this.uniqueId];
			},
			addTime() {
				clearTimeout(this.timeoutID);
			},
			up(like) {
				this.total += like;
				this.timeoutID = setTimeout((total) => {
					this.dropLikes(total);
				}, 4000, this.total) //4 seconds interval
			}
		};
		list_users_likes[data.uniqueId].up(data.likeCount);
	}
}})

Honestly, I don't even have any idea of what I modified, that's why I was confused 😅.

@bslkh
Copy link

bslkh commented Oct 21, 2022

😅

As far as I understand, that library has not been updated for a long time and does not work

In the case of likes, you just need to make sure that:

  1. 'data' comes in the right format
  2. slightly change code
    (for example)
var list_users_likes = new Object();
connection.on('like', data => {
if (confLike) {
	if (list_users_likes.hasOwnProperty(data.uniqueId)) {
		list_users_likes[data.uniqueId].addTime();
		list_users_likes[data.uniqueId].up(data);
	} else {
		list_users_likes[data.uniqueId] = {
			total: 0,
			uniqueId: data.uniqueId,
			dropLikes(data) {
				addMessage(data); //do something you need
				this.timeoutID = undefined;
				delete list_users_likes[this.uniqueId];
			},
			addTime() {
				clearTimeout(this.timeoutID);
			},
			up(data) {
				this.total += data.likeCount;
				data.likeCount = this.total;
				this.timeoutID = setTimeout((data) => {
					this.dropLikes(data);
				}, 4000, data) //4 seconds interval
			}
		};
		list_users_likes[data.uniqueId].up(data);
	}
}})
  1. addMessage or addMessageLike?

@richjr93
Copy link
Author

OMG it worked! Thank you very much!!! the addMessageLike is actually a custom function I made to display the data for likes when only the confLike is true. Otherwise, it needs both confLike and confComment to work which I don't want because that way it will show the comments as well when I only want to see the likes. 😁

@bslkh
Copy link

bslkh commented Oct 21, 2022

I'm glad that I can some help you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants