Skip to main content

Available Functions

The HCS-3 Recursion SDK provides a variety of functions for handling different types of content. Here's a comprehensive guide to the available functions:

Configuration

HTML Configuration

You can configure the SDK using HTML data attributes:

Loading Resources

Scripts

<script data-src="hcs://1/0.0.12345" data-script-id="unique-id"></script>

Stylesheets

<link data-src="hcs://1/0.0.12345" data-script-id="unique-id" rel="stylesheet">

Images

<img data-src="hcs://1/0.0.12345" alt="Description">

Video

<video data-src="hcs://1/0.0.12345" controls></video>

Audio

<audio data-src="hcs://1/0.0.12345" controls></audio>

3D Models (GLB)

<model-viewer data-src="hcs://1/0.0.12345" camera-controls auto-rotate ar></model-viewer>

Audio Functions

Preload Audio

await HCS.preloadAudio('0.0.12345');

Play Audio

await HCS.playAudio('0.0.12345', 0.5);

Pause Audio

await HCS.pauseAudio('0.0.12345');

Load and Play Audio

await HCS.loadAndPlayAudio('0.0.12345', true, 0.8);

Image Functions

Preload Image

const imageUrl = await HCS.preloadImage('0.0.12345');

Loading Order

You can control the loading order of resources using the data-load-order attribute:

<script data-src="hcs://1/0.0.12345" data-load-order="1"></script>
<script data-src="hcs://1/0.0.12346" data-load-order="2"></script>

Event Handling

Ready Event

window.HCSReady = function() {
console.log('All HCS resources have been loaded');
};

Loading Status Callback

window.onHCSLoading = function(id, status) {
console.log(`Resource ${id} status: ${status}`);
};

Additional Examples

For more examples and use cases, visit our GitHub repository.

Error Handling

The SDK includes built-in retry logic for failed requests:

  • Default retry attempts: 3
  • Default backoff: 300ms (doubles after each retry)
  • Required resources will throw errors if they fail to load
  • Optional resources will log errors but continue loading other resources

You can customize these settings using the configuration options shown above.