Skip to content

Events ​

Event Registration Timing ​

Callbacks can be registered at any time, before or after init(). However, to receive status changes during init() (CONNECTING, SOCKET_CONNECTED, etc.), register onStatus before calling init().

  • Callbacks are preserved after destroy(), so you don't need to re-register them on re-initialization.

WARNING

Only one callback per type can be registered; the latest registration overwrites the previous one.

If multiple screens or components need these events, register the SDK callbacks in a single place in your app and distribute the received events to the components that need them.

onSignal(callback) ​

Receives signals from the server.

js
SDK.onSignal((data) => {
  console.log(data.signal, data.payload);
});
jsx
useEffect(() => {
  window.KlleonSDK.onSignal((data) => {
    console.log(data.signal, data.payload);
  });
}, []);

Callback Parameters ​

FieldTypeRequiredDescription
signalIncomingSignalYesSignal type (enum, string at runtime)
payloadobjectNoAdditional data per signal
idstringYesSignal UUID
typestringYes"SESSION" | "INPUT" | "OUTPUT"

Key Signals ​

Conversation Flow ​

SignalDescriptionpayload
RESPONSE_TEXTAvatar response text{ text: string, language: string }
STT_RESULTSpeech recognition result{ text: string }
RESPONSE_PREPARINGPreparing response (just before LLM request)-
RESPONSE_STARTEDResponse started-
RESPONSE_ENDEDResponse completed-
USER_SPEECH_STARTEDSpeech segment started within STT session (mic already on)-
USER_SPEECH_STOPPEDSpeech segment ended within STT session (mic still on)-
ERRORResponse processing error (session maintained){ type: "STT_ERROR" | "LLM_ERROR" | ... }
REJECTEDInput rejected (session maintained){ type: "STT_EMPTY" | "MODERATION" | ... }

Session Management ​

SignalDescriptionpayload
MATCH_WAITINGWaiting for match (for loading UI)-
WAITServer preparing (keep waiting)-
SESSION_ENDEDSession ended normally-
IDLE_TIMED_OUTServer ended the session due to idle timeout-
SESSION_TIMED_OUTSession timeout-
TIME_EXHAUSTEDUsage time exhausted-
QUOTA_EXCEEDEDConcurrent connection quota exceeded-
SUSPEND_WARNEDLong idle warning-

onStatus(callback) ​

Receives SDK connection status changes.

js
SDK.onStatus((status) => {
  console.log('Status:', status);
  if (status === 'CONNECTED_FINISH') {
    console.log('Avatar ready');
  }
});
jsx
const [status, setStatus] = useState('IDLE');

useEffect(() => {
  window.KlleonSDK.onStatus((s) => setStatus(s));
}, []);

onError(callback) ​

Receives SDK internal errors and server errors.

js
SDK.onError((error) => {
  console.error(error.code, error.message);
});
jsx
useEffect(() => {
  window.KlleonSDK.onError((error) => {
    console.error(error.code, error.message);
  });
}, []);

Callback Parameters ​

FieldTypeRequiredDescription
codestringYesError code
messagestringNoDetailed message

Error Code Details ​

Initialization Errors (on init failure) ​

Init failures are delivered as the rejection of init() without an error code. Messages: "Failed to connect: ..." (SDK key validation failure or WebSocket connection failure) / "Failed to connect streaming: ..." (streaming connection failure) / "Init failed: ..." (other initialization failures)

However, onError may still fire for streaming-side issues during connection, so register onError before calling init().

Runtime Errors (during active connection) ​

CodeTriggermessage example
SOCKET_DISCONNECTED_UNEXPECTEDLYWebSocket error occurred"WebSocket disconnected unexpectedly: {code}" or "Handover failed after max retries and active socket is dead"
STREAMING_FAILEDRemote track subscription failure — the connection is maintained, only onError is delivered"Failed to subscribe to remote track"
STREAMING_DISCONNECTED_UNEXPECTEDLYStreaming abnormal termination"Streaming disconnected: {reason}" or "Remote user left streaming"

Server Errors ​

CodeTriggermessage example
SERVER_ERRORSERVER_ERROR signal received from serverServer message or "SERVER_ERROR"
WORKER_DISCONNECTEDServer connection termination signal received"WORKER_DISCONNECTED"

Event Registration Example ​

js
const SDK = window.KlleonSDK;

SDK.onStatus((status) => console.log('Status:', status));

SDK.onSignal((data) => {
  if (data.signal === 'RESPONSE_TEXT') {
    console.log('Avatar:', data.payload.text);
  }
});

SDK.onError((error) => {
  console.error(`[${error.code}] ${error.message}`);
});

SDK.init({
  sdk_key: 'YOUR_SDK_KEY',
  avatar_id: 'YOUR_AVATAR_ID',
}).catch((e) => console.error(e.message));
jsx
import { useEffect } from 'react';

function App() {
  useEffect(() => {
    const SDK = window.KlleonSDK;

    SDK.onStatus((status) => console.log('Status:', status));

    SDK.onSignal((data) => {
      if (data.signal === 'RESPONSE_TEXT') {
        console.log('Avatar:', data.payload.text);
      }
    });

    SDK.onError((error) => {
      console.error(`[${error.code}] ${error.message}`);
    });

    SDK.init({
      sdk_key: 'YOUR_SDK_KEY',
      avatar_id: 'YOUR_AVATAR_ID',
    })
      .catch((e) => console.error(e.message));

    return () => {
      // destroy() is safe even if init hasn't completed — it is serialized behind any in-flight init
      SDK.destroy();
    };
  }, []);

  return <avatar-container style={{ width: 400, height: 600 }} />;
}