Skip to content

Commit 1d1927d

Browse files
committed
Revert changes to Background Blur and Background Replacement to fix bug
1 parent b8242bd commit 1d1927d

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717

1818
### Changed
1919
- Updated `VoiceFocusProvider` to destroy the Voice Focus worker thread on unmount.
20+
- Reverted changes to `BackgroundBlurProvider` and `BackgroundReplacemenProvider` to fix bug related to `isBackgroundBlurSupported` and `isBackgroundReplacementSupported` returning false.
2021

2122
### Fixed
2223

2324
* Update the documentation to use `GlobalStyles` along with `ThemeProvider`.
2425

26+
2527
## [3.4.0] - 2022-09-13
2628

2729
### Added

src/providers/BackgroundBlurProvider/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,12 @@ const BackgroundBlurProvider: FC<Props> = ({ spec, options, children }) => {
8888
);
8989

9090
useEffect(() => {
91+
// One reason we need to initialize first, even though we'll destroy this background blur processor when we create a new device
92+
// is because we need to check if background blur is supported by initializing the background blur processor to see if the browser supports
93+
initializeBackgroundBlur();
9194
return () => {
9295
logger.info(
93-
'Specs or options were changed. Destroying background blur processor.'
96+
'Specs or options were changed. Destroying and re-initializing background blur processor.'
9497
);
9598
backgroundBlurProcessor?.destroy();
9699
};
@@ -147,9 +150,6 @@ const BackgroundBlurProvider: FC<Props> = ({ spec, options, children }) => {
147150
selectedDevice
148151
)}`
149152
);
150-
// TODO: We don't need to intialize a new processor every time we create a background blur device
151-
// We could potentially check for if a processor exists already AND that the processor isn't destroyed.
152-
// If both of those statements are true, then chooseNewInnerDevice instead of creating a new processor
153153
const currentProcessor = await initializeBackgroundBlur();
154154
try {
155155
const logger =

src/providers/BackgroundReplacementProvider/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,12 @@ const BackgroundReplacementProvider: FC<Props> = ({
9595
);
9696

9797
useEffect(() => {
98+
// One reason we need to initialize first, even though we'll destroy this background replacement processor when we create a new device
99+
// is because we need to check if background replacement is supported by initializing the background replacement processor to see if the browser supports
100+
initializeBackgroundReplacement();
98101
return () => {
99102
logger.info(
100-
'Specs or options were changed. Destroying background replacement processor.'
103+
'Specs or options were changed. Destroying and re-initializing background replacement processor.'
101104
);
102105
backgroundReplacementProcessor?.destroy();
103106
};
@@ -155,9 +158,6 @@ const BackgroundReplacementProvider: FC<Props> = ({
155158
selectedDevice
156159
)}`
157160
);
158-
// TODO: We don't need to intialize a new processor every time we create a background replacement device
159-
// We could potentially check for if a processor exists already AND that the processor isn't destroyed.
160-
// If both of those statements are true, then chooseNewInnerDevice instead of creating a new processor
161161
const currentProcessor = await initializeBackgroundReplacement();
162162
try {
163163
const logger =

tst/providers/BackgroundBlurProvider/index.test.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,27 @@ describe.only('BackgroundBlurProvider', () => {
5959
// happens when the component remounts. If it is happening more than
6060
// once, that means some dependency or parent is changing the parameters
6161
// erroneously.
62-
expect(loggerInfoMock).toHaveBeenCalledTimes(1);
62+
expect(loggerInfoMock).toHaveBeenCalledTimes(4);
6363
expect(loggerInfoMock).toHaveBeenCalledWith(
64-
'Specs or options were changed. Destroying background blur processor.'
64+
`Initializing background blur processor with, spec: ${JSON.stringify(
65+
undefined
66+
)}, options: ${JSON.stringify(blurOptions)}`
67+
);
68+
expect(loggerInfoMock).toHaveBeenCalledWith(
69+
'Specs or options were changed. Destroying and re-initializing background blur processor.'
70+
);
71+
72+
// Even though we are using a NoOpVideoFrameProcessor, the input specs
73+
// and options that are passed to the amazon-chime-sdk-js are still
74+
// run through `resolveOptions` and `resolveSpec` in the
75+
// `BackgroundBlurVideoFrameProcessor` constructor so any invalid API
76+
// boundary changes to those are still validated by this test. The
77+
// first warning call is output by `BackgroundBlurVideoFrameProcessor`
78+
// and we don't validate it strictly because there's a non-deterministic
79+
// timestamp. Verifying the call count should be good enough.
80+
expect(loggerWarnMock).toHaveBeenCalledTimes(2);
81+
expect(loggerWarnMock).toHaveBeenLastCalledWith(
82+
expect.stringContaining('Initialized NoOpVideoFrameProcessor')
6583
);
6684

6785
// No errors should happen.

0 commit comments

Comments
 (0)