@stream-io/video-filters-web 0.1.2 → 0.1.4

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.es.js CHANGED
@@ -673,6 +673,8 @@ function buildWebGL2Pipeline(videoSource, backgroundImage, blurLevel, background
673
673
  const gl = canvas.getContext('webgl2');
674
674
  if (!gl)
675
675
  throw new Error('WebGL2 is not supported');
676
+ if (gl.isContextLost())
677
+ throw new Error('WebGL2 context was lost');
676
678
  const { width: frameWidth, height: frameHeight } = videoSource;
677
679
  const { width: segmentationWidth, height: segmentationHeight } = segmentationConfig;
678
680
  const vertexShaderSource = glsl `#version 300 es
@@ -775,16 +777,21 @@ const getSegmentationParams = (level) => {
775
777
  return { width: 160, height: 96 };
776
778
  };
777
779
 
778
- function createRenderer(tflite, videoSource, targetCanvas, options) {
780
+ function createRenderer(tflite, videoSource, targetCanvas, options, onError) {
779
781
  const { backgroundFilter, backgroundImage, backgroundBlurLevel, segmentationLevel = SegmentationLevel.HIGH, fps = 30, } = options;
780
782
  if (backgroundFilter === 'image' && !backgroundImage) {
781
783
  throw new Error(`backgroundImage element is required when backgroundFilter is image`);
782
784
  }
783
785
  const pipeline = buildWebGL2Pipeline(videoSource, backgroundImage, backgroundBlurLevel, backgroundFilter, targetCanvas, tflite, getSegmentationParams(segmentationLevel));
784
786
  const id = setInterval(() => {
785
- pipeline.render();
786
- if (backgroundFilter === 'image') {
787
- pipeline.updatePostProcessingConfig();
787
+ try {
788
+ pipeline.render();
789
+ if (backgroundFilter === 'image') {
790
+ pipeline.updatePostProcessingConfig();
791
+ }
792
+ }
793
+ catch (error) {
794
+ onError?.(error);
788
795
  }
789
796
  }, 1000 / (fps <= 0 ? 30 : fps));
790
797
  return {
@@ -1022,7 +1029,7 @@ const createTFLiteSIMDModule = (__Module) => {
1022
1029
  }
1023
1030
 
1024
1031
  function getBinaryPromise() {
1025
- if (!wasmBinary && (ENVIRONMENT_IS_WEB )) {
1032
+ if (!wasmBinary && (ENVIRONMENT_IS_WEB)) {
1026
1033
  if (typeof fetch == 'function') {
1027
1034
  return fetch(wasmBinaryFile, { credentials: 'same-origin' })
1028
1035
  .then(function (response) {
@@ -1250,7 +1257,7 @@ const createTFLiteSIMDModule = (__Module) => {
1250
1257
  for (var i = 0; i < str.length; ++i) {
1251
1258
  HEAP8[buffer++ >> 0] = str.charCodeAt(i);
1252
1259
  }
1253
- if (!dontAddNull) HEAP8[buffer >> 0] = 0;
1260
+ HEAP8[buffer >> 0] = 0;
1254
1261
  }
1255
1262
 
1256
1263
  function _environ_get(__environ, environ_buf) {
@@ -1529,8 +1536,8 @@ const createTFLiteSIMDModule = (__Module) => {
1529
1536
  return __Module.ready;
1530
1537
  };
1531
1538
 
1532
- const version = "0.1.2" ;
1533
- const packageName = "@stream-io/video-filters-web" ;
1539
+ const version = "0.1.4";
1540
+ const packageName = "@stream-io/video-filters-web";
1534
1541
 
1535
1542
  // @ts-expect-error - module is not declared
1536
1543
  // This is a WebAssembly module compiled from the TensorFlow Lite C++ library.