Viewer SDK
Welcome to the documentation for floorfySDK—a powerful JavaScript library designed to facilitate communication with an iframe-based SDK. floorfySDK provides a seamless way to interact with iframe content by enabling message-based communication, managing pose data, and configuring user interactivity.
Key Features
Section titled “Key Features”- Initialization: Easily set up the SDK with a specific iframe by providing its ID.
- Pose Management: Retrieve, set, and subscribe to pose updates, making it simple to interact with pose-related data.
- User Interactivity: Configure interactivity settings to control how users interact with the iframe content.
- Event Handling: Automatically handle incoming messages from the iframe, ensuring your application reacts to relevant changes and actions.
Purpose
Section titled “Purpose”floorfySDK is designed to bridge the gap between your main application and an iframe-based content provider. Whether you’re building a sophisticated visualization tool, a custom interactive experience, or integrating external content, floorfySDK helps manage communication and interaction efficiently.
Getting Started
Section titled “Getting Started”To get started with floorfySDK, you need to initialize the SDK with the iframe ID and configure it to handle pose data and interactivity according to your needs. Refer to the detailed method descriptions and example usage in this documentation to integrate floorfySDK into your project effectively.
Properties
Section titled “Properties”iframeId: Stores the ID of the iframe element that the SDK interacts with.eventMethod: The method used to add event listeners (addEventListenerorattachEvent).eventer: Reference to the method used to add event listeners.messageEvent: The event type used for message events (messageoronmessage).posesubsriber: A function to be called when a pose-related message is received.poseresolver: A function to be called when a pose is requested.
Methods
Section titled “Methods”init(iframeId)
Section titled “init(iframeId)”Initializes the SDK with the provided iframe ID.
Parameters:
iframeId(String): The ID of the iframe element.
Usage:
floorfySDK.init('myIframe');pose.get()
Section titled “pose.get()”Requests the current pose from the iframe.
Returns:
- A
Promisethat resolves with the pose data.
Usage:
floorfySDK.pose.get().then(function(pose) { console.log(pose);});pose.subscribe(subscriberFunction)
Section titled “pose.subscribe(subscriberFunction)”Subscribes to pose updates. The provided function will be called whenever a pose-related message is received.
Parameters:
subscriberFunction (Function): A callback function to handle pose updates.
Usage:
floorfySDK.pose.subscribe(function(poseMessage) { console.log(poseMessage);});pose.set(pose)
Section titled “pose.set(pose)”Sends a new pose to the iframe.
Parameters:
pose (Object): The pose data to set.
Usage:
floorfySDK.pose.set({ x: 10, y: 20, z: 30 });user.setInteractivity(interactivity)
Section titled “user.setInteractivity(interactivity)”Sets the interactivity mode for the iframe.
Parameters:
interactivity (Object): The interactivity settings.
Usage:
floorfySDK.user.setInteractivity({ enabled: true });getIframe()
Section titled “getIframe()”Returns the contentWindow of the iframe with the ID stored in iframeId.
Returns:
Window (Object): The content window of the iframe.
Usage:
var iframeWindow = floorfySDK.getIframe();Event Handling
Section titled “Event Handling”The SDK listens for message events from the iframe. It parses incoming messages and triggers appropriate functions based on the message action:
changeSceneandcameraOrientationactions triggerposesubsriberif defined.getPoseandsynchCurrentPositionactions triggerposeresolverif defined.
Example
Section titled “Example”Here’s a full example of how to use floorfySDK:
// Initialize SDK with iframe IDfloorfySDK.init('myIframe');
// Subscribe to pose updatesfloorfySDK.pose.subscribe(function(poseMessage) { console.log('Pose updated:', poseMessage);});
// Get the current posefloorfySDK.pose.get().then(function(pose) { console.log('Current pose:', pose);});
// Set a new posefloorfySDK.pose.set({ x: 10, y: 20, z: 30 });
// Set interactivityfloorfySDK.user.setInteractivity({ enabled: true });