Skip to content

Commit

Permalink
feat: bump example electron version to 22.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
guoxianzhe committed Mar 13, 2024
1 parent 6518545 commit a8256c0
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 218 deletions.
5 changes: 2 additions & 3 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"agora-electron-sdk": "4.3.0",
"antd": "^4.20.3",
"download": "^8.0.0",
"ffi-napi": "^4.0.3",
"koffi": "^2.8.0",
"react": "^18.1.0",
"react-color": "^2.19.3",
"react-dom": "^18.1.0",
Expand All @@ -94,13 +94,12 @@
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.6",
"@teamsupercell/typings-for-css-modules-loader": "^2.5.1",
"@types/download": "^8.0.2",
"@types/ffi-napi": "^4.0.7",
"@types/react": "^16.9.44",
"@types/react-color": "^3.0.6",
"@types/react-dom": "^18.0.3",
"@types/react-router-dom": "^5.1.6",
"@types/ref-napi": "^3.0.7",
"electron": "18.2.3",
"electron": "22.0.0",
"electron-builder": "^23.1.0",
"electron-webpack": "^2.8.2",
"fork-ts-checker-webpack-plugin": "^4.1.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import {
createAgoraRtcEngine,
} from 'agora-electron-sdk';
import download from 'download';
import ffi, {
LibraryObject,
LibraryObjectDefinitionToLibraryDefinition,
} from 'ffi-napi';
import ffi, { IKoffiLib } from 'koffi';
import React, { ReactElement } from 'react';

import {
Expand All @@ -33,12 +30,21 @@ if (process.platform === 'darwin') {
}
pluginName += postfix;

type PluginType = {
EnablePlugin: ['bool', ['uint64']];
DisablePlugin: ['bool', ['uint64']];
CreateSamplePlugin: ['uint64', ['uint64']];
DestroySamplePlugin: ['void', ['uint64']];
CreateSampleAudioPlugin: ['uint64', ['uint64']];
type FuncConfig = {
returnType: string;
paramTypes: string[];
};

type PluginConfig = {
[funcName: string]: FuncConfig;
};

const pluginConfig: PluginConfig = {
CreateSampleAudioPlugin: { returnType: 'uint64', paramTypes: ['uint64'] },
CreateSamplePlugin: { returnType: 'uint64', paramTypes: ['uint64'] },
DestroySamplePlugin: { returnType: 'void', paramTypes: ['uint64'] },
DisablePlugin: { returnType: 'bool', paramTypes: ['uint64'] },
EnablePlugin: { returnType: 'bool', paramTypes: ['uint64'] },
};

interface State extends BaseVideoComponentState {
Expand All @@ -49,9 +55,16 @@ export default class ProcessVideoRawData
extends BaseComponent<{}, State>
implements IRtcEngineEventHandler
{
pluginLibrary?: LibraryObject<
LibraryObjectDefinitionToLibraryDefinition<PluginType>
>;
nativeLib?: IKoffiLib;
pluginLibrary: {
[funcName: string]: Function;
} = {
CreateSampleAudioPlugin: () => {},
CreateSamplePlugin: () => {},
DestroySamplePlugin: () => {},
DisablePlugin: () => {},
EnablePlugin: () => {},
};
plugin?: string | number;
pluginAudio?: string | number;

Expand Down Expand Up @@ -137,21 +150,24 @@ export default class ProcessVideoRawData
console.log(`download success`);
}

const plugin: PluginType = {
CreateSampleAudioPlugin: ['uint64', ['uint64']],
CreateSamplePlugin: ['uint64', ['uint64']],
DestroySamplePlugin: ['void', ['uint64']],
DisablePlugin: ['bool', ['uint64']],
EnablePlugin: ['bool', ['uint64']],
};
this.pluginLibrary ??= ffi.Library(dllPath, plugin);
this.nativeLib ??= ffi.load(dllPath);

for (const [funcName, { returnType, paramTypes }] of Object.entries(
pluginConfig
)) {
this.pluginLibrary[funcName] = this.nativeLib.func(
funcName,
returnType,
paramTypes
);
}

const handle = this.engine?.getNativeHandle();
if (handle !== undefined) {
this.plugin = this.pluginLibrary.CreateSamplePlugin(handle);
this.pluginLibrary.EnablePlugin(this.plugin);
this.pluginAudio = this.pluginLibrary.CreateSampleAudioPlugin(handle);
this.pluginLibrary.EnablePlugin(this.pluginAudio);
this.plugin = this.pluginLibrary.CreateSamplePlugin?.(handle);
this.pluginLibrary.EnablePlugin?.(this.plugin);
this.pluginAudio = this.pluginLibrary.CreateSampleAudioPlugin?.(handle);
this.pluginLibrary.EnablePlugin?.(this.pluginAudio);
}
this.setState({ enablePlugin: true });
};
Expand All @@ -161,16 +177,16 @@ export default class ProcessVideoRawData
*/
disablePlugin = () => {
if (this.plugin) {
this.pluginLibrary?.DisablePlugin(this.plugin);
this.pluginLibrary?.DestroySamplePlugin(this.plugin);
this.pluginLibrary.DisablePlugin?.(this.plugin);
this.pluginLibrary.DestroySamplePlugin?.(this.plugin);
this.plugin = undefined;
} else {
this.error('plugin is invalid');
}

if (this.pluginAudio) {
this.pluginLibrary?.DisablePlugin(this.pluginAudio);
this.pluginLibrary?.DestroySamplePlugin(this.pluginAudio);
this.pluginLibrary.DisablePlugin?.(this.pluginAudio);
this.pluginLibrary.DestroySamplePlugin?.(this.pluginAudio);
this.pluginAudio = undefined;
} else {
this.error('pluginAudio is invalid');
Expand Down
2 changes: 1 addition & 1 deletion example/webpack.renderer.additions.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module.exports = function (config) {
// ...config.externals,
'webpack',
'agora-electron-sdk',
'ffi-napi',
'koffi',
'ref-napi',
];
console.log('config', config.module.rules);
Expand Down

0 comments on commit a8256c0

Please sign in to comment.