Real-time messaging, binary data handling, and communication patterns in the HAIP SDK
New protocol version released: This page may contain outdated information.
Master real-time communication with the HAIP SDK’s powerful messaging system. From simple text messages to complex binary data streams, learn how to implement efficient, reliable messaging patterns for your applications.
// Send binary data directlyconst audioData = new ArrayBuffer(1024);await client.sendBinary(audioData);// Send audio chunk with metadataawait client.sendAudioChunk( "AUDIO_IN", // channel "audio-123", // message ID "audio/wav", // MIME type audioData, // binary data 1000, // duration in milliseconds runId // run ID);
// User sends a messageawait client.sendTextMessage("USER", "What is the weather?", "user", runId);// Agent respondsawait client.sendTextMessage( "AGENT", "The weather is sunny today.", "assistant", runId);// System notificationawait client.sendTextMessage( "SYSTEM", "Connection established", "system", runId);
// Convert binary data to base64const binaryData = new ArrayBuffer(1024);const base64Data = HAIPUtils.encodeBase64(binaryData);// Convert base64 back to binaryconst decodedData = HAIPUtils.parseBase64(base64Data);