### Start the React app to test setup Source: https://www.pubnub.com/docs/sdks/redux/react-tutorial Runs the npm start command to open a web browser and verify the app is working. If the expected screen appears, the setup is successful. ```bash npm start ``` -------------------------------- ### Get All UUID Metadata Sample Code Source: https://www.pubnub.com/docs/sdks/kotlin/api-reference/objects Self-contained reference example for the getAllUUIDMetadata method. It includes imports, configuration, setup of sample users, and a basic call to getAllUUIDMetadata. The example is truncated in the source; the remaining code is not shown. ```kotlin import com.pubnub.api.PubNub import com.pubnub.api.UserId import com.pubnub.api.v2.PNConfiguration /** * This example demonstrates how to use the getAllUUIDMetadata method in the PubNub Kotlin SDK. * * The App Context (Objects) API allows you to store metadata about users (UUIDs) in PubNub's * database without setting up your own backend. */ fun main() { println("PubNub UUID Metadata Example") println("============================") // 1. Configure PubNub val userId = UserId("uuid-metadata-demo-user") val config = PNConfiguration.builder(userId, "demo").apply { publishKey = "demo" }.build() // 2. Create PubNub instance val pubnub = PubNub.create(config) // 3. First, set up some sample user metadata setupSampleUsers(pubnub) // 4. Demonstrate getting all UUID metadata getAllUUIDMetadataBasic(pubnub) // 5. Demonstrate getting all UUID metadata with filtering getAllUUIDMetadataWithFilter(pubnub) // 6. Get metadata for a specific UUID getSpecificUUIDMetadata(pubnub) // 7. Clean up sample user metadata cleanupUserMetadata(pubnub) // Clean up pubnub.destroy() } /** * Set up sample user metadata for the demo */ private fun setupSampleUsers(pubnub: PubNub) { println("\n# Setting up sample user metadata") // Create a few users with metadata val users = listOf( Triple("user-1", "Alice", "Developer"), Triple("user-2", "Bob", "Manager"), Triple("user-3", "Charlie", "Support") ) users.forEach { (userId, name, role) -> println("\nSetting up metadata for $name ($userId)") pubnub.setUUIDMetadata( uuid = userId, name = name, includeCustom = true, custom = mapOf("role" to role, "active" to true), email = "$name@example.com".lowercase() ).async { result -> result.onSuccess { response -> println("SUCCESS: Created/updated user metadata for ${response.data?.id}") println("Name: ${response.data?.name}") println("Email: ${response.data?.email}") println("Custom: ${response.data?.custom}") }.onFailure { exception -> println("ERROR: Failed to set user metadata") println("Error details: ${exception.message}") } } } // Wait for a moment to ensure all operations are complete println("\nWaiting for metadata operations to complete...") Thread.sleep(2000) } /** * Demonstrates a basic call to getAllUUIDMetadata */ private fun getAllUUIDMetadataBasic(pubnub: PubNub) { println("\n# Getting All UUID Metadata (Basic)") pubnub.getAllUUIDMetadata( includeCustom = true, // Include custom fields includeCount = true // Include total count in response ).async { result -> result.onSuccess { response -> println("SUCCESS: Retrieved UUID metadata objects") ``` -------------------------------- ### Set up the project Source: https://www.pubnub.com/docs/use-cases/sports-media-entertainment/automated-polling Creates a new directory, initializes npm, and installs the PubNub SDK. ```bash mkdir automated-polling-tutorial cd automated-polling-tutorial npm init -y npm install pubnub ``` -------------------------------- ### Get typing events with StreamTyping and OnUsersTyping Source: https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/channels/typing-indicator Complete Unity Chat example that gets typing events on the 'support' channel. Joins the channel, enables streaming with StreamTyping(true), subscribes to OnUsersTyping, and starts typing to trigger the event. ```csharp using System; using System.Collections.Generic; using System.Threading.Tasks; using PubnubApi; using PubnubChatApi; using UnityEngine; // Configuration PubnubChatConfig chatConfig = new PubnubChatConfig(); PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId")) { SubscribeKey = "demo", PublishKey = "demo", Secure = true }; // Initialize Unity Chat var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration); if (!chatResult.Error) { chat = chatResult.Result; } // reference the channel where you want to listen to typing signals var channelResult = await chat.GetChannel("support"); if (!channelResult.Error) { var channel = channelResult.Result; Debug.Log($"Found channel with name {channel.Name}"); // join the channel, start listening for typing await channel.JoinChannel(); channel.Connect(); channel.StreamTyping(true); // subscribe to the OnUsersTyping event channel.OnUsersTyping += OnUsersTypingHandler; await Task.Delay(4000); // indicate that typing has started await channel.StartTyping(); } else { Debug.Log("Channel not found"); } // event handler for typing events void OnUsersTypingHandler(List users) { if (users.Count > 0) { Debug.Log($"Users typing: {string.Join(", ", users)}"); } else { Debug.Log("No users are currently typing"); } } ``` -------------------------------- ### Objective-C: PubNub Quickstart with Listener Source: https://www.pubnub.com/docs/getting-started/quickstart Sets up a PubNub client, subscribes to a channel, publishes a message, and prints received messages. Requires your publish and subscribe keys. The example uses a listener to handle messages and connection status, and publishes when connected. ```objectivec #import #import @interface QuickstartListener : NSObject @property(nonatomic, strong) PubNub *client; @end @implementation QuickstartListener - (void)client:(PubNub *)client didReceiveMessage:(PNMessageResult *)message { NSLog(@"Message received: %@", message.data.message[@"text"]); } - (void)client:(PubNub *)client didReceiveStatus:(PNStatus *)status { if (status.category == PNConnectedCategory) { [self publishMessage]; } } - (void)publishMessage { [self.client publish:@{@"text": @"Hello, PubNub!"} toChannel:@"quickstart-channel" withCompletion:^(PNPublishStatus *status) { if (status.isError) { NSLog(@"Publish failed: %@", status.errorData.information); } }]; } @end int main(int argc, const char *argv[]) { @autoreleasepool { PNConfiguration *configuration = [PNConfiguration configurationWithPublishKey:@"YOUR_PUBLISH_KEY" subscribeKey:@"YOUR_SUBSCRIBE_KEY" userID:@"quickstart-user"]; QuickstartListener *listener = [QuickstartListener new]; listener.client = [PubNub clientWithConfiguration:configuration]; [listener.client addListener:listener]; [listener.client subscribeToChannels:@[@"quickstart-channel"] withPresence:NO]; [[NSRunLoop currentRunLoop] run]; } return 0; } ``` -------------------------------- ### GetAllUUIDMetadata method chain example Source: https://www.pubnub.com/docs/sdks/go/api-reference/objects Shows the method chain for getting all UUID metadata with optional include, sort, limit, count, start, end, and filter parameters. ```go pn.GetAllUUIDMetadata(). Include([]pubnub.PNUUIDMetadataIncludeCustom). Sort(sort). Limit(int). Count(bool). Start(string). End(string). Filter(string). Execute() ``` -------------------------------- ### Go: Get UUID metadata with setup and retrieval Source: https://www.pubnub.com/docs/data-storage/metadata/manage-user-metadata Shows a complete Go example that sets user metadata, waits for persistence, then retrieves it. Includes configuration and error handling. ```go // Replace with your package name (usually "main") package pubnub_samples_test import ( "fmt" "time" pubnub "github.com/pubnub/go/v10" ) // Example_getUUIDMetadata demonstrates retrieving user metadata func Example_getUUIDMetadata() { config := pubnub.NewConfigWithUserId(pubnub.UserId("demo-user")) config.SubscribeKey = "demo" config.PublishKey = "demo" pn := pubnub.NewPubNub(config) // First, set user metadata pn.SetUUIDMetadata(). UUID("user-456"). Name("Jane Smith"). Email("jane@example.com"). Execute() // Small delay to ensure metadata is persisted before retrieval time.Sleep(2 * time.Second) // Then retrieve the user metadata response, status, err := pn.GetUUIDMetadata(). UUID("user-456"). // User ID to retrieve Execute() if err != nil { fmt.Printf("Error: %v\n", err) return } if status.StatusCode == 200 { fmt.Printf("User: %s\n", response.Data.Name) fmt.Printf("Email: %s\n", response.Data.Email) } // Output: // User: Jane Smith // Email: jane@example.com } ``` -------------------------------- ### Build a single example target Source: https://www.pubnub.com/docs/sdks/c/environment-setup Configure with the full preset and examples enabled, then build a specific example target. Target names follow the pattern example__