Skip to main content

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 identifier
  • display_name: User's display name
  • email: User's email address
  • email_verified: Boolean indicating if the email is verified
  • profile_image: URL of the user's profile image
  • language: Object containing language-specific strings
  • autoplay: Boolean indicating autoplay preference
  • companies: Array of companies the user is associated with
  • currencies: Array of currencies available to the user
  • saved: Object containing saved videos and collections
  • liked: Array of liked video IDs
  • last_seen: Array of last seen video information
  • country: User's country code
  • playlists: 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

  1. Always use the onReady method to ensure user data is available before accessing it.
  2. Check login status with isLoggedIn() before accessing user-specific data.
  3. Handle cases where optional user data might be missing.
  4. Respect user privacy and only use necessary information.
  5. 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.