### VideoUploadManager Initialization and Usage Example Source: https://github.com/byteark/video-upload-sdk-js/blob/main/README.md Demonstrates how to initialize the VideoUploadManager with SDK options and callbacks, and how to add and start upload jobs. ```APIDOC ## VideoUploadManager Initialization and Usage ### Description Initializes the SDK with configuration options and starts the upload process for provided files. ### Method `new VideoUploadManager(options: SDKOptions)` ### Parameters #### SDK Options - **serviceName** (string) - Required - The service to use, either 'byteark.stream' or 'byteark.qoder'. - **serviceEndpoint** (string) - Optional - Custom endpoint URL for the service. Defaults to 'https://stream.byteark.com' or 'https://qoder.byteark.com/apps//ajax'. - **formId** (string) - Required - The form ID for ByteArk Stream or appId for ByteArk Qoder. - **formSecret** (string) - Required - The form secret for ByteArk Stream or appSecret for ByteArk Qoder. - **projectKey** (string) - Required - The project key for ByteArk Stream or project ID for ByteArk Qoder. - **overlayPresetId** (string) - Optional - The ID of an overlay preset to apply to uploaded videos (for ByteArk Stream). #### Callback Functions - **onUploadProgress** (function) - Called when an upload job has a progress update. - **onUploadCompleted** (function) - Called when a video has finished uploading. - **onUploadFailed** (function) - Called when an upload job fails and cannot be retried. - **onVideosCreated** (function) - Called after all videos have been created on the service. ### Usage Example ```ts import { VideoUploadManager } from '@byteark/video-upload-sdk'; async function main() { const uploadManager = new VideoUploadManager({ serviceName: 'byteark.stream', serviceEndpoint: 'https://stream.byteark.com', formId: '', formSecret: '', projectKey: '', onUploadProgress: (job, progress) => { console.log(progress); }, onUploadCompleted: (job) => { console.log('Upload complete:', job); }, onUploadFailed: (job, error) => { console.error('Upload failed:', error); }, onVideosCreated: (videoKeys) => { console.log('Videos created:', videoKeys); } }); uploadManager.addUploadJobs(fileList); await uploadManager.start(); } main(); ``` ``` -------------------------------- ### Install ByteArk Video Upload SDK Source: https://context7.com/byteark/video-upload-sdk-js/llms.txt Install the SDK using npm or Yarn. ```bash # npm npm install --save @byteark/video-upload-sdk # Yarn yarn add @byteark/video-upload-sdk ``` -------------------------------- ### Start Uploading with start() Source: https://context7.com/byteark/video-upload-sdk-js/llms.txt Begins processing the job queue, launching TUS uploads concurrently. Calling start() a second time has no effect. Inspect the queue before starting and check getIsUploadStarted() after. ```typescript await manager.addUploadJobs(fileInput.files!); // Inspect queue before starting console.log(manager.getIsUploadStarted()); // false await manager.start(); console.log(manager.getIsUploadStarted()); // true // Jobs are now in 'uploading' state; callbacks fire asynchronously ``` -------------------------------- ### start() Source: https://context7.com/byteark/video-upload-sdk-js/llms.txt Initiates the upload process by starting to process the job queue. It launches multiple TUS uploads concurrently based on the `maximumConcurrentJobs` option and manages subsequent jobs as upload slots become available. Calling this method multiple times has no additional effect. ```APIDOC ## `start()` — Begin Uploading Starts processing the job queue. Launches up to `maximumConcurrentJobs` TUS uploads simultaneously and feeds subsequent jobs as slots free up. Calling `start()` a second time is a no-op. ### Method POST (Implicit, initiates background process) ### Endpoint N/A (SDK method) ### Parameters This method does not accept any parameters. ### Request Example ```ts await manager.start(); ``` ### Response This method does not return a value directly but initiates the upload process and updates the status of jobs in the queue. ``` -------------------------------- ### start Source: https://github.com/byteark/video-upload-sdk-js/blob/main/README.md Initiates the upload process for jobs in the queue. ```APIDOC ## start(): Promise ### Description Start uploading from a job queue. ### Method `start` ``` -------------------------------- ### Reconfigure Manager with setOptions() Source: https://context7.com/byteark/video-upload-sdk-js/llms.txt Updates manager options like credentials or callbacks. Must be called before start(); throws an error if called after uploading has begun. The example shows updating credentials and callbacks, and the error handling for calling after start(). ```typescript // Update credentials or callbacks before starting: manager.setOptions({ serviceName: 'byteark.stream', formId: 'updated-form-id', formSecret: 'updated-form-secret', projectKey: 'new-project-key', maximumConcurrentJobs: 2, onUploadProgress: (job, progress) => { document.getElementById(`progress-${job.uploadId}`)!.textContent = `${progress.percent}%`; }, onUploadCompleted: (job) => { console.log('Done:', job.uploadId); }, }); // After start() has been called, setOptions throws: try { manager.setOptions({ /* ... */ } as any); } catch (e) { console.error(e.message); // 'Cannot set new options after uploading has started.' } ``` -------------------------------- ### Install ByteArk Video Upload SDK with npm Source: https://github.com/byteark/video-upload-sdk-js/blob/main/README.md Use this command to add the SDK to your project if you are using npm as your package manager. ```bash npm install --save @byteark/video-upload-sdk ``` -------------------------------- ### Install ByteArk Video Upload SDK with Yarn Source: https://github.com/byteark/video-upload-sdk-js/blob/main/README.md Use this command to add the SDK to your project if you are using Yarn as your package manager. ```bash yarn add @byteark/video-upload-sdk ``` -------------------------------- ### Initialize and Use VideoUploadManager Source: https://github.com/byteark/video-upload-sdk-js/blob/main/README.md Demonstrates how to initialize the VideoUploadManager with SDK options and callback functions, and then add and start upload jobs. Ensure all required options like serviceName, formId, and formSecret are correctly provided. ```typescript import { VideoUploadManager } from '@byteark/video-upload-sdk'; async function main() { // Initialize the SDK const uploadManager = new VideoUploadManager({ // SDK Options serviceName: 'byteark.stream' | 'byteark.qoder', serviceEndpoint: 'https://stream.byteark.com' | 'https://qoder.byteark.com/apps//ajax', formId: '' | '', formSecret: '', projectKey: '' | '', overlayPresetId: 'overlayPresetId(Stream)', // Callback Functions onUploadProgress: (job: UploadJob, progress: UploadProgress) => { // Called when video uploading has a progress. }, onUploadCompleted: (job: UploadJob) => { // Called when a video has uploaded. }, onUploadFailed: (job: UploadJob, error: Error | DetailedError) => { // Called when video uploading failed (cannot retry). }, onVideosCreated: (videoKeys: string[]) => { // Called after all videos are created on our service. }, }); // An example use case uploadManager.addUploadJobs(fileList); await uploadManager.start(); } main(); ``` -------------------------------- ### setOptions Source: https://github.com/byteark/video-upload-sdk-js/blob/main/README.md Sets new options for the VideoUploadManager. This cannot be done if any upload job has already started. ```APIDOC ## setOptions(newOptions: UploadManagerOptions): void ### Description Set a new options to VideoUploadManager. This operation cannot be done when any upload job has already started. ### Method `setOptions` ### Parameters - `newOptions` (UploadManagerOptions) - Required - The new options to apply to the upload manager. ``` -------------------------------- ### Query Upload State (Started/Cancelled) Source: https://context7.com/byteark/video-upload-sdk-js/llms.txt Provides boolean getters to check if any upload has started or if all uploads have been cancelled. These are useful for controlling UI element states, such as disabling buttons. ```typescript // Disable "Start" button once upload has begun const startBtn = document.getElementById('start-btn') as HTMLButtonElement; startBtn.disabled = manager.getIsUploadStarted(); // Disable "Cancel All" once every job is cancelled const cancelAllBtn = document.getElementById('cancel-all') as HTMLButtonElement; cancelAllBtn.disabled = manager.getIsAllUploadCancelled(); // React example function UploadControls({ manager }) { const [jobs, setJobs] = useState(manager.getJobQueue()); return ( <> ); } ``` -------------------------------- ### setOptions(newOptions) Source: https://context7.com/byteark/video-upload-sdk-js/llms.txt Updates the manager's configuration options, including refreshing the authorization token. This method must be called before `start()` is invoked; otherwise, it will throw an error. It allows for dynamic adjustments to settings like service name, credentials, and callback functions. ```APIDOC ## `setOptions(newOptions)` — Reconfigure the Manager Replaces the current options object and refreshes the authorization token. **Must be called before `start()`**; throws if the upload has already begun. ### Parameters - **newOptions** (object) - Required - An object containing the new configuration options. Supported options include: - `serviceName` (string) - `formId` (string) - `formSecret` (string) - `projectKey` (string) - `maximumConcurrentJobs` (number) - `onUploadProgress` (function) - `onUploadCompleted` (function) - ... (other potential options) ### Request Example ```ts manager.setOptions({ serviceName: 'byteark.stream', formId: 'updated-form-id', formSecret: 'updated-form-secret', projectKey: 'new-project-key', maximumConcurrentJobs: 2, onUploadProgress: (job, progress) => { // Handle progress update }, onUploadCompleted: (job) => { // Handle completion }, }); ``` ### Error Handling - Throws an error if called after `start()` has been invoked. ### Response This method does not return a value directly but updates the manager's internal configuration. ``` -------------------------------- ### cancelAll() Source: https://context7.com/byteark/video-upload-sdk-js/llms.txt Cancels all active and paused uploads, marks queue entries as 'cancelled', clears uploader maps, and resets the 'started' flag. This allows the manager to be restarted. ```APIDOC ## cancelAll() ### Description Cancels all active and paused uploads in parallel, marks every queue entry as `'cancelled'`, clears both uploader maps, and resets `started` to `false` so the manager can be restarted. ### Method ```ts await manager.cancelAll(); ``` ### Usage Example ```ts await manager.addUploadJobs(files); await manager.start(); await manager.cancelAll(); console.log(manager.getIsAllUploadCancelled()); // true console.log(manager.getJobQueue().every(j => j.status === 'cancelled')); // true ``` ``` -------------------------------- ### Initialize and Manage Video Uploads in React Source: https://context7.com/byteark/video-upload-sdk-js/llms.txt This component initializes the VideoUploadManager with credentials and event handlers. It manages the state of upload jobs, including progress and status, and provides controls for starting, pausing, resuming, and canceling uploads. ```tsx import React, { useState, useCallback } from 'react'; import { VideoUploadManager } from '@byteark/video-upload-sdk'; import type { UploadJob, UploadProgress } from '@byteark/video-upload-sdk'; function VideoUploader() { const [manager, setManager] = useState(null); const [jobs, setJobs] = useState([]); // Step 1: Initialize the manager once with credentials const initManager = useCallback(() => { const mgr = new VideoUploadManager({ serviceName: 'byteark.stream', formId: process.env.REACT_APP_FORM_ID!, formSecret: process.env.REACT_APP_FORM_SECRET!, projectKey: process.env.REACT_APP_PROJECT_KEY!, maximumConcurrentJobs: 3, onVideosCreated: (videoKeys: string[]) => { console.log('Videos registered on ByteArk Stream:', videoKeys); }, onUploadStarted: (job: UploadJob) => { console.log('Upload started:', job.name); }, onUploadProgress: (job: UploadJob, progress: UploadProgress) => { setJobs(prev => prev.map(j => (j.uploadId === job.uploadId ? { ...job, progress } : j)) ); }, onUploadCompleted: (job: UploadJob) => { setJobs(prev => prev.map(j => (j.uploadId === job.uploadId ? job : j))); }, onUploadFailed: (job: UploadJob, error) => { console.error('Upload failed:', job.name, error); setJobs(prev => prev.map(j => (j.uploadId === job.uploadId ? job : j))); }, }); setManager(mgr); }, []); // Step 2: Add files const handleFileChange = useCallback(async (e: React.ChangeEvent) => { if (!manager || !e.target.files?.length) return; await manager.addUploadJobs(e.target.files); setJobs([...manager.getJobQueue()]); }, [manager]); // Step 3: Control uploads const handleStart = () => manager?.start(); const handlePause = (id: string) => { manager?.pauseUploadById(id); setJobs([...manager!.getJobQueue()]); }; const handleResume = (id: string) => { manager?.resumeUploadById(id); setJobs([...manager!.getJobQueue()]); }; const handleCancel = async (id: string) => { await manager?.cancelUploadById(id); setJobs([...manager!.getJobQueue()]); }; const handleCancelAll = async () => { await manager?.cancelAll(); setJobs([...manager!.getJobQueue()]); }; return (
{!manager && } {manager && ( <>
    {jobs.map(job => (
  • {job.name} — {job.status} {job.progress ? `${job.progress.percent}%` : ''}
  • ))}
)}
); } export default VideoUploader; ``` -------------------------------- ### Get Full Upload Job Queue Source: https://context7.com/byteark/video-upload-sdk-js/llms.txt Retrieves the current state of all upload jobs, including their status, progress, and associated file information. Useful for rendering UI elements like progress bars or job lists. ```typescript const queue = manager.getJobQueue(); /* [ ... ] */ // Render progress in a React component: queue.forEach(job => { console.log(`${job.name}: ${job.status} ${job.progress?.percent ?? 0}%`); }); ``` -------------------------------- ### Resume a Paused Job with resumeUploadById() Source: https://context7.com/byteark/video-upload-sdk-js/llms.txt Resumes a previously paused upload from its last point using TUS resume semantics. Throws if the uploadId is not found or not in a paused state. The example shows resuming and verifying the status change. ```typescript const resumedJob = await manager.resumeUploadById(uploadId); console.log(resumedJob.status); // 'uploading' console.log(manager.getJobByUploadId(uploadId)?.status); // 'uploading' ``` -------------------------------- ### Get Job by Upload ID Source: https://context7.com/byteark/video-upload-sdk-js/llms.txt Looks up a specific upload job using its unique `uploadId`. Returns the `UploadJob` object if found, otherwise `undefined`. Useful for directly accessing or updating the status of a particular upload. ```typescript const job = manager.getJobByUploadId('vid-key-1'); if (job) { console.log(job.name); // 'intro.mp4' console.log(job.status); // 'completed' console.log(job.progress?.percent); // 100 } ``` -------------------------------- ### Pause a Single Job with pauseUploadById() Source: https://context7.com/byteark/video-upload-sdk-js/llms.txt Pauses an actively uploading job, retaining partially uploaded data on the server for later resumption. Throws if the uploadId is not found or not currently uploading. The example demonstrates pausing and checking the status. ```typescript await manager.addUploadJobs(files); await manager.start(); const uploadId = manager.getJobQueue()[0].uploadId; // e.g. 'vid-key-abc' const pausedJob = await manager.pauseUploadById(uploadId); console.log(pausedJob.status); // 'paused' console.log(manager.getJobByUploadId(uploadId)?.status); // 'paused' ``` -------------------------------- ### Cancel a Single Job with cancelUploadById() Source: https://context7.com/byteark/video-upload-sdk-js/llms.txt Terminates an active or paused upload, removing it from the uploader maps. This action triggers uploadNextJob(), automatically filling the freed slot. The example shows canceling a job and observing the status change and subsequent job promotion. ```typescript await manager.addUploadJobs(files); // 3 files manager.setOptions({ ...options, maximumConcurrentJobs: 2 }); await manager.start(); // jobs 0 and 1 are 'uploading'; job 2 is 'pending' await manager.cancelUploadById('vid-key-1'); // slot freed → job 2 automatically promoted to 'uploading' console.log(manager.getJobByUploadId('vid-key-1')?.status); // 'cancelled' console.log(manager.getJobByUploadId('vid-key-3')?.status); // 'uploading' ``` -------------------------------- ### VideoUploadManager Constructor Source: https://context7.com/byteark/video-upload-sdk-js/llms.txt Initializes the `VideoUploadManager` with provided options. This manager handles the queue and TUS uploads. It supports configuration for both ByteArk Stream and the legacy ByteArk Qoder services. ```APIDOC ## `new VideoUploadManager(options)` — Constructor Creates and initializes the upload manager. Validates required fields, sets default service endpoints, and eagerly fetches the first authorization token. Throws synchronously if any required option is missing. ```ts import { VideoUploadManager } from '@byteark/video-upload-sdk'; import type { UploadJob, UploadProgress } from '@byteark/video-upload-sdk'; // ── ByteArk Stream ────────────────────────────────────────────────────────── const manager = new VideoUploadManager({ serviceName: 'byteark.stream', // serviceEndpoint defaults to 'https://stream.byteark.com' if omitted formId: 'my-form-id', // obtained from ByteArk Stream form upload setup formSecret: 'my-form-secret', // obtained from ByteArk Stream form upload setup projectKey: 'my-project-key', overlayPresetId: 'preset-abc', // optional: apply overlay to all uploads maximumConcurrentJobs: 3, // default: 3 onVideosCreated: (videoKeys: string[]) => { console.log('Remote video records created:', videoKeys); // e.g. ['vid-key-1', 'vid-key-2'] }, onUploadStarted: (job: UploadJob) => { console.log('Started:', job.name, job.uploadId); }, onUploadProgress: (job: UploadJob, progress: UploadProgress) => { console.log(`${job.name}: ${progress.percent}% (${progress.bytesUploaded}/${progress.bytesTotal})`); }, onUploadCompleted: (job: UploadJob) => { console.log('Completed:', job.name, '→ status:', job.status); // 'completed' }, onUploadFailed: (job: UploadJob, error) => { console.error('Failed:', job.name, error.message); }, }); // ── ByteArk Qoder (legacy) ────────────────────────────────────────────────── const qoderManager = new VideoUploadManager({ serviceName: 'byteark.qoder', // serviceEndpoint defaults to 'https://qoder.byteark.com/apps//ajax' formId: 'my-app-id', formSecret: 'my-app-secret', projectKey: 'my-project-id', }); ``` ### Required `UploadManagerOptions` fields | Field | Type | Description | |---|---|---| | `serviceName` | `'byteark.stream' | 'byteark.qoder'` | Target service | | `formId` | `string` | Form ID (Stream) or App ID (Qoder) | | `formSecret` | `string` | Form secret (Stream) or App secret (Qoder) | | `projectKey` | `string` | Destination project key / ID | | `serviceEndpoint` | `string` (optional) | Override default API base URL | | `overlayPresetId` | `string` (optional) | Apply a Stream overlay preset to all uploads | | `maximumConcurrentJobs` | `number` (optional) | Max parallel uploads, default `3` | | `headers` | `Record` (optional) | Extra HTTP headers forwarded to TUS requests | ``` -------------------------------- ### onUploadStarted Source: https://github.com/byteark/video-upload-sdk-js/blob/main/README.md Callback triggered when the first upload job begins uploading. ```APIDOC ## onUploadStarted(job: UploadJob) ### Description Triggers after the first upload job started uploading. ### Parameters - `job` (UploadJob) - The upload job that has started. ``` -------------------------------- ### Queue Videos for Upload with addUploadJobs Source: https://context7.com/byteark/video-upload-sdk-js/llms.txt Registers one or more video files with the manager. Supports File[], FileList, or VideoFileObject[]. Use VideoFileObject for metadata and overlay control. After this call, onVideosCreated fires with returned video keys. ```typescript // ── Simple: use File / FileList directly ─────────────────────────────────── const fileInput = document.getElementById('video-input') as HTMLInputElement; await manager.addUploadJobs(fileInput.files!); // video titles will default to each file's .name ``` ```typescript // ── Rich: use VideoFileObject for metadata / overlay control ─────────────── const videoFileObjects = [ { file: new File([blob1], 'intro.mp4', { type: 'video/mp4' }), videoMetadata: { title: 'Company Intro', tags: [{ name: 'marketing' }, { name: 'intro' }], }, useOverlayPreset: true, // apply overlayPresetId defined on the manager }, { file: new File([blob2], 'tutorial.mp4', { type: 'video/mp4' }), videoMetadata: { title: 'Getting Started Tutorial', }, useOverlayPreset: false, }, ]; await manager.addUploadJobs(videoFileObjects); // After this call, onVideosCreated fires: // ['vid-key-for-intro', 'vid-key-for-tutorial'] // Inspect the queue immediately after adding: console.log(manager.getJobQueue()); // [ // { uploadId: 'vid-key-for-intro', name: 'intro.mp4', status: 'pending', file: File }, // { uploadId: 'vid-key-for-tutorial', name: 'tutorial.mp4', status: 'pending', file: File }, // ] ``` -------------------------------- ### Initialize VideoUploadManager for ByteArk Stream Source: https://context7.com/byteark/video-upload-sdk-js/llms.txt Initialize the VideoUploadManager for ByteArk Stream, providing service details, form credentials, and optional configuration like concurrent jobs and event callbacks. ```typescript import { VideoUploadManager } from '@byteark/video-upload-sdk'; import type { UploadJob, UploadProgress } from '@byteark/video-upload-sdk'; // ── ByteArk Stream ────────────────────────────────────────────────────────── const manager = new VideoUploadManager({ serviceName: 'byteark.stream', // serviceEndpoint defaults to 'https://stream.byteark.com' if omitted formId: 'my-form-id', // obtained from ByteArk Stream form upload setup formSecret: 'my-form-secret', // obtained from ByteArk Stream form upload setup projectKey: 'my-project-key', overlayPresetId: 'preset-abc', // optional: apply overlay to all uploads maximumConcurrentJobs: 3, // default: 3 onVideosCreated: (videoKeys: string[]) => { console.log('Remote video records created:', videoKeys); // e.g. ['vid-key-1', 'vid-key-2'] }, onUploadStarted: (job: UploadJob) => { console.log('Started:', job.name, job.uploadId); }, onUploadProgress: (job: UploadJob, progress: UploadProgress) => { console.log(`${job.name}: ${progress.percent}% (${progress.bytesUploaded}/${progress.bytesTotal})`); }, onUploadCompleted: (job: UploadJob) => { console.log('Completed:', job.name, '→ status:', job.status); // 'completed' }, onUploadFailed: (job: UploadJob, error) => { console.error('Failed:', job.name, error.message); }, }); // ── ByteArk Qoder (legacy) ────────────────────────────────────────────────── const qoderManager = new VideoUploadManager({ serviceName: 'byteark.qoder', // serviceEndpoint defaults to 'https://qoder.byteark.com/apps//ajax' formId: 'my-app-id', formSecret: 'my-app-secret', projectKey: 'my-project-id', }); ``` -------------------------------- ### addUploadJobs(files) Source: https://context7.com/byteark/video-upload-sdk-js/llms.txt Registers one or more video files with the manager, queues them for upload, and internally calls the ByteArk video-creation API. It supports various input types including File[], FileList, or VideoFileObject[]. ```APIDOC ## `addUploadJobs(files)` — Queue Videos for Upload Registers one or more video files with the manager. Internally calls the ByteArk video-creation API, fires `onVideosCreated` with the returned video keys, then appends `UploadJob` entries to the internal queue. Supports `File[]`, `FileList`, or `VideoFileObject[]`. ### Parameters - **files** (File[] | FileList | VideoFileObject[]) - Required - An array or list of files or video objects to be uploaded. ### Request Example ```ts // Simple usage with FileList const fileInput = document.getElementById('video-input') as HTMLInputElement; await manager.addUploadJobs(fileInput.files!); // Rich usage with VideoFileObject for metadata const videoFileObjects = [ { file: new File([blob1], 'intro.mp4', { type: 'video/mp4' }), videoMetadata: { title: 'Company Intro', tags: [{ name: 'marketing' }, { name: 'intro' }], }, useOverlayPreset: true, }, // ... other video objects ]; await manager.addUploadJobs(videoFileObjects); ``` ### Response This method does not return a value directly but triggers the `onVideosCreated` event with video keys and updates the internal job queue. ``` -------------------------------- ### getIsUploadStarted Source: https://github.com/byteark/video-upload-sdk-js/blob/main/README.md Checks if any upload job has been initiated. ```APIDOC ## getIsUploadStarted ### Description Indicates whether the upload process has started for any job in the queue. ### Method Signature `getIsUploadStarted(): boolean` ### Returns - **boolean**: `true` if at least one upload job has started, `false` otherwise. ``` -------------------------------- ### getIsUploadStarted() / getIsAllUploadCancelled() Source: https://context7.com/byteark/video-upload-sdk-js/llms.txt Provides boolean status queries for upload state, useful for controlling UI elements like buttons. ```APIDOC ## getIsUploadStarted() / getIsAllUploadCancelled() ### Description Convenience boolean getters for controlling UI elements. ### Methods - `getIsUploadStarted()`: Returns `true` if any upload has started, `false` otherwise. - `getIsAllUploadCancelled()`: Returns `true` if all upload jobs have been cancelled, `false` otherwise. ### Usage Example ```ts // Disable "Start" button once upload has begun const startBtn = document.getElementById('start-btn') as HTMLButtonElement; startBtn.disabled = manager.getIsUploadStarted(); // Disable "Cancel All" once every job is cancelled const cancelAllBtn = document.getElementById('cancel-all') as HTMLButtonElement; cancelAllBtn.disabled = manager.getIsAllUploadCancelled(); // React example function UploadControls({ manager }) { const [jobs, setJobs] = useState(manager.getJobQueue()); return ( <> ); } ``` ``` -------------------------------- ### onVideosCreated Source: https://github.com/byteark/video-upload-sdk-js/blob/main/README.md Callback triggered after all videos have been successfully created on the service. ```APIDOC ## onVideosCreated(videoKeys: string[]) ### Description Triggers after all videos are created on our service, which will happen after calling `addUploadJobs(files)` method. ### Parameters - `videoKeys` (string[]) - An array of keys for the created videos. ``` -------------------------------- ### addUploadJobs Source: https://github.com/byteark/video-upload-sdk-js/blob/main/README.md Adds video files to the upload queue. The SDK will create videos from these files and trigger the `onVideosCreated` callback. ```APIDOC ## addUploadJobs ### Description Adds video files to the upload queue. The SDK processes these files, creates corresponding video entries on the service, and invokes the `onVideosCreated` callback with the keys of the newly created videos. ### Method Signature `addUploadJobs(files: FileList | File[] | VideoFileObject[]): Promise` ### Parameters - **files** (FileList | File[] | VideoFileObject[]) - Required - A list of files or file-like objects to be uploaded. ``` -------------------------------- ### getJobQueue() Source: https://context7.com/byteark/video-upload-sdk-js/llms.txt Returns the live UploadJob array, providing the current state of each job (pending, uploading, paused, completed, failed, cancelled) and progress data. ```APIDOC ## getJobQueue() ### Description Returns the live `UploadJob[]` array. Each entry reflects the current state of the job (`pending`, `uploading`, `paused`, `completed`, `failed`, `cancelled`) along with byte-level progress data when available. ### Method ```ts const queue = manager.getJobQueue(); ``` ### Response Example ```json [ { "uploadId": "vid-key-1", "name": "movie.mp4", "status": "uploading", "file": "File", "progress": { "bytesUploaded": 52428800, "bytesTotal": 104857600, "percent": 50 } }, { "uploadId": "vid-key-2", "name": "clip.mp4", "status": "pending", "file": "File", "progress": undefined } ] ``` ### Usage Example ```ts // Render progress in a React component: queue.forEach(job => { console.log(`${job.name}: ${job.status} ${job.progress?.percent ?? 0}%`); }); ``` ``` -------------------------------- ### resumeUploadById(uploadId) Source: https://context7.com/byteark/video-upload-sdk-js/llms.txt Resumes a video upload job that was previously paused. It utilizes TUS resume semantics to continue the upload from where it left off. An error is thrown if the `uploadId` is not found or if the job is not in a 'paused' state. ```APIDOC ## `resumeUploadById(uploadId)` — Resume a Paused Job Resumes a previously paused upload from where it left off via TUS resume semantics. Throws if the `uploadId` is not found or not in a paused state. ### Parameters - **uploadId** (string) - Required - The unique identifier of the upload job to resume. ### Request Example ```ts const resumedJob = await manager.resumeUploadById(uploadId); console.log(resumedJob.status); // 'uploading' ``` ### Response - **resumedJob** (object) - The job object that has been resumed, with its status updated to 'uploading'. ### Error Handling - Throws if the `uploadId` is not found or the job is not in a paused state. ``` -------------------------------- ### onUploadProgress Source: https://github.com/byteark/video-upload-sdk-js/blob/main/README.md Callback triggered periodically to report the upload progress of jobs. ```APIDOC ## onUploadProgress(job: UploadJob, progress: UploadProgress) ### Description Triggers periodically when upload job(s) are being uploaded. ### Parameters - `job` (UploadJob) - The upload job for which progress is reported. - `progress` (UploadProgress) - An object containing the current upload progress details. ``` -------------------------------- ### getJobQueue Source: https://github.com/byteark/video-upload-sdk-js/blob/main/README.md Retrieves the current queue of upload jobs. ```APIDOC ## getJobQueue ### Description Returns an array containing all the current upload jobs in the queue. ### Method Signature `getJobQueue(): UploadJob[]` ### Returns - **UploadJob[]**: An array of `UploadJob` objects representing the jobs in the queue. ``` -------------------------------- ### cancelAll Source: https://github.com/byteark/video-upload-sdk-js/blob/main/README.md Cancels all upload jobs currently in the queue. ```APIDOC ## cancelAll(): Promise ### Description Cancel all jobs in a job queue. ### Method `cancelAll` ``` -------------------------------- ### onUploadFailed Source: https://github.com/byteark/video-upload-sdk-js/blob/main/README.md Callback triggered if an error occurs during the upload process, halting the uploader. ```APIDOC ## onUploadFailed(job: UploadJob, error: Error | DetailedError) ### Description Triggers when something happened while uploading and halted the uploader. ### Parameters - `job` (UploadJob) - The upload job that failed. - `error` (Error | DetailedError) - The error object detailing the failure. ``` -------------------------------- ### onUploadCompleted Source: https://github.com/byteark/video-upload-sdk-js/blob/main/README.md Callback triggered once all upload jobs have finished successfully. ```APIDOC ## onUploadCompleted(job: UploadJob) ### Description Triggers after all upload jobs finished uploading. ### Parameters - `job` (UploadJob) - The upload job that has completed. ``` -------------------------------- ### resumeUploadById Source: https://github.com/byteark/video-upload-sdk-js/blob/main/README.md Resumes a paused upload job identified by its upload ID. ```APIDOC ## resumeUploadById(uploadId: UploadId): Promise ### Description Resume a job by the provided uploadId. This method throws an error when a job with the provided uploadId cannot be found. ### Method `resumeUploadById` ### Parameters - `uploadId` (UploadId) - Required - The ID of the upload job to resume. ``` -------------------------------- ### pauseUploadById(uploadId) Source: https://context7.com/byteark/video-upload-sdk-js/llms.txt Pauses a specific video upload job that is currently in progress. The upload can be resumed later from the point it was paused. This method throws an error if the specified `uploadId` is not found or if the job is not in an actively uploading state. ```APIDOC ## `pauseUploadById(uploadId)` — Pause a Single Job Pauses an actively uploading job. The partially uploaded data is retained on the server and can be resumed later. Throws if the `uploadId` is not found or not currently uploading. ### Parameters - **uploadId** (string) - Required - The unique identifier of the upload job to pause. ### Request Example ```ts const uploadId = manager.getJobQueue()[0].uploadId; // e.g. 'vid-key-abc' const pausedJob = await manager.pauseUploadById(uploadId); console.log(pausedJob.status); // 'paused' ``` ### Response - **pausedJob** (object) - The job object that has been paused, with its status updated to 'paused'. ### Error Handling - Throws if the `uploadId` is not found or the job is not currently uploading. ``` -------------------------------- ### Cancel All Upload Jobs Source: https://context7.com/byteark/video-upload-sdk-js/llms.txt Use this method to cancel all ongoing and paused uploads. It marks all jobs as 'cancelled' and resets the manager's state, allowing it to be restarted. ```typescript await manager.addUploadJobs(files); await manager.start(); await manager.cancelAll(); console.log(manager.getIsAllUploadCancelled()); // true console.log(manager.getJobQueue().every(j => j.status === 'cancelled')); // true ``` -------------------------------- ### getJobByUploadId(uploadId) Source: https://context7.com/byteark/video-upload-sdk-js/llms.txt Retrieves a specific UploadJob by its unique uploadId. Returns undefined if no job matches the provided ID. ```APIDOC ## getJobByUploadId(uploadId) ### Description Returns the `UploadJob` matching the given `uploadId` (video key for Stream, video source ID for Qoder), or `undefined` if not found. ### Method ```ts const job = manager.getJobByUploadId('vid-key-1'); ``` ### Parameters #### Path Parameters - **uploadId** (string) - Required - The unique identifier for the upload job. ### Usage Example ```ts const job = manager.getJobByUploadId('vid-key-1'); if (job) { console.log(job.name); // 'intro.mp4' console.log(job.status); // 'completed' console.log(job.progress?.percent); // 100 } ``` ``` -------------------------------- ### getIsAllUploadCancelled Source: https://github.com/byteark/video-upload-sdk-js/blob/main/README.md Checks if all upload jobs in the queue have been cancelled. ```APIDOC ## getIsAllUploadCancelled ### Description Determines if all upload jobs currently in the queue have been cancelled. ### Method Signature `getIsAllUploadCancelled(): boolean` ### Returns - **boolean**: `true` if all jobs have been cancelled, `false` otherwise. ``` -------------------------------- ### pauseUploadById Source: https://github.com/byteark/video-upload-sdk-js/blob/main/README.md Pauses a specific upload job identified by its upload ID. ```APIDOC ## pauseUploadById(uploadId: UploadId): Promise ### Description Pause a job by the provided uploadId. This method throws an error when a job with the provided uploadId cannot be found. ### Method `pauseUploadById` ### Parameters - `uploadId` (UploadId) - Required - The ID of the upload job to pause. ``` -------------------------------- ### getJobByUploadId Source: https://github.com/byteark/video-upload-sdk-js/blob/main/README.md Retrieves a specific upload job using its unique upload ID. ```APIDOC ## getJobByUploadId ### Description Fetches and returns a single upload job that matches the provided `uploadId`. ### Method Signature `getJobByUploadId(uploadId: string): UploadJob | undefined` ### Parameters - **uploadId** (string) - Required - The unique identifier of the upload job to retrieve. ### Returns - **UploadJob | undefined**: The `UploadJob` object if found, otherwise `undefined`. ``` -------------------------------- ### cancelUploadById(uploadId) Source: https://context7.com/byteark/video-upload-sdk-js/llms.txt Cancels a video upload job, whether it is actively uploading or paused. This action removes the job from the uploader's management and triggers the processing of the next queued item to fill the freed slot. The status of the cancelled job is updated to 'cancelled'. ```APIDOC ## `cancelUploadById(uploadId)` — Cancel a Single Job Terminates an active or paused upload and removes it from the active/paused uploader maps. Triggers `uploadNextJob()` so the next queued item fills the freed slot automatically. ### Parameters - **uploadId** (string) - Required - The unique identifier of the upload job to cancel. ### Request Example ```ts await manager.cancelUploadById('vid-key-1'); console.log(manager.getJobByUploadId('vid-key-1')?.status); // 'cancelled' ``` ### Response This method does not return a value directly but updates the status of the specified job to 'cancelled' and potentially triggers the upload of the next job in the queue. ``` -------------------------------- ### cancelUploadById Source: https://github.com/byteark/video-upload-sdk-js/blob/main/README.md Cancels a specific upload job identified by its upload ID. ```APIDOC ## cancelUploadById(uploadId: UploadId): Promise ### Description Cancel a job by the provided uploadId. This method throws an error when a job with the provided uploadId cannot be found. ### Method `cancelUploadById` ### Parameters - `uploadId` (UploadId) - Required - The ID of the upload job to cancel. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.