@scalemule/sdk 0.0.38 → 0.0.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +94 -0
- package/dist/index.d.ts +94 -0
- package/dist/index.js +117 -3
- package/dist/index.mjs +117 -3
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1691,8 +1691,47 @@ interface VideoInfo {
|
|
|
1691
1691
|
created_at: string;
|
|
1692
1692
|
updated_at: string;
|
|
1693
1693
|
}
|
|
1694
|
+
/** Request body for {@link VideoService.register}. */
|
|
1695
|
+
interface RegisterVideoRequest {
|
|
1696
|
+
/** Storage file_id of the previously-uploaded video. */
|
|
1697
|
+
fileId: string;
|
|
1698
|
+
/** Optional override; defaults to the gateway-injected x-user-id. */
|
|
1699
|
+
userId?: string;
|
|
1700
|
+
}
|
|
1701
|
+
/** Response shape from POST /v1/videos/register. */
|
|
1702
|
+
interface RegisterVideoResponse {
|
|
1703
|
+
video_id: string;
|
|
1704
|
+
file_id: string;
|
|
1705
|
+
/** `registering` (scan was clean) | `pending_scan` (scan in progress) */
|
|
1706
|
+
status: 'registering' | 'pending_scan';
|
|
1707
|
+
original_view_url: string;
|
|
1708
|
+
}
|
|
1709
|
+
/** Result of {@link VideoService.uploadViaStorage}. */
|
|
1710
|
+
interface VideoUploadViaStorageResult {
|
|
1711
|
+
/** Storage file_id — store this in chat-attachment metadata. */
|
|
1712
|
+
file_id: string;
|
|
1713
|
+
/** Video service id. Equals `file_id` for storage-backed videos. */
|
|
1714
|
+
video_id: string;
|
|
1715
|
+
/**
|
|
1716
|
+
* Short-lived signed URL to the original bytes. Usable immediately on the
|
|
1717
|
+
* recipient side, before HLS transcoding completes.
|
|
1718
|
+
*/
|
|
1719
|
+
original_view_url: string | null;
|
|
1720
|
+
/**
|
|
1721
|
+
* Resolves once the transcode worker finishes (or times out at 30s).
|
|
1722
|
+
* On resolution: an HLS master playlist URL. On timeout: `null` — caller
|
|
1723
|
+
* should fall back to `original_view_url` and try the playlist later.
|
|
1724
|
+
*/
|
|
1725
|
+
hls_url_promise: Promise<string | null>;
|
|
1726
|
+
}
|
|
1694
1727
|
declare class VideoService extends ServiceModule {
|
|
1728
|
+
private readonly storage;
|
|
1695
1729
|
protected basePath: string;
|
|
1730
|
+
/**
|
|
1731
|
+
* @param storage Required for {@link uploadViaStorage}. Wired up by the
|
|
1732
|
+
* top-level {@link ScaleMule} constructor.
|
|
1733
|
+
*/
|
|
1734
|
+
constructor(client: ScaleMuleClient, storage: StorageService);
|
|
1696
1735
|
/**
|
|
1697
1736
|
* Upload a video file using chunked multipart upload.
|
|
1698
1737
|
*
|
|
@@ -1706,6 +1745,61 @@ declare class VideoService extends ServiceModule {
|
|
|
1706
1745
|
upload(file: File | Blob, options?: VideoUploadOptions, requestOptions?: RequestOptions): Promise<ApiResponse<VideoInfo>>;
|
|
1707
1746
|
/** Get video metadata and status. */
|
|
1708
1747
|
get(videoId: string, options?: RequestOptions): Promise<ApiResponse<VideoInfo>>;
|
|
1748
|
+
/**
|
|
1749
|
+
* Register a video from a file already uploaded to scalemule-storage.
|
|
1750
|
+
*
|
|
1751
|
+
* The synchronous handshake for storage-uploaded videos. Verifies the
|
|
1752
|
+
* caller's app owns the storage `file_id` and reads scan status:
|
|
1753
|
+
* - clean → 201, video record created with status='uploading',
|
|
1754
|
+
* transcode worker advances on `scan.file.completed`
|
|
1755
|
+
* - pending → 202, video record created with status='pending_scan',
|
|
1756
|
+
* worker advances when scan completes
|
|
1757
|
+
* - threat → 409 (rejected; row not created)
|
|
1758
|
+
*
|
|
1759
|
+
* Idempotent: calling twice with the same file_id returns the existing
|
|
1760
|
+
* row's data (the underlying INSERT uses ON DUPLICATE KEY UPDATE).
|
|
1761
|
+
*
|
|
1762
|
+
* For storage-backed videos `video_id == file_id` — the response's
|
|
1763
|
+
* `video_id` and `file_id` are identical, and either can be used with
|
|
1764
|
+
* `getStreamUrl()` / `get()`.
|
|
1765
|
+
*
|
|
1766
|
+
* Most callers should use {@link uploadViaStorage} which composes
|
|
1767
|
+
* `storage.uploadPrivate()` + `register()` in a single call.
|
|
1768
|
+
*/
|
|
1769
|
+
register(request: RegisterVideoRequest, options?: RequestOptions): Promise<ApiResponse<RegisterVideoResponse>>;
|
|
1770
|
+
/**
|
|
1771
|
+
* Upload a video to storage (browser → S3 direct, private, no
|
|
1772
|
+
* compression) and register it with the video service so transcoding
|
|
1773
|
+
* + HLS streaming work.
|
|
1774
|
+
*
|
|
1775
|
+
* The canonical chat-attachment / progressive-video upload primitive.
|
|
1776
|
+
* Same private-direct-to-S3 path as `storage.uploadPrivate()`, plus a
|
|
1777
|
+
* follow-up `video.register()` call so HLS playback URLs become live
|
|
1778
|
+
* once the transcoder finishes.
|
|
1779
|
+
*
|
|
1780
|
+
* The returned `hls_url_promise` resolves once the video's status
|
|
1781
|
+
* flips to `ready` (or after a 30s timeout — caller can still serve
|
|
1782
|
+
* `original_view_url` as the fallback). Phase 3 of the realtime-chat
|
|
1783
|
+
* media pipeline ADR replaces the poll with a realtime subscription.
|
|
1784
|
+
*
|
|
1785
|
+
* If `register()` fails after a successful storage upload, the file
|
|
1786
|
+
* is *not* lost: the returned `file_id` is still valid as a generic
|
|
1787
|
+
* storage file. SDK logs a warning and resolves `hls_url_promise`
|
|
1788
|
+
* to `null`.
|
|
1789
|
+
*/
|
|
1790
|
+
uploadViaStorage(file: File | Blob, uploadOptions?: {
|
|
1791
|
+
userId?: string;
|
|
1792
|
+
filename?: string;
|
|
1793
|
+
metadata?: Record<string, unknown>;
|
|
1794
|
+
onProgress?: (progress: number) => void;
|
|
1795
|
+
signal?: AbortSignal;
|
|
1796
|
+
}, requestOptions?: RequestOptions): Promise<ApiResponse<VideoUploadViaStorageResult>>;
|
|
1797
|
+
/**
|
|
1798
|
+
* Poll {@link get} until the video's status is `ready` or the 30s
|
|
1799
|
+
* timeout fires. Resolves to the HLS master playlist URL on success;
|
|
1800
|
+
* `null` on timeout (caller should fall back to `original_view_url`).
|
|
1801
|
+
*/
|
|
1802
|
+
private pollTranscodeComplete;
|
|
1709
1803
|
/**
|
|
1710
1804
|
* Get the HLS master playlist URL for streaming.
|
|
1711
1805
|
* Returns the playlist URL that can be passed to a video player.
|
package/dist/index.d.ts
CHANGED
|
@@ -1691,8 +1691,47 @@ interface VideoInfo {
|
|
|
1691
1691
|
created_at: string;
|
|
1692
1692
|
updated_at: string;
|
|
1693
1693
|
}
|
|
1694
|
+
/** Request body for {@link VideoService.register}. */
|
|
1695
|
+
interface RegisterVideoRequest {
|
|
1696
|
+
/** Storage file_id of the previously-uploaded video. */
|
|
1697
|
+
fileId: string;
|
|
1698
|
+
/** Optional override; defaults to the gateway-injected x-user-id. */
|
|
1699
|
+
userId?: string;
|
|
1700
|
+
}
|
|
1701
|
+
/** Response shape from POST /v1/videos/register. */
|
|
1702
|
+
interface RegisterVideoResponse {
|
|
1703
|
+
video_id: string;
|
|
1704
|
+
file_id: string;
|
|
1705
|
+
/** `registering` (scan was clean) | `pending_scan` (scan in progress) */
|
|
1706
|
+
status: 'registering' | 'pending_scan';
|
|
1707
|
+
original_view_url: string;
|
|
1708
|
+
}
|
|
1709
|
+
/** Result of {@link VideoService.uploadViaStorage}. */
|
|
1710
|
+
interface VideoUploadViaStorageResult {
|
|
1711
|
+
/** Storage file_id — store this in chat-attachment metadata. */
|
|
1712
|
+
file_id: string;
|
|
1713
|
+
/** Video service id. Equals `file_id` for storage-backed videos. */
|
|
1714
|
+
video_id: string;
|
|
1715
|
+
/**
|
|
1716
|
+
* Short-lived signed URL to the original bytes. Usable immediately on the
|
|
1717
|
+
* recipient side, before HLS transcoding completes.
|
|
1718
|
+
*/
|
|
1719
|
+
original_view_url: string | null;
|
|
1720
|
+
/**
|
|
1721
|
+
* Resolves once the transcode worker finishes (or times out at 30s).
|
|
1722
|
+
* On resolution: an HLS master playlist URL. On timeout: `null` — caller
|
|
1723
|
+
* should fall back to `original_view_url` and try the playlist later.
|
|
1724
|
+
*/
|
|
1725
|
+
hls_url_promise: Promise<string | null>;
|
|
1726
|
+
}
|
|
1694
1727
|
declare class VideoService extends ServiceModule {
|
|
1728
|
+
private readonly storage;
|
|
1695
1729
|
protected basePath: string;
|
|
1730
|
+
/**
|
|
1731
|
+
* @param storage Required for {@link uploadViaStorage}. Wired up by the
|
|
1732
|
+
* top-level {@link ScaleMule} constructor.
|
|
1733
|
+
*/
|
|
1734
|
+
constructor(client: ScaleMuleClient, storage: StorageService);
|
|
1696
1735
|
/**
|
|
1697
1736
|
* Upload a video file using chunked multipart upload.
|
|
1698
1737
|
*
|
|
@@ -1706,6 +1745,61 @@ declare class VideoService extends ServiceModule {
|
|
|
1706
1745
|
upload(file: File | Blob, options?: VideoUploadOptions, requestOptions?: RequestOptions): Promise<ApiResponse<VideoInfo>>;
|
|
1707
1746
|
/** Get video metadata and status. */
|
|
1708
1747
|
get(videoId: string, options?: RequestOptions): Promise<ApiResponse<VideoInfo>>;
|
|
1748
|
+
/**
|
|
1749
|
+
* Register a video from a file already uploaded to scalemule-storage.
|
|
1750
|
+
*
|
|
1751
|
+
* The synchronous handshake for storage-uploaded videos. Verifies the
|
|
1752
|
+
* caller's app owns the storage `file_id` and reads scan status:
|
|
1753
|
+
* - clean → 201, video record created with status='uploading',
|
|
1754
|
+
* transcode worker advances on `scan.file.completed`
|
|
1755
|
+
* - pending → 202, video record created with status='pending_scan',
|
|
1756
|
+
* worker advances when scan completes
|
|
1757
|
+
* - threat → 409 (rejected; row not created)
|
|
1758
|
+
*
|
|
1759
|
+
* Idempotent: calling twice with the same file_id returns the existing
|
|
1760
|
+
* row's data (the underlying INSERT uses ON DUPLICATE KEY UPDATE).
|
|
1761
|
+
*
|
|
1762
|
+
* For storage-backed videos `video_id == file_id` — the response's
|
|
1763
|
+
* `video_id` and `file_id` are identical, and either can be used with
|
|
1764
|
+
* `getStreamUrl()` / `get()`.
|
|
1765
|
+
*
|
|
1766
|
+
* Most callers should use {@link uploadViaStorage} which composes
|
|
1767
|
+
* `storage.uploadPrivate()` + `register()` in a single call.
|
|
1768
|
+
*/
|
|
1769
|
+
register(request: RegisterVideoRequest, options?: RequestOptions): Promise<ApiResponse<RegisterVideoResponse>>;
|
|
1770
|
+
/**
|
|
1771
|
+
* Upload a video to storage (browser → S3 direct, private, no
|
|
1772
|
+
* compression) and register it with the video service so transcoding
|
|
1773
|
+
* + HLS streaming work.
|
|
1774
|
+
*
|
|
1775
|
+
* The canonical chat-attachment / progressive-video upload primitive.
|
|
1776
|
+
* Same private-direct-to-S3 path as `storage.uploadPrivate()`, plus a
|
|
1777
|
+
* follow-up `video.register()` call so HLS playback URLs become live
|
|
1778
|
+
* once the transcoder finishes.
|
|
1779
|
+
*
|
|
1780
|
+
* The returned `hls_url_promise` resolves once the video's status
|
|
1781
|
+
* flips to `ready` (or after a 30s timeout — caller can still serve
|
|
1782
|
+
* `original_view_url` as the fallback). Phase 3 of the realtime-chat
|
|
1783
|
+
* media pipeline ADR replaces the poll with a realtime subscription.
|
|
1784
|
+
*
|
|
1785
|
+
* If `register()` fails after a successful storage upload, the file
|
|
1786
|
+
* is *not* lost: the returned `file_id` is still valid as a generic
|
|
1787
|
+
* storage file. SDK logs a warning and resolves `hls_url_promise`
|
|
1788
|
+
* to `null`.
|
|
1789
|
+
*/
|
|
1790
|
+
uploadViaStorage(file: File | Blob, uploadOptions?: {
|
|
1791
|
+
userId?: string;
|
|
1792
|
+
filename?: string;
|
|
1793
|
+
metadata?: Record<string, unknown>;
|
|
1794
|
+
onProgress?: (progress: number) => void;
|
|
1795
|
+
signal?: AbortSignal;
|
|
1796
|
+
}, requestOptions?: RequestOptions): Promise<ApiResponse<VideoUploadViaStorageResult>>;
|
|
1797
|
+
/**
|
|
1798
|
+
* Poll {@link get} until the video's status is `ready` or the 30s
|
|
1799
|
+
* timeout fires. Resolves to the HLS master playlist URL on success;
|
|
1800
|
+
* `null` on timeout (caller should fall back to `original_view_url`).
|
|
1801
|
+
*/
|
|
1802
|
+
private pollTranscodeComplete;
|
|
1709
1803
|
/**
|
|
1710
1804
|
* Get the HLS master playlist URL for streaming.
|
|
1711
1805
|
* Returns the playlist URL that can be passed to a video player.
|
package/dist/index.js
CHANGED
|
@@ -4065,8 +4065,13 @@ var RealtimeService = class extends ServiceModule {
|
|
|
4065
4065
|
var DEFAULT_CHUNK_SIZE = 5 * 1024 * 1024;
|
|
4066
4066
|
var MIN_CHUNK_SIZE = 5 * 1024 * 1024;
|
|
4067
4067
|
var VideoService = class extends ServiceModule {
|
|
4068
|
-
|
|
4069
|
-
|
|
4068
|
+
/**
|
|
4069
|
+
* @param storage Required for {@link uploadViaStorage}. Wired up by the
|
|
4070
|
+
* top-level {@link ScaleMule} constructor.
|
|
4071
|
+
*/
|
|
4072
|
+
constructor(client, storage) {
|
|
4073
|
+
super(client);
|
|
4074
|
+
this.storage = storage;
|
|
4070
4075
|
this.basePath = "/v1/videos";
|
|
4071
4076
|
}
|
|
4072
4077
|
// --------------------------------------------------------------------------
|
|
@@ -4140,6 +4145,115 @@ var VideoService = class extends ServiceModule {
|
|
|
4140
4145
|
async get(videoId, options) {
|
|
4141
4146
|
return super._get(`/${videoId}`, options);
|
|
4142
4147
|
}
|
|
4148
|
+
/**
|
|
4149
|
+
* Register a video from a file already uploaded to scalemule-storage.
|
|
4150
|
+
*
|
|
4151
|
+
* The synchronous handshake for storage-uploaded videos. Verifies the
|
|
4152
|
+
* caller's app owns the storage `file_id` and reads scan status:
|
|
4153
|
+
* - clean → 201, video record created with status='uploading',
|
|
4154
|
+
* transcode worker advances on `scan.file.completed`
|
|
4155
|
+
* - pending → 202, video record created with status='pending_scan',
|
|
4156
|
+
* worker advances when scan completes
|
|
4157
|
+
* - threat → 409 (rejected; row not created)
|
|
4158
|
+
*
|
|
4159
|
+
* Idempotent: calling twice with the same file_id returns the existing
|
|
4160
|
+
* row's data (the underlying INSERT uses ON DUPLICATE KEY UPDATE).
|
|
4161
|
+
*
|
|
4162
|
+
* For storage-backed videos `video_id == file_id` — the response's
|
|
4163
|
+
* `video_id` and `file_id` are identical, and either can be used with
|
|
4164
|
+
* `getStreamUrl()` / `get()`.
|
|
4165
|
+
*
|
|
4166
|
+
* Most callers should use {@link uploadViaStorage} which composes
|
|
4167
|
+
* `storage.uploadPrivate()` + `register()` in a single call.
|
|
4168
|
+
*/
|
|
4169
|
+
async register(request, options) {
|
|
4170
|
+
return this.post(
|
|
4171
|
+
"/register",
|
|
4172
|
+
{
|
|
4173
|
+
file_id: request.fileId,
|
|
4174
|
+
sm_user_id: request.userId
|
|
4175
|
+
},
|
|
4176
|
+
options
|
|
4177
|
+
);
|
|
4178
|
+
}
|
|
4179
|
+
/**
|
|
4180
|
+
* Upload a video to storage (browser → S3 direct, private, no
|
|
4181
|
+
* compression) and register it with the video service so transcoding
|
|
4182
|
+
* + HLS streaming work.
|
|
4183
|
+
*
|
|
4184
|
+
* The canonical chat-attachment / progressive-video upload primitive.
|
|
4185
|
+
* Same private-direct-to-S3 path as `storage.uploadPrivate()`, plus a
|
|
4186
|
+
* follow-up `video.register()` call so HLS playback URLs become live
|
|
4187
|
+
* once the transcoder finishes.
|
|
4188
|
+
*
|
|
4189
|
+
* The returned `hls_url_promise` resolves once the video's status
|
|
4190
|
+
* flips to `ready` (or after a 30s timeout — caller can still serve
|
|
4191
|
+
* `original_view_url` as the fallback). Phase 3 of the realtime-chat
|
|
4192
|
+
* media pipeline ADR replaces the poll with a realtime subscription.
|
|
4193
|
+
*
|
|
4194
|
+
* If `register()` fails after a successful storage upload, the file
|
|
4195
|
+
* is *not* lost: the returned `file_id` is still valid as a generic
|
|
4196
|
+
* storage file. SDK logs a warning and resolves `hls_url_promise`
|
|
4197
|
+
* to `null`.
|
|
4198
|
+
*/
|
|
4199
|
+
async uploadViaStorage(file, uploadOptions, requestOptions) {
|
|
4200
|
+
const uploadResult = await this.storage.uploadPrivate(file, {
|
|
4201
|
+
filename: uploadOptions?.filename,
|
|
4202
|
+
metadata: uploadOptions?.metadata,
|
|
4203
|
+
onProgress: uploadOptions?.onProgress,
|
|
4204
|
+
signal: uploadOptions?.signal
|
|
4205
|
+
});
|
|
4206
|
+
if (uploadResult.error || !uploadResult.data) {
|
|
4207
|
+
return { data: null, error: uploadResult.error };
|
|
4208
|
+
}
|
|
4209
|
+
const fileInfo = uploadResult.data;
|
|
4210
|
+
const fileId = fileInfo.id;
|
|
4211
|
+
const originalViewUrl = fileInfo.url ?? null;
|
|
4212
|
+
const registerResult = await this.register({ fileId, userId: uploadOptions?.userId }, requestOptions);
|
|
4213
|
+
if (registerResult.error || !registerResult.data) {
|
|
4214
|
+
console.warn(
|
|
4215
|
+
"[scalemule-sdk] video.register() failed after storage upload; HLS variants unavailable.",
|
|
4216
|
+
registerResult.error
|
|
4217
|
+
);
|
|
4218
|
+
return {
|
|
4219
|
+
data: {
|
|
4220
|
+
file_id: fileId,
|
|
4221
|
+
video_id: fileId,
|
|
4222
|
+
original_view_url: originalViewUrl,
|
|
4223
|
+
hls_url_promise: Promise.resolve(null)
|
|
4224
|
+
},
|
|
4225
|
+
error: null
|
|
4226
|
+
};
|
|
4227
|
+
}
|
|
4228
|
+
const videoId = registerResult.data.video_id;
|
|
4229
|
+
const hlsUrlPromise = this.pollTranscodeComplete(videoId, requestOptions);
|
|
4230
|
+
return {
|
|
4231
|
+
data: {
|
|
4232
|
+
file_id: fileId,
|
|
4233
|
+
video_id: videoId,
|
|
4234
|
+
original_view_url: originalViewUrl,
|
|
4235
|
+
hls_url_promise: hlsUrlPromise
|
|
4236
|
+
},
|
|
4237
|
+
error: null
|
|
4238
|
+
};
|
|
4239
|
+
}
|
|
4240
|
+
/**
|
|
4241
|
+
* Poll {@link get} until the video's status is `ready` or the 30s
|
|
4242
|
+
* timeout fires. Resolves to the HLS master playlist URL on success;
|
|
4243
|
+
* `null` on timeout (caller should fall back to `original_view_url`).
|
|
4244
|
+
*/
|
|
4245
|
+
async pollTranscodeComplete(videoId, requestOptions) {
|
|
4246
|
+
const intervalMs = 1e3;
|
|
4247
|
+
const maxAttempts = 30;
|
|
4248
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
4249
|
+
const result = await this.get(videoId, requestOptions);
|
|
4250
|
+
if (result.data?.status === "ready") {
|
|
4251
|
+
return `${this.client.getBaseUrl()}${this.basePath}/${videoId}/playlist.m3u8`;
|
|
4252
|
+
}
|
|
4253
|
+
await new Promise((r) => setTimeout(r, intervalMs));
|
|
4254
|
+
}
|
|
4255
|
+
return null;
|
|
4256
|
+
}
|
|
4143
4257
|
/**
|
|
4144
4258
|
* Get the HLS master playlist URL for streaming.
|
|
4145
4259
|
* Returns the playlist URL that can be passed to a video player.
|
|
@@ -7140,7 +7254,7 @@ var ScaleMule = class {
|
|
|
7140
7254
|
this.auth = new AuthService(this._client);
|
|
7141
7255
|
this.storage = new StorageService(this._client);
|
|
7142
7256
|
this.realtime = new RealtimeService(this._client);
|
|
7143
|
-
this.video = new VideoService(this._client);
|
|
7257
|
+
this.video = new VideoService(this._client, this.storage);
|
|
7144
7258
|
this.data = new DataService(this._client);
|
|
7145
7259
|
this.chat = new ChatService(this._client);
|
|
7146
7260
|
this.conference = new ConferenceService(this._client);
|
package/dist/index.mjs
CHANGED
|
@@ -3693,8 +3693,13 @@ var RealtimeService = class extends ServiceModule {
|
|
|
3693
3693
|
var DEFAULT_CHUNK_SIZE = 5 * 1024 * 1024;
|
|
3694
3694
|
var MIN_CHUNK_SIZE = 5 * 1024 * 1024;
|
|
3695
3695
|
var VideoService = class extends ServiceModule {
|
|
3696
|
-
|
|
3697
|
-
|
|
3696
|
+
/**
|
|
3697
|
+
* @param storage Required for {@link uploadViaStorage}. Wired up by the
|
|
3698
|
+
* top-level {@link ScaleMule} constructor.
|
|
3699
|
+
*/
|
|
3700
|
+
constructor(client, storage) {
|
|
3701
|
+
super(client);
|
|
3702
|
+
this.storage = storage;
|
|
3698
3703
|
this.basePath = "/v1/videos";
|
|
3699
3704
|
}
|
|
3700
3705
|
// --------------------------------------------------------------------------
|
|
@@ -3768,6 +3773,115 @@ var VideoService = class extends ServiceModule {
|
|
|
3768
3773
|
async get(videoId, options) {
|
|
3769
3774
|
return super._get(`/${videoId}`, options);
|
|
3770
3775
|
}
|
|
3776
|
+
/**
|
|
3777
|
+
* Register a video from a file already uploaded to scalemule-storage.
|
|
3778
|
+
*
|
|
3779
|
+
* The synchronous handshake for storage-uploaded videos. Verifies the
|
|
3780
|
+
* caller's app owns the storage `file_id` and reads scan status:
|
|
3781
|
+
* - clean → 201, video record created with status='uploading',
|
|
3782
|
+
* transcode worker advances on `scan.file.completed`
|
|
3783
|
+
* - pending → 202, video record created with status='pending_scan',
|
|
3784
|
+
* worker advances when scan completes
|
|
3785
|
+
* - threat → 409 (rejected; row not created)
|
|
3786
|
+
*
|
|
3787
|
+
* Idempotent: calling twice with the same file_id returns the existing
|
|
3788
|
+
* row's data (the underlying INSERT uses ON DUPLICATE KEY UPDATE).
|
|
3789
|
+
*
|
|
3790
|
+
* For storage-backed videos `video_id == file_id` — the response's
|
|
3791
|
+
* `video_id` and `file_id` are identical, and either can be used with
|
|
3792
|
+
* `getStreamUrl()` / `get()`.
|
|
3793
|
+
*
|
|
3794
|
+
* Most callers should use {@link uploadViaStorage} which composes
|
|
3795
|
+
* `storage.uploadPrivate()` + `register()` in a single call.
|
|
3796
|
+
*/
|
|
3797
|
+
async register(request, options) {
|
|
3798
|
+
return this.post(
|
|
3799
|
+
"/register",
|
|
3800
|
+
{
|
|
3801
|
+
file_id: request.fileId,
|
|
3802
|
+
sm_user_id: request.userId
|
|
3803
|
+
},
|
|
3804
|
+
options
|
|
3805
|
+
);
|
|
3806
|
+
}
|
|
3807
|
+
/**
|
|
3808
|
+
* Upload a video to storage (browser → S3 direct, private, no
|
|
3809
|
+
* compression) and register it with the video service so transcoding
|
|
3810
|
+
* + HLS streaming work.
|
|
3811
|
+
*
|
|
3812
|
+
* The canonical chat-attachment / progressive-video upload primitive.
|
|
3813
|
+
* Same private-direct-to-S3 path as `storage.uploadPrivate()`, plus a
|
|
3814
|
+
* follow-up `video.register()` call so HLS playback URLs become live
|
|
3815
|
+
* once the transcoder finishes.
|
|
3816
|
+
*
|
|
3817
|
+
* The returned `hls_url_promise` resolves once the video's status
|
|
3818
|
+
* flips to `ready` (or after a 30s timeout — caller can still serve
|
|
3819
|
+
* `original_view_url` as the fallback). Phase 3 of the realtime-chat
|
|
3820
|
+
* media pipeline ADR replaces the poll with a realtime subscription.
|
|
3821
|
+
*
|
|
3822
|
+
* If `register()` fails after a successful storage upload, the file
|
|
3823
|
+
* is *not* lost: the returned `file_id` is still valid as a generic
|
|
3824
|
+
* storage file. SDK logs a warning and resolves `hls_url_promise`
|
|
3825
|
+
* to `null`.
|
|
3826
|
+
*/
|
|
3827
|
+
async uploadViaStorage(file, uploadOptions, requestOptions) {
|
|
3828
|
+
const uploadResult = await this.storage.uploadPrivate(file, {
|
|
3829
|
+
filename: uploadOptions?.filename,
|
|
3830
|
+
metadata: uploadOptions?.metadata,
|
|
3831
|
+
onProgress: uploadOptions?.onProgress,
|
|
3832
|
+
signal: uploadOptions?.signal
|
|
3833
|
+
});
|
|
3834
|
+
if (uploadResult.error || !uploadResult.data) {
|
|
3835
|
+
return { data: null, error: uploadResult.error };
|
|
3836
|
+
}
|
|
3837
|
+
const fileInfo = uploadResult.data;
|
|
3838
|
+
const fileId = fileInfo.id;
|
|
3839
|
+
const originalViewUrl = fileInfo.url ?? null;
|
|
3840
|
+
const registerResult = await this.register({ fileId, userId: uploadOptions?.userId }, requestOptions);
|
|
3841
|
+
if (registerResult.error || !registerResult.data) {
|
|
3842
|
+
console.warn(
|
|
3843
|
+
"[scalemule-sdk] video.register() failed after storage upload; HLS variants unavailable.",
|
|
3844
|
+
registerResult.error
|
|
3845
|
+
);
|
|
3846
|
+
return {
|
|
3847
|
+
data: {
|
|
3848
|
+
file_id: fileId,
|
|
3849
|
+
video_id: fileId,
|
|
3850
|
+
original_view_url: originalViewUrl,
|
|
3851
|
+
hls_url_promise: Promise.resolve(null)
|
|
3852
|
+
},
|
|
3853
|
+
error: null
|
|
3854
|
+
};
|
|
3855
|
+
}
|
|
3856
|
+
const videoId = registerResult.data.video_id;
|
|
3857
|
+
const hlsUrlPromise = this.pollTranscodeComplete(videoId, requestOptions);
|
|
3858
|
+
return {
|
|
3859
|
+
data: {
|
|
3860
|
+
file_id: fileId,
|
|
3861
|
+
video_id: videoId,
|
|
3862
|
+
original_view_url: originalViewUrl,
|
|
3863
|
+
hls_url_promise: hlsUrlPromise
|
|
3864
|
+
},
|
|
3865
|
+
error: null
|
|
3866
|
+
};
|
|
3867
|
+
}
|
|
3868
|
+
/**
|
|
3869
|
+
* Poll {@link get} until the video's status is `ready` or the 30s
|
|
3870
|
+
* timeout fires. Resolves to the HLS master playlist URL on success;
|
|
3871
|
+
* `null` on timeout (caller should fall back to `original_view_url`).
|
|
3872
|
+
*/
|
|
3873
|
+
async pollTranscodeComplete(videoId, requestOptions) {
|
|
3874
|
+
const intervalMs = 1e3;
|
|
3875
|
+
const maxAttempts = 30;
|
|
3876
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
3877
|
+
const result = await this.get(videoId, requestOptions);
|
|
3878
|
+
if (result.data?.status === "ready") {
|
|
3879
|
+
return `${this.client.getBaseUrl()}${this.basePath}/${videoId}/playlist.m3u8`;
|
|
3880
|
+
}
|
|
3881
|
+
await new Promise((r) => setTimeout(r, intervalMs));
|
|
3882
|
+
}
|
|
3883
|
+
return null;
|
|
3884
|
+
}
|
|
3771
3885
|
/**
|
|
3772
3886
|
* Get the HLS master playlist URL for streaming.
|
|
3773
3887
|
* Returns the playlist URL that can be passed to a video player.
|
|
@@ -6768,7 +6882,7 @@ var ScaleMule = class {
|
|
|
6768
6882
|
this.auth = new AuthService(this._client);
|
|
6769
6883
|
this.storage = new StorageService(this._client);
|
|
6770
6884
|
this.realtime = new RealtimeService(this._client);
|
|
6771
|
-
this.video = new VideoService(this._client);
|
|
6885
|
+
this.video = new VideoService(this._client, this.storage);
|
|
6772
6886
|
this.data = new DataService(this._client);
|
|
6773
6887
|
this.chat = new ChatService(this._client);
|
|
6774
6888
|
this.conference = new ConferenceService(this._client);
|