@vidtreo/recorder 1.6.1 → 1.6.2

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +2438 -2429
  2. package/dist/index.js +70 -37
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1695,6 +1695,36 @@ async function resolveAudioCodecFromPolicy(options) {
1695
1695
  return options.policy.preferredAudioCodec;
1696
1696
  }
1697
1697
 
1698
+ // src/core/transcode/output-format.ts
1699
+ function getMimeTypeForOutputFormat(format) {
1700
+ switch (format) {
1701
+ case "mp4":
1702
+ return "video/mp4";
1703
+ case "webm":
1704
+ return "video/webm";
1705
+ case "mkv":
1706
+ return "video/x-matroska";
1707
+ case "mov":
1708
+ return "video/quicktime";
1709
+ default:
1710
+ throw new Error(`Unsupported output format: ${format}`);
1711
+ }
1712
+ }
1713
+ function getFileExtensionForOutputFormat(format) {
1714
+ switch (format) {
1715
+ case "mp4":
1716
+ return "mp4";
1717
+ case "webm":
1718
+ return "webm";
1719
+ case "mkv":
1720
+ return "mkv";
1721
+ case "mov":
1722
+ return "mov";
1723
+ default:
1724
+ throw new Error(`Unsupported output format: ${format}`);
1725
+ }
1726
+ }
1727
+
1698
1728
  // src/core/transcode/video-transcoder.ts
1699
1729
  var ALLOW_ROTATION_METADATA = false;
1700
1730
  function createSource(input) {
@@ -1720,20 +1750,6 @@ function createOutputFormat(format) {
1720
1750
  throw new Error(`Unsupported output format: ${format}`);
1721
1751
  }
1722
1752
  }
1723
- function getMimeTypeForFormat(format) {
1724
- switch (format) {
1725
- case "mp4":
1726
- return "video/mp4";
1727
- case "webm":
1728
- return "video/webm";
1729
- case "mkv":
1730
- return "video/x-matroska";
1731
- case "mov":
1732
- return "video/quicktime";
1733
- default:
1734
- throw new Error(`Unsupported output format: ${format}`);
1735
- }
1736
- }
1737
1753
  function createConversionOptions(config, optimizeForSpeed = false) {
1738
1754
  const video = {
1739
1755
  fit: "contain",
@@ -1828,7 +1844,7 @@ async function transcodeVideo(input, config = {}, onProgress) {
1828
1844
  if (!buffer) {
1829
1845
  throw new Error("Transcoding completed but no output buffer was generated");
1830
1846
  }
1831
- const mimeType = getMimeTypeForFormat(finalConfig.format);
1847
+ const mimeType = getMimeTypeForOutputFormat(finalConfig.format);
1832
1848
  return {
1833
1849
  buffer,
1834
1850
  blob: new Blob([buffer], { type: mimeType })
@@ -1899,7 +1915,7 @@ async function transcodeVideoForNativeCamera(file, config = {}, onProgress) {
1899
1915
  if (!buffer) {
1900
1916
  throw new Error("Transcoding completed but no output buffer was generated");
1901
1917
  }
1902
- const mimeType = getMimeTypeForFormat(finalConfig.format);
1918
+ const mimeType = getMimeTypeForOutputFormat(finalConfig.format);
1903
1919
  return {
1904
1920
  buffer,
1905
1921
  blob: new Blob([buffer], { type: mimeType })
@@ -6045,7 +6061,7 @@ function resolveDeviceError(input) {
6045
6061
  // package.json
6046
6062
  var package_default = {
6047
6063
  name: "@vidtreo/recorder",
6048
- version: "1.6.1",
6064
+ version: "1.6.2",
6049
6065
  type: "module",
6050
6066
  description: "Vidtreo SDK for browser-based video recording and transcoding. Features include camera/screen recording, real-time MP4 transcoding, audio level analysis, mute/pause controls, source switching, device selection, and automatic backend uploads. Similar to Ziggeo and Addpipe, Vidtreo provides enterprise-grade video processing capabilities for web applications.",
6051
6067
  main: "./dist/index.js",
@@ -6852,6 +6868,7 @@ class UploadQueueManager {
6852
6868
  apiKey: upload.apiKey,
6853
6869
  backendUrl: upload.backendUrl,
6854
6870
  filename: upload.filename,
6871
+ mimeType: upload.mimeType,
6855
6872
  metadata: upload.metadata,
6856
6873
  userMetadata: upload.userMetadata,
6857
6874
  onProgress: (progress) => {
@@ -6899,6 +6916,7 @@ class UploadQueueManager {
6899
6916
 
6900
6917
  // src/core/upload/upload-service.ts
6901
6918
  var API_UPLOAD_PATH = "/api/v1/videos/upload";
6919
+ var MIME_TYPE_PARAMETER_SEPARATOR = ";";
6902
6920
 
6903
6921
  class VideoUploadService {
6904
6922
  uploadVideo(blob, options) {
@@ -6913,6 +6931,7 @@ class VideoUploadService {
6913
6931
  uploadVideoFile(blob, options) {
6914
6932
  return new Promise((resolve, reject) => {
6915
6933
  const xhr = new XMLHttpRequest;
6934
+ const uploadBlob = this.createUploadBlob(blob, options.mimeType);
6916
6935
  if (options.onProgress) {
6917
6936
  const onProgress = options.onProgress;
6918
6937
  xhr.upload.addEventListener("progress", (event) => {
@@ -6939,10 +6958,10 @@ class VideoUploadService {
6939
6958
  xhr.open("POST", url);
6940
6959
  xhr.setRequestHeader("Authorization", `Bearer ${options.apiKey}`);
6941
6960
  const formData = new FormData;
6942
- formData.append("file", blob, options.filename);
6961
+ formData.append("file", uploadBlob, options.filename);
6943
6962
  const metadata = {
6944
6963
  filename: options.filename,
6945
- mimeType: blob.type
6964
+ mimeType: uploadBlob.type
6946
6965
  };
6947
6966
  if (options.userMetadata) {
6948
6967
  metadata.userMetadata = options.userMetadata;
@@ -6951,6 +6970,26 @@ class VideoUploadService {
6951
6970
  xhr.send(formData);
6952
6971
  });
6953
6972
  }
6973
+ createUploadBlob(blob, mimeType) {
6974
+ const normalizedMimeType = this.resolveUploadMimeType(blob, mimeType);
6975
+ if (normalizedMimeType === blob.type) {
6976
+ return blob;
6977
+ }
6978
+ return new Blob([blob], { type: normalizedMimeType });
6979
+ }
6980
+ resolveUploadMimeType(blob, mimeType) {
6981
+ if (mimeType && mimeType.trim().length > 0) {
6982
+ return this.normalizeMimeType(mimeType);
6983
+ }
6984
+ return this.normalizeMimeType(blob.type);
6985
+ }
6986
+ normalizeMimeType(mimeType) {
6987
+ const [baseMimeType] = mimeType.split(MIME_TYPE_PARAMETER_SEPARATOR);
6988
+ if (baseMimeType === undefined) {
6989
+ return mimeType.trim().toLowerCase();
6990
+ }
6991
+ return baseMimeType.trim().toLowerCase();
6992
+ }
6954
6993
  parseSuccessResponse(xhr, resolve, reject) {
6955
6994
  const parsed = this.safeParseJsonFromXhr(xhr);
6956
6995
  if (!parsed) {
@@ -22276,23 +22315,9 @@ var DEFAULT_ROUTE_DECISION2 = {
22276
22315
  var DEFAULT_RECORDING_MANAGER_DEPENDENCIES = {
22277
22316
  transcodeVideo
22278
22317
  };
22279
- function getExpectedMimeTypePrefix(config) {
22280
- switch (config.format) {
22281
- case "mp4":
22282
- return "video/mp4";
22283
- case "webm":
22284
- return "video/webm";
22285
- case "mkv":
22286
- return "video/x-matroska";
22287
- case "mov":
22288
- return "video/quicktime";
22289
- default:
22290
- return null;
22291
- }
22292
- }
22293
22318
  function isBlobAlreadyInTargetFormat(blob, config) {
22294
- const expectedMimeTypePrefix = getExpectedMimeTypePrefix(config);
22295
- return expectedMimeTypePrefix !== null && blob.type.toLowerCase().startsWith(expectedMimeTypePrefix);
22319
+ const expectedMimeTypePrefix = getMimeTypeForOutputFormat(config.format);
22320
+ return blob.type.toLowerCase().startsWith(expectedMimeTypePrefix);
22296
22321
  }
22297
22322
 
22298
22323
  class RecordingManager {
@@ -23102,7 +23127,9 @@ class RecorderController {
23102
23127
  async uploadVideo(blob, apiKey, backendUrl, metadata) {
23103
23128
  this.uploadCallbacks.onClearStatus();
23104
23129
  const duration = await extractVideoDuration(blob);
23105
- const filename = `recording-${Date.now()}.mp4`;
23130
+ const outputFormat = this.configManager.getConfigForRecording().format;
23131
+ const filename = `recording-${Date.now()}.${getFileExtensionForOutputFormat(outputFormat)}`;
23132
+ const mimeType = getMimeTypeForOutputFormat(outputFormat);
23106
23133
  const sourceType = this.getCurrentSourceType();
23107
23134
  let userMetadata;
23108
23135
  if (Object.keys(metadata).length > 0) {
@@ -23119,6 +23146,7 @@ class RecorderController {
23119
23146
  apiKey,
23120
23147
  backendUrl,
23121
23148
  filename,
23149
+ mimeType,
23122
23150
  duration,
23123
23151
  sourceType,
23124
23152
  userMetadata
@@ -23130,6 +23158,7 @@ class RecorderController {
23130
23158
  apiKey,
23131
23159
  backendUrl,
23132
23160
  filename,
23161
+ mimeType,
23133
23162
  duration,
23134
23163
  metadata: undefined,
23135
23164
  userMetadata
@@ -23156,6 +23185,7 @@ class RecorderController {
23156
23185
  apiKey: options.apiKey,
23157
23186
  backendUrl: options.backendUrl,
23158
23187
  filename: options.filename,
23188
+ mimeType: options.mimeType,
23159
23189
  metadata: undefined,
23160
23190
  userMetadata: options.userMetadata,
23161
23191
  onProgress: this.uploadCallbacks.onProgress
@@ -23854,8 +23884,10 @@ class VidtreoRecorder {
23854
23884
  async stopRecording() {
23855
23885
  await this.ensureInitialized();
23856
23886
  const blob = await this.controller.stopRecording();
23887
+ const outputFormat = (await this.controller.getConfig()).format;
23857
23888
  const timestamp = Date.now();
23858
- const filename = `recording-${timestamp}.mp4`;
23889
+ const filename = `recording-${timestamp}.${getFileExtensionForOutputFormat(outputFormat)}`;
23890
+ const mimeType = getMimeTypeForOutputFormat(outputFormat);
23859
23891
  const uploadService = this.controller.getUploadService();
23860
23892
  if (!uploadService) {
23861
23893
  throw new Error("Upload service not available");
@@ -23864,6 +23896,7 @@ class VidtreoRecorder {
23864
23896
  apiKey: this.config.apiKey,
23865
23897
  backendUrl: this.config.apiUrl,
23866
23898
  filename,
23899
+ mimeType,
23867
23900
  userMetadata: this.config.userMetadata,
23868
23901
  onProgress: this.config.onUploadProgress
23869
23902
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vidtreo/recorder",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "type": "module",
5
5
  "description": "Vidtreo SDK for browser-based video recording and transcoding. Features include camera/screen recording, real-time MP4 transcoding, audio level analysis, mute/pause controls, source switching, device selection, and automatic backend uploads. Similar to Ziggeo and Addpipe, Vidtreo provides enterprise-grade video processing capabilities for web applications.",
6
6
  "main": "./dist/index.js",