Skip to content

Commit

Permalink
Merge pull request #32 from apivideo/static-wrapper
Browse files Browse the repository at this point in the history
Add static wrapper
  • Loading branch information
olivier-lando authored Oct 31, 2023
2 parents 8615fb1 + b48b66b commit d7569ca
Show file tree
Hide file tree
Showing 7 changed files with 417 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tabWidth": 4,
"useTabs": false,
"printWidth": 120
}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog
All changes to this project will be documented in this file.

## [1.1.6] - 2023-10-31
- Add static wrapper

## [1.1.5] - 2023-10-26
- Add cancel() methods
- Add part number in progressive upload onProgress()
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
- [`onProgress()`](#onprogress-1)
- [`cancel()`](#cancel-1)
- [`onPlayable()`](#onplayable-1)
- [Static wrapper](#static-wrapper)

# Project description

Expand Down Expand Up @@ -402,3 +403,7 @@ The onPlayable() method let you defined a listener that will be called when the
</script>
```


# Static wrapper

For situations where managing object instances is impractical, consider using the [UploaderStaticWrapper](./doc/UploaderStaticWrapper.md) class, which offers static method equivalents for all functionalities.
115 changes: 115 additions & 0 deletions doc/UploaderStaticWrapper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Uploader static wrapper documentation

## Overview

The `UploaderStaticWrapper` class serves as a static interface to the underlying object-oriented uploader library.

This static abstraction is particularly beneficial in contexts where direct object manipulation can be challenging, such as when working within cross-platform frameworks like Flutter or React Native, or in no-code solutions.

By providing a suite of static methods, `UploaderStaticWrapper` allows developers to leverage the power of the library without the complexity of handling instances or managing object lifecycles.

This approach simplifies integration, making it more accessible for a wider range of development environments where traditional object-oriented paradigms are less suitable or harder to implement.

## Common functions

### `UploaderStaticWrapper.setApplicationName(name: string, version: string)`

Sets the application name and version for the SDK.

- **Parameters:**
- `name: string` - The name of the application using the SDK.
- `version: string` - The version of the application.

### `UploaderStaticWrapper.setChunkSize(chunkSize: number)`

Sets the chunk size for the video upload.

- **Parameters:**
- `chunkSize: number` - The size of each chunk in bytes.


### `UploaderStaticWrapper.cancelAll()`

Cancels all ongoing uploads, both progressive and standard.


## Standard uploads functions


### `UploaderStaticWrapper.uploadWithUploadToken(blob: Blob, uploadToken: string, videoName: string, onProgress: (event: number) => void, videoId?: string)`

Uploads a video with an upload token.

- **Parameters:**
- `blob: Blob` - The video file to be uploaded.
- `uploadToken: string` - The upload token provided by the backend.
- `videoName: string` - The name of the video.
- `onProgress: (event: number) => void` - The callback to call on progress updates.
- `videoId?: string` - The ID of the video to be uploaded (optional).

- **Returns:**
- `Promise<string>` - A promise resolving to a JSON representation of the `VideoUploadResponse` object.

### `UploaderStaticWrapper.uploadWithApiKey(blob: Blob, apiKey: string, onProgress: (event: number) => void, videoId: string)`

Uploads a video with an API key.

- **Parameters:**
- `blob: Blob` - The video file to be uploaded.
- `apiKey: string` - The API key provided by the backend.
- `onProgress: (event: number) => void` - The callback to call on progress updates.
- `videoId: string` - The ID of the video to be uploaded (optional).

- **Returns:**
- `Promise<string>` - A promise resolving to a JSON representation of the `VideoUploadResponse` object.

## Progressive uploads functions

### `UploaderStaticWrapper.createProgressiveUploadWithUploadTokenSession(sessionId: string, uploadToken: string, videoId: string)`

Creates a new progressive upload session with an upload token.

- **Parameters:**
- `sessionId: string` - The unique session identifier.
- `uploadToken: string` - The upload token provided by the backend.
- `videoId: string` - The ID of the video to be uploaded.

### `UploaderStaticWrapper.createProgressiveUploadWithApiKeySession(sessionId: string, apiKey: string, videoId: string)`

Creates a new progressive upload session with an API key.

- **Parameters:**
- `sessionId: string` - The unique session identifier.
- `apiKey: string` - The API key provided by the backend.
- `videoId: string` - The ID of the video to be uploaded.

### `UploaderStaticWrapper.uploadPart(sessionId: string, blob: Blob, onProgress: (progress: number) => void)`

Uploads a part of a video in a progressive upload session.

- **Parameters:**
- `sessionId: string` - The unique session identifier.
- `blob: Blob` - The video part.
- `onProgress: (progress: number) => void` - The callback to call on progress updates.

- **Returns:**
- `Promise<string>` - A promise resolving to a JSON representation of the `VideoUploadResponse` object.
-
### `UploaderStaticWrapper.uploadLastPart(sessionId: string, blob: Blob, onProgress: (progress: number) => void)`

Uploads the last part of a video in a progressive upload session and finalizes the upload.

- **Parameters:**
- `sessionId: string` - The unique session identifier.
- `blob: Blob` - The video part.
- `onProgress: (progress: number) => void` - The callback to call on progress updates.

- **Returns:**
- `Promise<string>` - A promise resolving to a JSON representation of the `VideoUploadResponse` object.

### `UploaderStaticWrapper.disposeProgressiveUploadSession(sessionId: string)`

Disposes a progressive upload session by its ID.

- **Parameters:**
- `sessionId: string` - The unique session identifier to dispose.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@api.video/video-uploader",
"version": "1.1.5",
"version": "1.1.6",
"description": "api.video video uploader",
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ import { VideoUploader } from "./video-uploader";
export { UploadProgressEvent, VideoUploader, VideoUploaderOptionsWithAccessToken, VideoUploaderOptionsWithUploadToken } from "./video-uploader";
export { ProgressiveUploadProgressEvent, ProgressiveUploader, ProgressiveUploaderOptionsWithAccessToken, ProgressiveUploaderOptionsWithUploadToken } from './progressive-video-uploader';
export { VideoUploadResponse, MIN_CHUNK_SIZE, MAX_CHUNK_SIZE } from './abstract-uploader';
export { UploaderStaticWrapper } from './static-wrapper';
Loading

0 comments on commit d7569ca

Please sign in to comment.