Skip to content

Commit

Permalink
chore: fix extension demo NMS-21902
Browse files Browse the repository at this point in the history
  • Loading branch information
guoxianzhe committed Aug 8, 2024
1 parent e043377 commit 9dc0e94
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions example/src/examples/advanced/Extension/Extension.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export default class Extension
joinChannelSuccess: false,
remoteUsers: [],
startPreview: false,
path: 'agora_segmentation_extension',
provider: 'agora_video_filters_segmentation',
extension: 'portrait_segmentation',
path: '',
provider: '',
extension: '',
enableExtension: false,
};
}
Expand Down Expand Up @@ -95,17 +95,21 @@ export default class Extension
this.engine?.loadExtensionProvider(path);
}

this.engine?.enableExtension(provider, extension, true);
this.setState({ enableExtension: true });
let result = this.engine?.enableExtension(provider, extension, true);
if (result && result < 0) {
this.error(`enableExtension failed: ${result}`);
}
};

/**
* Step 2-2: disableExtension
*/
disableExtension = () => {
const { provider, extension } = this.state;
this.engine?.enableExtension(provider, extension, false);
this.setState({ enableExtension: false });
let result = this.engine?.enableExtension(provider, extension, false);
if (result && result < 0) {
this.error(`enableExtension failed: ${result}`);
}
};

/**
Expand Down Expand Up @@ -183,12 +187,22 @@ export default class Extension

onExtensionStartedWithContext(context: ExtensionContext) {
this.info('onExtensionStartedWithContext', 'context', context);
this.setState({ enableExtension: true });
if (
context.providerName === this.state.provider &&
context.extensionName === this.state.extension
) {
this.setState({ enableExtension: true });
}
}

OnExtensionStoppedWithContext(context: ExtensionContext) {
this.info('OnExtensionStoppedWithContext', 'context', context);
this.setState({ enableExtension: false });
onExtensionStoppedWithContext(context: ExtensionContext) {
this.info('onExtensionStoppedWithContext', 'context', context);
if (
context.providerName === this.state.provider &&
context.extensionName === this.state.extension
) {
this.setState({ enableExtension: false });
}
}

protected renderConfiguration(): ReactElement | undefined {
Expand Down Expand Up @@ -229,11 +243,10 @@ export default class Extension
}

protected renderAction(): ReactElement | undefined {
const { joinChannelSuccess, enableExtension } = this.state;
const { enableExtension } = this.state;
return (
<>
<AgoraButton
disabled={joinChannelSuccess}
title={`${enableExtension ? 'disable' : 'enable'} Extension`}
onPress={
enableExtension ? this.disableExtension : this.enableExtension
Expand Down

0 comments on commit 9dc0e94

Please sign in to comment.