@livekit/track-processors 0.6.0 → 0.7.0

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/README.md CHANGED
@@ -10,15 +10,16 @@ npm add @livekit/track-processors
10
10
 
11
11
  ### Available processors
12
12
 
13
- This package exposes the `BackgroundBlur` and `VirtualBackground` pre-prepared processor pipelines.
13
+ This package exposes the `BackgroundProcessor` pre-prepared processor pipeline, which can be used in a few ways:
14
14
 
15
- - `BackgroundBlur(blurRadius)`
16
- - `VirtualBackground(imagePath)`
15
+ - `BackgroundProcessor({ mode: 'background-blur', blurRadius: 10 /* (optional) */ })`
16
+ - `BackgroundProcessor({ mode: 'virtual-background', imagePath: "http://path.to/image.png" })`
17
+ - `BackgroundProcessor({ mode: 'disabled' })`
17
18
 
18
19
  ### Usage example
19
20
 
20
21
  ```ts
21
- import { BackgroundBlur, supportsBackgroundProcessors, supportsModernBackgroundProcessors } from '@livekit/track-processors';
22
+ import { BackgroundProcessor, supportsBackgroundProcessors, supportsModernBackgroundProcessors } from '@livekit/track-processors';
22
23
 
23
24
  if(!supportsBackgroundProcessors()) {
24
25
  throw new Error("this browser does not support background processors")
@@ -29,19 +30,40 @@ if(supportsModernBackgroundProcessors()) {
29
30
  }
30
31
 
31
32
  const videoTrack = await createLocalVideoTrack();
32
- const blur = BackgroundBlur(10);
33
- await videoTrack.setProcessor(blur);
33
+ const processor = BackgroundProcessor({ mode: 'background-blur' });
34
+ await videoTrack.setProcessor(processor);
34
35
  room.localParticipant.publishTrack(videoTrack);
35
36
 
36
37
  async function disableBackgroundBlur() {
37
38
  await videoTrack.stopProcessor();
38
39
  }
39
40
 
40
- async updateBlurRadius(radius) {
41
- return blur.updateTransformerOptions({blurRadius: radius})
41
+ async function updateBlurRadius(radius) {
42
+ return processor.switchTo({ mode: 'background-blur', blurRadius: radius });
42
43
  }
44
+ ```
45
+
46
+ In a real application, it's likely you will want to only sometimes apply background effects. You
47
+ could accomplish this by calling `videoTrack.setProcessor(...)` / `videoTrack.stopProcessor(...)` on
48
+ demand, but these functions can sometimes result in output visual artifacts as part of the switching
49
+ process, which can result in a poor user experience.
50
+
51
+ A better option which won't result in any visual artifacts while switching is to initialize the
52
+ `BackgroundProcessor` in its "disabled" mode, and then later on switch to the desired mode. For
53
+ example:
54
+ ```ts
55
+ const videoTrack = await createLocalVideoTrack();
56
+ const processor = BackgroundProcessor({ mode: 'disabled' });
57
+ await videoTrack.setProcessor(processor);
58
+ room.localParticipant.publishTrack(videoTrack);
43
59
 
60
+ async function enableBlur(radius) {
61
+ await processor.switchTo({ mode: 'background-blur', blurRadius: radius });
62
+ }
44
63
 
64
+ async function disableBlur() {
65
+ await videoTrack.switchTo({ mode: 'disabled' });
66
+ }
45
67
  ```
46
68
 
47
69
  ## Developing your own processors
@@ -58,7 +80,7 @@ export const VirtualBackground = (imagePath: string) => {
58
80
 
59
81
  ### Available base transformers
60
82
 
61
- - BackgroundTransformer (can blur background or use a virtual background);
83
+ - BackgroundTransformer (can blur background, use a virtual background, or be put into a disabled state);
62
84
 
63
85
 
64
86
  ## Running the sample app