Teyuto SDK - User Module
Overview
The Teyuto.user
module is a crucial component of the Teyuto SDK, providing access to user-related data and functionalities. This module allows developers to interact with user information, preferences, and activities within the Teyuto platform.
Key Features
- Access to user profile information
- User authentication status
- User preferences and settings
- Saved content and playlists
- Interaction history (likes, views)
Properties
The Teyuto.user
object contains various properties that provide information about the current user:
id_user
: User's unique identifierdisplay_name
: User's display nameemail
: User's email addressemail_verified
: Boolean indicating if the email is verifiedprofile_image
: URL of the user's profile imagelanguage
: Object containing language-specific stringsautoplay
: Boolean indicating autoplay preferencecompanies
: Array of companies the user is associated withcurrencies
: Array of currencies available to the usersaved
: Object containing saved videos and collectionsliked
: Array of liked video IDslast_seen
: Array of last seen video informationcountry
: User's country codeplaylists
: Object containing user's playlists
Methods
onReady(callback)
Executes the provided callback function when the user data is ready.
Teyuto.user.onReady(function(user) {
console.log("User data loaded:", user);
});
isLoggedIn()
Checks if the user is currently logged in.
Teyuto.user.onReady(function(user) {
if (user.isLoggedIn()) {
console.log("User is logged in");
} else {
console.log("User is not logged in");
}
});
Usage Examples
1. Displaying User Information
Teyuto.user.onReady(function(user) {
if (user.isLoggedIn()) {
document.getElementById('userInfo').innerHTML = `
<img src="${user.profile_image}" alt="Profile Picture">
<h2>Welcome, ${user.display_name}!</h2>
<p>Email: ${user.email}</p>
`;
} else {
document.getElementById('userInfo').innerHTML = `
<p>Please log in to view your profile.</p>
`;
}
});
2. Handling User Preferences
Teyuto.user.onReady(function(user) {
if (user.autoplay) {
console.log("Autoplay is enabled");
// Implement autoplay functionality
}
// Set user's preferred language
document.documentElement.lang = Teyuto.user.language.info.code;
});
3. Displaying User's Saved Content
Teyuto.user.onReady(function(user) {
const savedVideosList = document.getElementById('savedVideos');
user.saved.videos.forEach(videoId => {
const listItem = document.createElement('li');
listItem.textContent = `Video ID: ${videoId}`;
savedVideosList.appendChild(listItem);
});
});
4. Working with User's Playlists
Teyuto.user.onReady(function(user) {
const playlistContainer = document.getElementById('playlists');
Object.entries(user.playlists).forEach(([playlistId, playlist]) => {
const playlistElement = document.createElement('div');
playlistElement.innerHTML = `
<h3>${playlist.title}</h3>
<p>Videos: ${playlist.videos.length}</p>
<p>Public: ${playlist.public ? 'Yes' : 'No'}</p>
`;
playlistContainer.appendChild(playlistElement);
});
});
5. Handling User's Last Seen Videos
Teyuto.user.onReady(function(user) {
const lastSeenContainer = document.getElementById('lastSeen');
user.last_seen.forEach(video => {
const videoElement = document.createElement('div');
videoElement.innerHTML = `
<p>Video ID: ${video.video_id}</p>
<p>Last Watched: ${video.last_second} seconds</p>
<p>Progress: ${(video.last_second / video.duration * 100).toFixed(2)}%</p>
`;
lastSeenContainer.appendChild(videoElement);
});
});
Best Practices
- Always use the
onReady
method to ensure user data is available before accessing it. - Check login status with
isLoggedIn()
before accessing user-specific data. - Handle cases where optional user data might be missing.
- Respect user privacy and only use necessary information.
- Consider user preferences (like autoplay and language) when customizing the user experience.
Conclusion
The Teyuto.user
module provides a powerful interface for accessing and utilizing user data within the Teyuto platform. By leveraging this module, developers can create personalized, user-centric experiences that enhance engagement and functionality of Teyuto-powered applications.