@stream-io/video-filters-web 0.2.0 → 0.2.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.
- package/CHANGELOG.md +12 -0
- package/dist/index.cjs.js +16 -6
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +16 -6
- package/dist/index.es.js.map +1 -1
- package/dist/src/compatibility.d.ts +12 -1
- package/package.json +2 -1
- package/src/compatibility.ts +27 -2
- package/src/createRenderer.ts +6 -3
package/dist/index.es.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { simd } from 'wasm-feature-detect';
|
|
2
|
+
import { WorkerTimer } from '@stream-io/worker-timer';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Checks if the current platform is a mobile device.
|
|
@@ -7,14 +8,21 @@ import { simd } from 'wasm-feature-detect';
|
|
|
7
8
|
* https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent
|
|
8
9
|
*/
|
|
9
10
|
const isMobile = () => /Mobi/i.test(navigator.userAgent);
|
|
11
|
+
/**
|
|
12
|
+
* Checks whether the current browser is Safari.
|
|
13
|
+
*/
|
|
14
|
+
const isSafari = () => /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
|
10
15
|
/**
|
|
11
16
|
* Runs a check to see if the current platform supports
|
|
12
17
|
* the necessary APIs required for the video filters.
|
|
13
18
|
*/
|
|
14
|
-
const isPlatformSupported = async () => typeof document !== 'undefined' &&
|
|
19
|
+
const isPlatformSupported = async ({ forceMobileSupport = false, forceSafariSupport = false, } = {}) => typeof document !== 'undefined' &&
|
|
15
20
|
typeof window !== 'undefined' &&
|
|
16
21
|
typeof navigator !== 'undefined' &&
|
|
17
|
-
|
|
22
|
+
// we don't support mobile devices yet due to performance issues
|
|
23
|
+
(forceMobileSupport || !isMobile()) &&
|
|
24
|
+
// Safari has issues with timer throttling, causing low FPS when the tab goes to the background
|
|
25
|
+
(forceSafariSupport || !isSafari()) &&
|
|
18
26
|
typeof WebAssembly !== 'undefined' &&
|
|
19
27
|
!!window.WebGL2RenderingContext && // WebGL2 is required for the video filters
|
|
20
28
|
!!document.createElement('canvas').getContext('webgl2') &&
|
|
@@ -786,7 +794,8 @@ function createRenderer(tflite, videoSource, targetCanvas, options, onError) {
|
|
|
786
794
|
throw new Error(`backgroundImage element is required when backgroundFilter is image`);
|
|
787
795
|
}
|
|
788
796
|
const pipeline = buildWebGL2Pipeline(videoSource, backgroundImage, backgroundBlurLevel, backgroundFilter, targetCanvas, tflite, getSegmentationParams(segmentationLevel));
|
|
789
|
-
const
|
|
797
|
+
const timers = new WorkerTimer({ useWorker: true });
|
|
798
|
+
const id = timers.setInterval(() => {
|
|
790
799
|
try {
|
|
791
800
|
pipeline.render();
|
|
792
801
|
if (backgroundFilter === 'image') {
|
|
@@ -796,11 +805,12 @@ function createRenderer(tflite, videoSource, targetCanvas, options, onError) {
|
|
|
796
805
|
catch (error) {
|
|
797
806
|
onError?.(error);
|
|
798
807
|
}
|
|
799
|
-
}, 1000 / (fps <= 0 ? 30 : fps));
|
|
808
|
+
}, Math.floor(1000 / (fps <= 0 ? 30 : fps)));
|
|
800
809
|
return {
|
|
801
810
|
dispose: () => {
|
|
802
811
|
pipeline.cleanUp();
|
|
803
|
-
clearInterval(id);
|
|
812
|
+
timers.clearInterval(id);
|
|
813
|
+
timers.destroy();
|
|
804
814
|
},
|
|
805
815
|
};
|
|
806
816
|
}
|
|
@@ -1531,7 +1541,7 @@ const createTFLiteSIMDModule = (__Module) => {
|
|
|
1531
1541
|
return __Module.ready;
|
|
1532
1542
|
};
|
|
1533
1543
|
|
|
1534
|
-
const version = "0.2.
|
|
1544
|
+
const version = "0.2.2";
|
|
1535
1545
|
const packageName = "@stream-io/video-filters-web";
|
|
1536
1546
|
|
|
1537
1547
|
// @ts-expect-error - module is not declared
|