@livekit/track-processors 0.6.1 → 0.7.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/README.md +31 -9
- package/dist/index.js +297 -84
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +296 -83
- package/dist/index.mjs.map +1 -1
- package/dist/src/ProcessorWrapper.d.ts +12 -7
- package/dist/src/index.d.ts +56 -5
- package/dist/src/logger.d.ts +29 -0
- package/dist/src/transformers/BackgroundTransformer.d.ts +4 -2
- package/dist/src/transformers/VideoTransformer.d.ts +1 -1
- package/dist/src/transformers/types.d.ts +11 -8
- package/dist/src/webgl/index.d.ts +1 -0
- package/dist/src/webgl/shader-programs/compositeShader.d.ts +1 -0
- package/package.json +3 -4
- package/src/ProcessorWrapper.ts +66 -24
- package/src/index.ts +211 -42
- package/src/logger.ts +74 -0
- package/src/transformers/BackgroundTransformer.ts +22 -8
- package/src/transformers/VideoTransformer.ts +1 -1
- package/src/transformers/types.ts +11 -8
- package/src/webgl/index.ts +24 -11
- package/src/webgl/shader-programs/compositeShader.ts +18 -13
- package/src/webgl/utils.ts +6 -2
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 `
|
|
13
|
+
This package exposes the `BackgroundProcessor` pre-prepared processor pipeline, which can be used in a few ways:
|
|
14
14
|
|
|
15
|
-
- `
|
|
16
|
-
- `
|
|
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 {
|
|
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
|
|
33
|
-
await videoTrack.setProcessor(
|
|
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
|
|
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 processor.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
|
|
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
|