@stream-io/video-react-sdk 0.6.14 → 0.6.16
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 +13 -0
- package/dist/index.cjs.js +26 -15
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +27 -16
- package/dist/index.es.js.map +1 -1
- package/package.json +3 -3
- package/src/components/BackgroundFilters/BackgroundFilters.tsx +35 -24
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stream-io/video-react-sdk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.16",
|
|
4
4
|
"packageManager": "yarn@3.2.4",
|
|
5
5
|
"main": "./dist/index.cjs.js",
|
|
6
6
|
"module": "./dist/index.es.js",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@floating-ui/react": "^0.26.5",
|
|
32
|
-
"@stream-io/video-client": "0.7.
|
|
32
|
+
"@stream-io/video-client": "0.7.10",
|
|
33
33
|
"@stream-io/video-filters-web": "0.1.0",
|
|
34
|
-
"@stream-io/video-react-bindings": "0.4.
|
|
34
|
+
"@stream-io/video-react-bindings": "0.4.21",
|
|
35
35
|
"chart.js": "^4.4.1",
|
|
36
36
|
"clsx": "^2.0.0",
|
|
37
37
|
"react-chartjs-2": "^5.2.0"
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from 'react';
|
|
10
10
|
import clsx from 'clsx';
|
|
11
11
|
import { useCall } from '@stream-io/video-react-bindings';
|
|
12
|
+
import { disposeOfMediaStream } from '@stream-io/video-client';
|
|
12
13
|
import {
|
|
13
14
|
BackgroundBlurLevel,
|
|
14
15
|
BackgroundFilter,
|
|
@@ -232,8 +233,8 @@ const BackgroundFilters = (props: { tfLite: TFLite }) => {
|
|
|
232
233
|
const register = (unregister.current || Promise.resolve()).then(() =>
|
|
233
234
|
call.camera.registerFilter(async (ms) => {
|
|
234
235
|
return new Promise<MediaStream>((resolve) => {
|
|
235
|
-
setMediaStream(ms);
|
|
236
236
|
signalFilterReadyRef.current = resolve;
|
|
237
|
+
setMediaStream(ms);
|
|
237
238
|
});
|
|
238
239
|
}),
|
|
239
240
|
);
|
|
@@ -241,36 +242,45 @@ const BackgroundFilters = (props: { tfLite: TFLite }) => {
|
|
|
241
242
|
return () => {
|
|
242
243
|
unregister.current = register
|
|
243
244
|
.then((unregisterFilter) => unregisterFilter())
|
|
245
|
+
.then(() => (signalFilterReadyRef.current = undefined))
|
|
244
246
|
.then(() => setMediaStream(undefined))
|
|
245
247
|
.catch((err) => console.error('Failed to unregister filter', err));
|
|
246
248
|
};
|
|
247
249
|
}, [backgroundFilter, call]);
|
|
248
250
|
|
|
251
|
+
const [isPlaying, setIsPlaying] = useState(false);
|
|
249
252
|
useEffect(() => {
|
|
250
|
-
if (!mediaStream || !videoRef
|
|
251
|
-
|
|
253
|
+
if (!mediaStream || !videoRef) return;
|
|
252
254
|
const handleOnPlay = () => {
|
|
253
255
|
const [track] = mediaStream.getVideoTracks();
|
|
254
|
-
if (track)
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
const resolveFilter = signalFilterReadyRef.current;
|
|
261
|
-
if (!resolveFilter) return;
|
|
262
|
-
const filter = canvasRef.captureStream();
|
|
263
|
-
resolveFilter(filter);
|
|
256
|
+
if (!track) return;
|
|
257
|
+
const { width: w = 0, height: h = 0 } = track.getSettings();
|
|
258
|
+
setWidth(w);
|
|
259
|
+
setHeight(h);
|
|
260
|
+
setIsPlaying(true);
|
|
264
261
|
};
|
|
265
262
|
videoRef.addEventListener('play', handleOnPlay);
|
|
266
|
-
|
|
267
263
|
videoRef.srcObject = mediaStream;
|
|
268
|
-
videoRef.play().catch((err) =>
|
|
264
|
+
videoRef.play().catch((err) => {
|
|
265
|
+
console.error('Failed to play video', err);
|
|
266
|
+
});
|
|
269
267
|
return () => {
|
|
270
268
|
videoRef.removeEventListener('play', handleOnPlay);
|
|
271
269
|
videoRef.srcObject = null;
|
|
270
|
+
setIsPlaying(false);
|
|
272
271
|
};
|
|
273
|
-
}, [
|
|
272
|
+
}, [mediaStream, videoRef]);
|
|
273
|
+
|
|
274
|
+
useEffect(() => {
|
|
275
|
+
const resolveFilter = signalFilterReadyRef.current;
|
|
276
|
+
if (!canvasRef || !resolveFilter) return;
|
|
277
|
+
|
|
278
|
+
const filter = canvasRef.captureStream();
|
|
279
|
+
resolveFilter(filter);
|
|
280
|
+
return () => {
|
|
281
|
+
disposeOfMediaStream(filter);
|
|
282
|
+
};
|
|
283
|
+
}, [canvasRef]);
|
|
274
284
|
|
|
275
285
|
return (
|
|
276
286
|
<div
|
|
@@ -280,7 +290,7 @@ const BackgroundFilters = (props: { tfLite: TFLite }) => {
|
|
|
280
290
|
height: `${height}px`,
|
|
281
291
|
}}
|
|
282
292
|
>
|
|
283
|
-
{mediaStream && (
|
|
293
|
+
{mediaStream && isPlaying && (
|
|
284
294
|
<RenderPipeline
|
|
285
295
|
tfLite={tfLite}
|
|
286
296
|
videoRef={videoRef}
|
|
@@ -313,13 +323,14 @@ const BackgroundFilters = (props: { tfLite: TFLite }) => {
|
|
|
313
323
|
height={height}
|
|
314
324
|
/>
|
|
315
325
|
)}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
326
|
+
{isPlaying && (
|
|
327
|
+
<canvas
|
|
328
|
+
className="str-video__background-filters__target-canvas"
|
|
329
|
+
width={width}
|
|
330
|
+
height={height}
|
|
331
|
+
ref={setCanvasRef}
|
|
332
|
+
/>
|
|
333
|
+
)}
|
|
323
334
|
</div>
|
|
324
335
|
);
|
|
325
336
|
};
|