disguise developers

Discovery

Designer instances after r30.4 support DNS-SD discovery. This allows you to discover Designer instances on your network and connect to them, without prior knowledge of the hostname or port number. This includes access to both the Service and Session APIs.

Designer instances are discovered using the following DNS-SD service name:

d3api._http._tcp.local.

Note: The domain will always be suffixed with .local.. Each interface will be assigned a unique service name, so if you have multiple interfaces, you will see ‘d3api (N)._http._tcp.local.’ for each interface.

Python Example

In the below example, we use the zeroconf library to discover Designer instances on the local network. We then make an HTTP GET request to the /api/session/status/health health endpoint to check the health of the Designer instance. This allows us to check the health of the Designer instance and get the current FPS and system states, without prior knowledge of the Designer instance’s hostname or port.

from zeroconf import ServiceBrowser, Zeroconf # Use the zeroconf library to discover Designer instances
import requests # Use the requests library to make HTTP requests
import json # Use the json library to parse JSON

class Listener:
    def check_health(self, hostname, port):
        """Check the health of a d3 instance and print the results."""
        try:
            url = f"http://{hostname}:{port}/api/session/status/health" # Create the URL for the health check
            response = requests.get(url, timeout=5) # Make the HTTP GET request to the health check URL
            if response.status_code == 200: # Check if the response status code is 200 (OK)
                health = response.json() # Parse the response as JSON
                # Extract and display relevant health info
                for result in health['result']:
                    machine = result['machine']
                    status = result['status']
                    print(f"\nHealth Status for {machine['name']}:")
                    print(f"  FPS: {status['averageFPS']:.2f}")
                    print("\nSystem States:")
                    for state in status['states']:
                        print(f"  {state['name']}: {state['detail']} ({state['severity']})")
            else:
                print(f"Health check failed with status code: {response.status_code}") # Print the status code if the health check fails
        except Exception as e:
            print(f"Failed to get health status: {str(e)}") # Print the error message if the health check fails

    def add_service(self, zc, type_, name):
        if "d3api" in name.lower():  # Check if the service name contains "d3api"
            info = zc.get_service_info(type_, name) # Get the service info from the zeroconf instance
            if info:
                hostname = info.server.rstrip('.local.') # Get the hostname from the service info
                print(f"Found d3 instance - {name} {hostname}:{info.port}") # Print the service name, hostname and port
                self.check_health(hostname, info.port) # Perform health check

    def update_service(self, zc, type_, name):
        if "d3api" in name.lower():
            info = zc.get_service_info(type_, name) # Get the service info from the zeroconf instance
            if info:
                hostname = info.server.rstrip('.local.') # Get the hostname from the service info
                print(f"\nUpdated d3 instance - {name} {hostname}:{info.port}") # Print the service name, hostname and port
                self.check_health(hostname, info.port) # Perform health check

zc = Zeroconf()
browser = ServiceBrowser(zc, "_http._tcp.local.", Listener())
input("Press Enter to exit...\n")
zc.close()