API Reference
Detailed API reference for the Zapdos JavaScript SDK
Installation
To install the Zapdos JavaScript SDK, run:
npm install zapdos-js
Client
The main interface for interacting with the Zapdos service.
Constructor
new ZapdosClient({
baseUrl?: string // defaults to 'api.zapdoslabs.com'
})
Creates a new ZapdosClient instance.
Parameters:
baseUrl
(string, optional): The base URL for the Zapdos API (defaults to 'api.zapdoslabs.com')
index
async *index(
videoPath: string,
options?: {
interval?: number, // Interval in seconds between extracted frames (default: 5)
compact?: boolean // Whether to return compact results (default: false)
}
): AsyncGenerator<IndexEvent, void, unknown>
Indexes a video file by extracting keyframes and analyzing their content. Returns an async generator that yields events during the indexing process.
Parameters:
videoPath
(string): Path to the video file to indexoptions
(object, optional): Configuration optionsinterval
(number, optional): Interval in seconds between extracted frames (default: 5)compact
(boolean, optional): Whether to return compact results (default: false)
Returns:
AsyncGenerator<IndexEvent, void, unknown>
: An async generator that yields indexing events
Throws:
Error
: If there are issues with the indexing process
forward
async forward(url: string): Promise<void>
Forwards a video stream to the Zapdos service for processing.
Parameters:
url
(string): URL of the video stream to forward
Returns:
Promise<void>
: A promise that resolves when the stream forwarding is complete
Indexing Events
Constants for the different event types that can be received during indexing:
IndexingEvent.START_EXTRACTING_AUDIO
IndexingEvent.END_EXTRACTING_AUDIO
IndexingEvent.START_EXTRACTING_FRAMES
IndexingEvent.END_EXTRACTING_FRAMES
IndexingEvent.START_STT
IndexingEvent.END_STT
IndexingEvent.START_OBJECT_DETECTION
IndexingEvent.END_OBJECT_DETECTION
IndexingEvent.START_IMAGE_DESCRIPTION
IndexingEvent.END_IMAGE_DESCRIPTION
IndexingEvent.START_SUMMARIZATION
IndexingEvent.END_SUMMARIZATION
IndexingEvent.ERROR
IndexingEvent.DONE
Usage Example
import ZapdosClient from 'zapdos-js';
const client = new ZapdosClient();
// Index a video file
for await (const event of client.index('/path/to/video.mp4', { interval: 10 })) {
switch (event.type) {
case 'extracting_frames__start':
console.log('Starting frame extraction...');
break;
case 'stt__end':
console.log('Speech-to-text completed');
break;
case 'done':
console.log('Indexing completed:', event.value);
break;
case 'error':
console.error('Indexing error:', event.message);
break;
}
}