Skip to main content

Overview

The web SDK emits events when the ambient session state changes. You can listen for these events to track the state of the ambient session and handle responses accordingly. For more information, refer to the emitter-events-type section.

Code Example

The example below demonstrates how to listen for ambient events in the web SDK.
React
import { SukiAssistant, SukiProvider, useSuki } from "@suki-sdk/react";

function MyComponent() {
  const { on, activeAmbientId } = useSuki();

  useEffect(() => {
    const handleAmbientUpdate = (event) => {
      console.log("Ambient event received:", event);
    };

    // Subscribe to ambient update events
    const unsubscribe = on("ambient-update", handleAmbientUpdate);

    // Cleanup subscription on unmount
    return () => {
      unsubscribe();
    };
  }, [on]);

  return (
    <>
      Active Ambient ID: {activeAmbientId}
      <SukiAssistant
      // props
      />
    </>
  );
}

Next Steps

Refer to the Test Mode example to learn how to use the test mode in the web SDK.