[+] 鸿蒙

This commit is contained in:
acgist
2023-11-28 12:05:16 +08:00
parent ca063b5191
commit dd0d80df5c
41 changed files with 604 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
# 桃夭终端
## 支持版本
* SDK 9
## C++终端
* [libmediasoupclient源码](https://github.com/versatica/libmediasoupclient)
* [libmediasoupclient文档](https://mediasoup.org/documentation/v3/libmediasoupclient)
* [libmediasoupclient接口](https://mediasoup.org/documentation/v3/libmediasoupclient/api)
## 项目配置
可以自己编译`WebRTC`依赖或者下载已有依赖,项目导入以后拷贝`libmediasoupclient`源码还有`WebRTC`头文件和库文件到`deps`目录。
[WebRTC](https://pan.baidu.com/s/1E_DXv32D9ODyj5J-o-ji_g?pwd=hudc)
> 注意删除目录`build`目录和`third_party`目录中除了`abseil-cpp`以外的所有依赖(当然不删也没关系就是文件太多编译器会变慢)

View File

@@ -0,0 +1,14 @@
.cxx
.idea
.test
.hvigor
.clangd
.clang-tidy
.clang-format
local.properties
oh-package-lock.json5
deps
build
oh_modules
node_modules

View File

@@ -0,0 +1,10 @@
{
"app": {
"bundleName": "com.acgist.taoyao",
"vendor": "acgist",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name"
}
}

View File

@@ -0,0 +1,8 @@
{
"string": [
{
"name": "app_name",
"value": "taoyao"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

View File

@@ -0,0 +1,41 @@
{
"app": {
"compileSdkVersion": 9,
"compatibleSdkVersion": 9,
"products": [
{
"name": "default",
"signingConfig": "default"
}
],
"signingConfigs": [
{
"name": "default",
"type": "HarmonyOS",
"material": {
"certpath": "C:\\Users\\acgis\\.ohos\\config\\auto_debug_taoyao_com.acgist.taoyao_30086000001511570.cer",
"storePassword": "0000001B6B72744A79D44F625FF6D295CE824032D543A50BF93BD6985B89C7B657379C8735401C2A9700CC",
"keyAlias": "debugKey",
"keyPassword": "0000001B6120DA129145E921FE4068BC61E7D7B5F4BF9386D51C895374C65BF9FE5890AFCD0F992B21E509",
"profile": "C:\\Users\\acgis\\.ohos\\config\\auto_debug_taoyao_com.acgist.taoyao_30086000001511570.p7b",
"signAlg": "SHA256withECDSA",
"storeFile": "C:\\Users\\acgis\\.ohos\\config\\auto_debug_taoyao_com.acgist.taoyao_30086000001511570.p12"
}
}
],
},
"modules": [
{
"name": "media",
"srcPath": "./media",
"targets": [
{
"name": "default",
"applyToProducts": [
"default"
]
}
]
}
]
}

View File

@@ -0,0 +1,6 @@
{
"hvigorVersion": "2.4.2",
"dependencies": {
"@ohos/hvigor-ohos-plugin": "2.4.2"
}
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
export { appTasks } from '@ohos/hvigor-ohos-plugin';

View File

@@ -0,0 +1,48 @@
#!/bin/bash
# ----------------------------------------------------------------------------
# Hvigor startup script, version 1.0.0
#
# Required ENV vars:
# ------------------
# NODE_HOME - location of a Node home dir
# or
# Add /usr/local/nodejs/bin to the PATH environment variable
# ----------------------------------------------------------------------------
HVIGOR_APP_HOME=$(dirname $(readlink -f $0))
HVIGOR_WRAPPER_SCRIPT=${HVIGOR_APP_HOME}/hvigor/hvigor-wrapper.js
warn() {
echo ""
echo -e "\033[1;33m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
}
error() {
echo ""
echo -e "\033[1;31m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
}
fail() {
error "$@"
exit 1
}
# Determine node to start hvigor wrapper script
if [ -n "${NODE_HOME}" ];then
EXECUTABLE_NODE="${NODE_HOME}/bin/node"
if [ ! -x "$EXECUTABLE_NODE" ];then
fail "ERROR: NODE_HOME is set to an invalid directory,check $NODE_HOME\n\nPlease set NODE_HOME in your environment to the location where your nodejs installed"
fi
else
EXECUTABLE_NODE="node"
which ${EXECUTABLE_NODE} > /dev/null 2>&1 || fail "ERROR: NODE_HOME is not set and not 'node' command found in your path"
fi
# Check hvigor wrapper script
if [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ];then
fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}"
fi
# start hvigor-wrapper script
exec "${EXECUTABLE_NODE}" \
"${HVIGOR_WRAPPER_SCRIPT}" "$@"

View File

@@ -0,0 +1,64 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Hvigor startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
set WRAPPER_MODULE_PATH=%APP_HOME%\hvigor\hvigor-wrapper.js
set NODE_EXE=node.exe
goto start
:start
@rem Find node.exe
if defined NODE_HOME goto findNodeFromNodeHome
%NODE_EXE% --version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH.
echo.
echo Please set the NODE_HOME variable in your environment to match the
echo location of your NodeJs installation.
goto fail
:findNodeFromNodeHome
set NODE_HOME=%NODE_HOME:"=%
set NODE_EXE_PATH=%NODE_HOME%/%NODE_EXE%
if exist "%NODE_EXE_PATH%" goto execute
echo.
echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH.
echo.
echo Please set the NODE_HOME variable in your environment to match the
echo location of your NodeJs installation.
goto fail
:execute
@rem Execute hvigor
"%NODE_EXE%" %WRAPPER_MODULE_PATH% %*
if "%ERRORLEVEL%" == "0" goto hvigorwEnd
:fail
exit /b 1
:hvigorwEnd
if "%OS%" == "Windows_NT" endlocal
:end

View File

@@ -0,0 +1,18 @@
{
"apiType": 'stageMode',
"buildOption": {
"externalNativeOptions": {
"path": "./src/main/cpp/CMakeLists.txt",
"arguments": "",
// "cFlags": "-std=c17",
"cppFlags": "-std=c++17",
"abiFilters": [ "arm64-v8a" ]
}
},
"targets": [
{
"name": "default",
"runtimeOS": "HarmonyOS"
}
]
}

View File

@@ -0,0 +1 @@
export { hapTasks } from '@ohos/hvigor-ohos-plugin';

View File

@@ -0,0 +1,12 @@
{
"name": "media",
"main": "",
"author": "acgist",
"description": "桃夭媒体终端",
"license": "Apache-2.0",
"version": "1.0.0",
"dependencies": {},
"devDependencies": {
"@types/libtaoyao.so": "file:./src/main/cpp/types/libtaoyao"
},
}

View File

@@ -0,0 +1,39 @@
cmake_minimum_required(VERSION 3.4.1)
project(taoyao VERSION 1.0.0 LANGUAGES C CXX)
# Debug | Release
#-DCMAKE_BUILD_TYPE=Debug
#set(CMAKE_BUILD_TYPE Debug)
# C编译选项
set(CMAKE_C_STANDARD 17)
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c17 -O3")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -std=c17 -O0 -g")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -std=c17 -O3")
# C++编译选项
set(CMAKE_CXX_STANDARD 17)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -O3")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++17 -O0 -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++17 -O3")
set(LIBWEBRTC_INCLUDE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/deps/webrtc/src")
set(LIBWEBRTC_BINARY_PATH "${CMAKE_CURRENT_SOURCE_DIR}/deps/webrtc/lib/arm64-v8a")
add_subdirectory("./deps/libmediasoupclient")
add_library(${PROJECT_NAME} SHARED hello.cpp)
target_include_directories(
${PROJECT_NAME} PUBLIC
"./include"
"./deps/libmediasoupclient/include"
"./deps/libmediasoupclient/deps/libsdptransform/include"
)
target_link_libraries(
${PROJECT_NAME} PUBLIC
mediasoupclient
libace_napi.z.so
)

View File

@@ -0,0 +1,54 @@
#include "napi/native_api.h"
static napi_value Add(napi_env env, napi_callback_info info)
{
size_t requireArgc = 2;
size_t argc = 2;
napi_value args[2] = {nullptr};
napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);
napi_valuetype valuetype0;
napi_typeof(env, args[0], &valuetype0);
napi_valuetype valuetype1;
napi_typeof(env, args[1], &valuetype1);
double value0;
napi_get_value_double(env, args[0], &value0);
double value1;
napi_get_value_double(env, args[1], &value1);
napi_value sum;
napi_create_double(env, value0 + value1, &sum);
return sum;
}
EXTERN_C_START
static napi_value Init(napi_env env, napi_value exports)
{
napi_property_descriptor desc[] = {
{ "add", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr }
};
napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
return exports;
}
EXTERN_C_END
static napi_module demoModule = {
.nm_version = 1,
.nm_flags = 0,
.nm_filename = nullptr,
.nm_register_func = Init,
.nm_modname = "taoyao",
.nm_priv = ((void*)0),
.reserved = { 0 },
};
extern "C" __attribute__((constructor)) void RegisterEntryModule(void)
{
napi_module_register(&demoModule);
}

View File

@@ -0,0 +1,19 @@
/**
* 终端
*
* @author acgist
*/
#ifndef taoyao_Client_HPP
#define taoyao_Client_HPP
namespace acgist {
class Client {
public:
};
}
#endif taoyao_Client_HPP

View File

@@ -0,0 +1,10 @@
/**
* 房间本地终端
*
* @author acgist
*/
#ifndef taoyao_LocalClient_HPP
#define taoyao_LocalClient_HPP
#endif taoyao_LocalClient_HPP

View File

@@ -0,0 +1,29 @@
/**
* WebRTC媒体服务
* 提供通道等等创建
*
* @author acgist
*/
#ifndef taoyao_MediaManager_HPP
#define taoyao_MediaManager_HPP
#include "pc/peer_connection.h"
#include "pc/peer_connection_factory.h"
namespace acgist {
class MediaManager {
public:
webrtc::PeerConnectionFactory* peerConnectionFactoryPtr;
public:
void initPeerConnectionFactory();
webrtc::PeerConnection* buildPeerConnection();
void startCapture();
void startAudioCapture();
void startVideoCapture();
};
}
#endif taoyao_MediaManager_HPP

View File

@@ -0,0 +1,10 @@
/**
* 房间远程终端
*
* @author acgist
*/
#ifndef taoyao_RemoteClient_HPP
#define taoyao_RemoteClient_HPP
#endif taoyao_RemoteClient_HPP

View File

@@ -0,0 +1,10 @@
/**
* 房间
*
* @author acgist
*/
#ifndef taoyao_Room.cpp_HPP
#define taoyao_Room.cpp_HPP
#endif taoyao_Room.cpp_HPP

View File

@@ -0,0 +1,10 @@
/**
* 房间终端
*
* @author acgist
*/
#ifndef taoyao_RoomClient_HPP
#define taoyao_RoomClient_HPP
#endif taoyao_RoomClient_HPP

View File

@@ -0,0 +1,10 @@
/**
* 会话终端
*
* @author acgist
*/
#ifndef taoyao_SessionClient_HPP
#define taoyao_SessionClient_HPP
#endif taoyao_SessionClient_HPP

View File

@@ -0,0 +1 @@
export const add: (a: number, b: number) => number;

View File

@@ -0,0 +1,6 @@
{
"name": "libtaoyao.so",
"types": "./index.d.ts",
"version": "",
"description": "桃夭媒体依赖"
}

View File

@@ -0,0 +1,41 @@
import UIAbility from '@ohos.app.ability.UIAbility';
import hilog from '@ohos.hilog';
import window from '@ohos.window';
export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
}
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/Index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
}
onForeground() {
// Ability has brought to foreground
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
}
onBackground() {
// Ability has back to background
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
}
};

View File

@@ -0,0 +1,25 @@
import hilog from '@ohos.hilog';
// import testNapi from 'libtaoyao.so'
@Entry
@Component
struct Index {
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
.onClick(() => {
// hilog.info(0x0000, 'testTag', 'Test NAPI 2 + 3 = %{public}d', testNapi.add(2, 3));
})
}
.width('100%')
}
.height('100%')
}
}

View File

@@ -0,0 +1,18 @@
/**
* 信令连接
*
* @author acgist
*/
// import { BusinessError } from '@ohos.base';
import webSocket from '@ohos.net.webSocket';
export default class TaoyaoSignal {
// const socket;
//
// void connect(address) {
//
// }
}

View File

@@ -0,0 +1,37 @@
{
"module": {
"name": "media",
"type": "entry",
"pages": "$profile:main_pages",
"description": "$string:module_desc",
"mainElement": "EntryAbility",
"installationFree": false,
"deliveryWithInstall": true,
"deviceTypes": [
"phone",
"tablet"
],
"abilities": [
{
"name": "EntryAbility",
"icon": "$media:icon",
"label": "$string:EntryAbility_label",
"exported": true,
"srcEntry": "./ets/entryability/EntryAbility.ts",
"description": "$string:EntryAbility_desc",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
]
}
]
}
}

View File

@@ -0,0 +1,8 @@
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}

View File

@@ -0,0 +1,16 @@
{
"string": [
{
"name": "module_desc",
"value": "桃夭媒体服务"
},
{
"name": "EntryAbility_desc",
"value": "主界面"
},
{
"name": "EntryAbility_label",
"value": "主界面"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

View File

@@ -0,0 +1,5 @@
{
"src": [
"pages/Index"
]
}

View File

@@ -0,0 +1,12 @@
{
"name": "taoyao",
"main": "",
"author": "acgist",
"description": "桃夭鸿蒙终端",
"version": "1.0.0",
"license": "Apache-2.0",
"dependencies": {},
"devDependencies": {
"@ohos/hypium": "1.0.6"
},
}