Complete Guide to TEN Extension Development
TEN Framework provides rich extension templates to help developers quickly create extensions and complete the entire process from development to testing. This guide will demonstrate in detail how to use C++, Go, Python, and Node.js for the complete extension development workflow through practical operations.
Pre-development Preparation
Environment Requirements
Before starting extension development, please ensure your development environment is properly configured. Verify the installation with the following command:
Under normal circumstances, you should see version information output similar to the following:
Important Note: Please ensure you are using
tman
version >= 0.10.12. If your version is too low, please go to GitHub Releases to download the latest version.
Development Workflow Overview
Regardless of which programming language you use, TEN extension development follows the following standardized workflow:
- Project Creation - Generate extension project skeleton using official templates
- Dependency Installation - Configure runtime environment and install necessary dependency packages
- Core Development - Implement extension business logic and functional code
- Build and Test - Compile project (if needed) and execute unit tests
- Debug and Optimize - Use professional debugging tools to locate and solve problems
C++ Extension Development
C++ extensions are suitable for application scenarios with extremely high performance requirements, such as real-time audio and video processing, high-frequency data computation, low-level system operations, etc.
Create Project
Use the official C++ extension template provided by TEN to quickly create a new project:
After successful project creation, you will get the following complete project structure:
Environment Configuration Verification
Enter the project directory and verify that the build tools are working properly:
Expected Output:
If the command cannot be executed, please check whether the TEN Framework development environment is correctly installed.
Dependency Package Installation
Install all dependency packages required for extension runtime:
After successful installation, you will see detailed installation logs similar to the following:
Project Build
TEN framework provides two convenient build methods for you to choose from:
Method 1: Manual Step-by-step Build
Method 2: Use tman Shortcut Command
After the build is complete, check the generated executable test file:
Run Tests
Verify that the extension functionality is working properly:
Method 1: Execute Test File Directly
Method 2: Use tman Unified Command
Example output when tests execute successfully:
Success Indicator: When you see
[ PASSED ] 1 test.
it means all tests have passed.
Core Code Structure Explanation
Extension Main Implementation (src/main.cc)
The core class of C++ extensions needs to inherit from the ten::extension_t
base class and implement complete lifecycle management methods:
Test Framework Implementation (tests/basic.cc)
Use TEN-specific test framework to write complete unit tests:
Debug Environment Configuration
VSCode Integrated Debugging
- Install the CodeLLDB extension plugin for VSCode
- Set breakpoints in source code
- Select the "standalone test (lldb, launch)" debug configuration
- Press F5 to start debugging session
Debug configuration file .vscode/launch.json
content:
Command Line Debugging
Use the classic GDB debugger for command-line debugging:
Go Extension Development
Go extensions provide a good balance between high performance and development efficiency, particularly suitable for building network services, concurrent processing, microservice architecture and other application scenarios.
Create Project
Create a new project using the Go extension template:
After successful project creation, it will display:
The complete project structure is as follows:
Dependency Package Installation
Install dependency packages required for project runtime:
Run Tests
Verify the correctness of extension functionality:
Method 1: Use Startup Script
Method 2: Use tman Command
Example output when tests execute successfully:
Core Code Structure Explanation
Extension Implementation (extension.go)
Core implementation structure of Go extensions:
Test Framework (tests/basic_tester.go)
Go extension test framework implementation:
Development Environment Optimization
To improve development experience and debugging convenience, it is recommended to create a go.work
workspace file in the extension root directory:
Debug Environment Configuration
VSCode Integrated Debugging
Make sure the official Go extension is installed, then use the following debug configuration:
Python Extension Development
Python extensions have the highest development efficiency, particularly suitable for rapid prototyping, AI/ML application integration, complex business logic implementation and other scenarios.
Create Project
Create a project using the Python async extension template:
Complete project structure:
Dependency Package Installation
Install Python dependency packages required for the project:
Run Tests
Verify Python extension functionality:
Method 1: Use Startup Script
Method 2: Use tman Command
Example output when tests execute successfully:
Core Code Structure Explanation
Extension Implementation (extension.py)
Python extensions recommend using modern async programming patterns for better performance and concurrent processing capabilities:
Plugin Registration Entry (addon.py)
Extension plugin registration and creation logic:
Test Implementation (tests/test_basic.py)
Complete async test framework implementation:
Debug Environment Configuration
VSCode Integrated Debugging
Make sure you have installed the Python extension and debugpy debugger, use the following configuration for debugging:
Node.js Extension Development
Node.js extensions provide a modern JavaScript/TypeScript development experience, particularly suitable for Web application integration, rapid prototyping, frontend technology stack extensions and other scenarios. Thanks to Node.js's async characteristics and rich ecosystem, developers can easily build efficient real-time applications.
Create Project
Use the official Node.js extension template provided by TEN to quickly create a new project:
After successful project creation, you will get the following complete project structure:
Environment Configuration Verification
Enter the project directory and verify the development environment:
Expected Output:
Dependency Package Installation
Install all dependency packages required for extension runtime:
After successful installation, you will see detailed installation logs similar to the following:
Important Note:
tman install --standalone
will create a.ten/app/ten_packages/extension/my_example_ext_nodejs/
directory in the project directory. Subsequent build and test operations need to be performed in this directory.
Project Build
Node.js extensions are developed using TypeScript and need to install standalone mode dependencies first, then compile to JavaScript:
Method 1: Manual Build
Method 2: Use tman Shortcut Command
After the build is complete, check the generated compilation results:
Run Tests
Verify that the extension functionality is working properly:
Method 1: Use Startup Script
Method 2: Use tman Unified Command
Example output when tests execute successfully:
Success Indicator: When you see all test cases showing
✓
and finally displayingpassing
, it means all tests have passed.
Core Code Structure Explanation
Extension Main Implementation (src/index.ts)
The core class of Node.js extensions needs to inherit from the Extension
base class and implement complete lifecycle management methods:
Plugin Registration Entry
Extension plugin registration and creation logic:
Test Framework Implementation (tests/src/index.ts)
Use TEN-specific test framework to write complete unit tests:
Test Case Definition (tests/src/index.spec.ts)
Use Mocha test framework to write specific test cases:
TypeScript Configuration
Node.js extensions use modern TypeScript configuration, supporting the latest language features:
Debug Environment Configuration
VSCode Integrated Debugging
Make sure you have installed the official Node.js extension, then use the following debug configuration:
Command Line Debugging
Use Node.js built-in debugger for command-line debugging:
Complete Development Process Summary
To help developers get started quickly, here is a complete Node.js extension development process summary:
Working Directory Note:
- Extension source code is located in the
src/
folder at the project root directory- Actual build, test, and run operations are performed in the
.ten/app/ten_packages/extension/my_example_ext_nodejs/
directory- This design ensures extension independence and proper dependency management
Development Best Practices
Async Programming
Node.js extensions fully utilize async programming patterns for better performance:
Error Handling
Implement comprehensive error handling mechanisms:
Development Summary
By following the complete development process provided in this guide, you can efficiently develop, test, and debug TEN extensions. Whether you choose C++, Go, Python, or Node.js, TEN Framework provides you with a complete toolchain and best practices to help you fully leverage the powerful features of TEN Framework and build high-performance, high-reliability extension applications.
Each language has its unique advantages and applicable scenarios:
- C++: Suitable for scenarios with extremely high performance requirements, such as real-time audio and video processing, high-frequency computation
- Go: Provides a balance between high performance and development efficiency, suitable for network services, concurrent processing
- Python: Has the highest development efficiency, particularly suitable for AI/ML applications, rapid prototyping
- Node.js: Provides modern Web development experience, suitable for frontend technology stack extensions, real-time applications
Please choose the most suitable development solution based on your specific needs and team technology stack. During the development process, it is recommended to fully utilize the debugging tools and testing frameworks provided by TEN Framework to ensure the quality and stability of your extensions.