diff --git a/taoyao-client-harmony/README.md b/taoyao-client-harmony/README.md index 421b2b1..82bd49f 100644 --- a/taoyao-client-harmony/README.md +++ b/taoyao-client-harmony/README.md @@ -1,7 +1,5 @@ # 鸿蒙终端 -提供嵌入式开发能力,选择开发板`Hi3518E`。 - ## C++终端 * [libmediasoupclient源码](https://github.com/versatica/libmediasoupclient) @@ -10,119 +8,6 @@ ## 学习资料 -https://hpm.harmonyos.com/#/cn/home -https://repo.harmonyos.com/#/cn/home -https://www.hihope.org/download/download.aspx -https://device.harmonyos.com/cn/develop/ide/ -https://device.harmonyos.com/cn/documentation/ -https://www.openharmony.cn/docs/zh-cn/overview/ -https://www.openharmony.cn/docs/zh-cn/device-dev/ -https://docs.openharmony.cn/pages/v3.1/zh-cn/OpenHarmony-Overview_zh.md/ -https://docs.openharmony.cn/pages/v3.1/zh-cn/device-dev/device-dev-guide.md/ -https://docs.openharmony.cn/pages/v3.1/zh-cn/device-dev/hpm-part/hpm-part-about.md/ - -## 环境 - -``` -# Ubuntu -# https://mirrors.tuna.tsinghua.edu.cn/ubuntu-releases/20.04.5/ - -# `Ubuntu`选择版本`20.04.5`,建议选择相同版本,不然很多软件版本需要自己调整。 - -# 环境搭建 -# https://device.harmonyos.com/cn/docs/documentation/guide/ide-install-windows-ubuntu-0000001194073744 -``` - -## 源码 - -``` -# 下载源码 -# https://gitee.com/openharmony/manifest/tree/OpenHarmony-3.2-Release/ -# https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/get-code/sourcecode-acquire.md - -repo init -u https://gitee.com/openharmony/manifest.git -b OpenHarmony-3.2-Release -m chipsets/hispark_aries.xml -g ohos:mini --no-repo-verify -repo sync -c -repo forall -c 'git lfs pull' - -# Marketplace -# https://hpm.harmonyos.com/#/cn/solution/@ohos%2Fhispark_aries -# https://repo.harmonyos.com/#/cn/solution/@opensource%2Fhoperun_hm_door_3518 -# https://gitee.com/openharmony-sig/knowledge_demo_smart_home/blob/master/dev/docs/smart_door_viewer_3518/README.md - -sudo apt install nodejs -sudo apt install npm -npm config set registry https://repo.huaweicloud.com/repository/npm -npm install -g @ohos/hpm-cli -``` - -## 编译 - -https://hpm.harmonyos.com/#/cn/home -https://docs.openharmony.cn/pages/v3.1/zh-cn/device-dev/hpm-part/hpm-part-about.md/ - -``` -# 下载依赖 -hpm install - -# hpm编译 -hpm dist - -# hb编译 -pip3 install build/lite -# hp增量编译 -hb build -# hp完整编译 -hb build -f - -# build编译 -./build.sh \ - --ccache \ - --product-name Hi3518EV300 \ - --build-target build_kernel \ - --gn-args linux_kernel_version=\"linux-5.10\" -``` - -## 烧录 - -https://www.hihope.org/download/download.aspx - -``` -# out/hispark_aries/ipcamera_hispark_aries -# device/hisilicon/hispark_aries/sdk_liteos/uboot/out/boot - -u-boot-hi3518ev300.bin:fastboot -OHOS_Image.bin:kernel -rootfs_jffs2.img:rootfs -userfs_jffs2.img:userfs -``` - -## 配置 - -串口:`115200` - -``` -setenv bootcmd "sf probe 0;sf read 0x40000000 0x100000 0x600000;go 0x40000000" -setenv bootargs "console=ttyAMA0,115200n8 root=flash fstype=jffs2 rw rootaddr=7M rootsize=8M" -save -reset -./bin/wpa_supplicant -iwlan0 -c /etc/wpa_supplicant.conf -``` - -## 代码目录 - -``` -applications 应用程序样例,包括camera等 -base 基础软件服务子系统集&硬件服务子系统集 -build 组件化编译、构建和配置脚本 -docs 说明文档 -domains 增强软件服务子系统集 -drivers 驱动子系统 -foundation 系统基础能力子系统集 -kernel 内核子系统 -prebuilts 编译器及工具链子系统 -test 测试子系统 -third_party 开源第三方组件 -utils 常用的工具集 -vendor 厂商提供的软件 -build.py 编译脚本文件 -``` +https://developer.harmonyos.com/cn/develop/ +https://developer.harmonyos.com/cn/docs/documentation/doc-guides/start-overview-0000000000029602 +https://developer.harmonyos.com/cn/docs/documentation/doc-references/reference-document-outline-0000001115016824 diff --git a/taoyao-client-harmony/hi3518e.xml b/taoyao-client-harmony/hi3518e.xml deleted file mode 100644 index c64171b..0000000 --- a/taoyao-client-harmony/hi3518e.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/taoyao-client-harmony/os/.gitignore b/taoyao-client-harmony/os/.gitignore deleted file mode 100644 index f48ed97..0000000 --- a/taoyao-client-harmony/os/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.vscode/ -ohos_bundles \ No newline at end of file diff --git a/taoyao-client-harmony/os/README.md b/taoyao-client-harmony/os/README.md deleted file mode 100644 index 4fcb103..0000000 --- a/taoyao-client-harmony/os/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# 桃夭鸿蒙系统 - -https://hpm.harmonyos.com/#/cn/solution/@ohos%2Fhispark_aries diff --git a/taoyao-client-harmony/os/bundle.json b/taoyao-client-harmony/os/bundle.json deleted file mode 100644 index e8c8671..0000000 --- a/taoyao-client-harmony/os/bundle.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "taoyao", - "version": "1.0.0", - "license": "https://gitee.com/acgist/taoyao/blob/master/LICENSE", - "hompage": "https://gitee.com/acgist/taoyao", - "repository": "https://gitee.com/acgist/taoyao.git", - "description": "桃夭鸿蒙终端", - "publishAs": "distribution", - "ohos": { - "os": "3.0.0", - "board": "hi3518", - "kernel": "liteos_a" - }, - "base": { - "name": "@ohos/hispark_aries", - "version": "3.0.3" - }, - "author": { - "url": "https://www.acgist.com", - "name": "acgist", - "email": "rei@acgist.com" - }, - "dirs": {}, - "envs": {}, - "scripts": {}, - "excludes": [], - "dependencies": {} -} diff --git a/taoyao-client-harmony/os/bundle.release.json b/taoyao-client-harmony/os/bundle.release.json deleted file mode 100644 index e059025..0000000 --- a/taoyao-client-harmony/os/bundle.release.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "taoyao", - "version": "1.0.0", - "license": "https://gitee.com/acgist/taoyao/blob/master/LICENSE", - "hompage": "https://gitee.com/acgist/taoyao", - "repository": "https://gitee.com/acgist/taoyao.git", - "description": "桃夭鸿蒙终端", - "publishAs": "distribution", - "ohos": { - "os": "3.0.0", - "board": "hi3518", - "kernel": "liteos_a" - }, - "base": { - "name": "@ohos/hispark_aries", - "version": "3.0.3" - }, - "author": { - "url": "https://www.acgist.com", - "name": "acgist", - "email": "rei@acgist.com" - }, - "dirs": {}, - "envs": { - "debug": false - }, - "scripts": {}, - "excludes": ["applications_sample_camera"], - "dependencies": {} -} diff --git a/taoyao-client-harmony/taoyao/.gitignore b/taoyao-client-harmony/taoyao/.gitignore index 99e1bca..a7c9c0c 100644 --- a/taoyao-client-harmony/taoyao/.gitignore +++ b/taoyao-client-harmony/taoyao/.gitignore @@ -1,10 +1,12 @@ -CMakeCache.txt +local.properties -**/*.so -**/*.exe -**/*.lib +.clangd +.clang-tidy +.clang-format -.vscode/** +**/.cxx +**/.idea +**/.gradle -build/** -openharmony/** \ No newline at end of file +**/build +**/node_modules diff --git a/taoyao-client-harmony/taoyao/.gitmodules b/taoyao-client-harmony/taoyao/.gitmodules deleted file mode 100644 index 92176b2..0000000 --- a/taoyao-client-harmony/taoyao/.gitmodules +++ /dev/null @@ -1,4 +0,0 @@ -[submodule "googletest"] - path = test/lib/googletest - url = https://github.com/google/googletest.git - branch = master diff --git a/taoyao-client-harmony/taoyao/CMakeLists.txt b/taoyao-client-harmony/taoyao/CMakeLists.txt deleted file mode 100644 index fcc9dfb..0000000 --- a/taoyao-client-harmony/taoyao/CMakeLists.txt +++ /dev/null @@ -1,84 +0,0 @@ -cmake_minimum_required(VERSION 3.2) - -#define CMAKE_TEMPLATE_VERSION_MAJOR @CMakeTemplate_VERSION_MAJOR@ -#define CMAKE_TEMPLATE_VERSION_MINOR @CMakeTemplate_VERSION_MINOR@ -#define CMAKE_TEMPLATE_VERSION_PATCH @CMakeTemplate_VERSION_PATCH@ -project(taoyao-client-camera VERSION 1.0.0 LANGUAGES C CXX) - -# Debug | Release -# DCMAKE_BUILD_TYPE=Debug -set(CMAKE_BUILD_TYPE Debug) - -# set(CMAKE_C_COMPILER gcc) -# set(CMAKE_CXX_COMPILER g++) - -# 全局宏定义 -# add_definitions(-DDEBUG) - -# 全局编译选项 -# add_compile_options() - -# C编译选项 -set(CMAKE_C_STANDARD 11) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -O3") -set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -O0") -set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3") - -# C++编译选项 -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3") -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0") -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3") - -# 输出目录 -set(PROJECT_BINARY_DIR ${PROJECT_SOURCE_DIR}/build) - -# 包含源代码 -# add_subdirectory(src) -# add_subdirectory(test) - -file( - GLOB SOURCE_FILE - "include/*.h" - "include/*.hpp" - "src/main.cpp" - "src/media/*.c" - "src/signal/*.c" - "src/media/*.cpp" - "src/signal/*.cpp" -) - -# -lpthread - -add_executable(${PROJECT_NAME} ${SOURCE_FILE}) - -# message("源码地址:" ${SOURCE_FILE}) - -# 配置 -# cmake -B build -# Windows:-G "Unix Makefiles" -# 安装位置:-DCMAKE_INSTALL_PREFIX=`pwd`/output | --install --prefix -# 打包位置:-DCPACK_OUTPUT_FILE_PREFIX=`pwd`/output - -# 编译 -# cmake --build build - -# 安装 -# cd build && make install && cd - - -# install( -# TARGETS taoyao -# RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin -# LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib -# ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib -# ) - -# 打包 -# cd build && cpack && cd - - -# include(CPack) -# set(CPACK_GENERATOR "ZIP") -# set(CPACK_SET_DESTDIR ON) -# set(CPACK_INSTALL_PREFIX "") -# set(CPACK_PACKAGE_NAME "taoyao") -# set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) diff --git a/taoyao-client-harmony/taoyao/README.md b/taoyao-client-harmony/taoyao/README.md deleted file mode 100644 index deb89d5..0000000 --- a/taoyao-client-harmony/taoyao/README.md +++ /dev/null @@ -1 +0,0 @@ -# 桃夭鸿蒙终端 diff --git a/taoyao-client-harmony/taoyao/build.gradle b/taoyao-client-harmony/taoyao/build.gradle new file mode 100644 index 0000000..430c913 --- /dev/null +++ b/taoyao-client-harmony/taoyao/build.gradle @@ -0,0 +1,41 @@ +apply plugin: 'com.huawei.ohos.app' + +ohos { + signingConfigs { + debug { + storeFile file('C:\\Users\\acgis\\.ohos\\config\\auto_debug_taoyao_com.acgist.taoyao_30086000001511570.p12') + storePassword '0000001BF429DD369062C4630873F17257C6AE37F3B5CCC5BE92C1DE60CEBE94E3592C9A6423F38CA5C88E' + keyAlias = 'debugKey' + keyPassword '0000001B814502DD14E5F3430066B6F451C85FFB36AB7ADB13AC53823EB7A3F644FED4758F5053827B968D' + signAlg = 'SHA256withECDSA' + profile file('C:\\Users\\acgis\\.ohos\\config\\auto_debug_taoyao_com.acgist.taoyao_30086000001511570.p7b') + certpath file('C:\\Users\\acgis\\.ohos\\config\\auto_debug_taoyao_com.acgist.taoyao_30086000001511570.cer') + } + } + compileSdkVersion 7 +} + +buildscript { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + } + dependencies { + classpath 'com.huawei.ohos:hap:3.1.2.0' + classpath 'com.huawei.ohos:decctest:1.2.7.19' + } +} +allprojects { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + } +} diff --git a/taoyao-client-harmony/taoyao/client/build.gradle b/taoyao-client-harmony/taoyao/client/build.gradle new file mode 100644 index 0000000..34a6fdd --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/build.gradle @@ -0,0 +1,34 @@ +apply plugin: 'com.huawei.ohos.hap' +apply plugin: 'com.huawei.ohos.decctest' + +ohos { + compileSdkVersion 7 + defaultConfig { + compatibleSdkVersion 7 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } + externalNativeBuild { + path "src/main/cpp/CMakeLists.txt" + arguments "" + abiFilters "arm64-v8a" + cppFlags "" + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + implementation 'com.fasterxml.jackson.core:jackson-databind:2.14.2' + implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.14.2' + testImplementation 'junit:junit:4.13.1' + ohosTestImplementation 'com.huawei.ohos.testkit:runner:2.0.0.400' +} +decc { + supportType = ['html', 'xml'] +} diff --git a/taoyao-client-harmony/taoyao/client/src/main/config.json b/taoyao-client-harmony/taoyao/client/src/main/config.json new file mode 100644 index 0000000..274e2f1 --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/main/config.json @@ -0,0 +1,60 @@ +{ + "app": { + "bundleName": "com.acgist.taoyao", + "vendor": "acgist", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": { + "default": { + "keepAlive": true + } + }, + "module": { + "package": "com.acgist.taoyao", + "name": "com.acgist.taoyao.TaoyaoApplication", + "mainAbility": "com.acgist.taoyao.MainAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "client", + "moduleType": "entry", + "installationFree": false + }, + "abilities": [ + { + "name": "com.acgist.taoyao.MainAbility", + "icon": "$media:icon", + "label": "$string:main_label", + "description": "$string:main_description", + "launchType": "standard", + "orientation": "unspecified", + "visible": true, + "skills": [ + { + "actions": [ + "action.system.home", + "main", + "setting" + ], + "entities": [ + "entity.system.home" + ] + } + ], + "type": "page" + }, + { + "name": "com.acgist.taoyao.MediaAbility", + "description": "$string:media_description", + "type": "service", + "backgroundModes": [], + "icon": "$media:icon" + } + ] + } +} \ No newline at end of file diff --git a/taoyao-client-harmony/taoyao/client/src/main/cpp/CMakeLists.txt b/taoyao-client-harmony/taoyao/client/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000..d026331 --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/main/cpp/CMakeLists.txt @@ -0,0 +1,41 @@ +cmake_minimum_required(VERSION 3.2) + +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 11) +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 11) +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(PROJECT_BINARY_DIR ${PROJECT_SOURCE_DIR}/build) + +file( + GLOB SOURCE_FILE + "main.hpp" + "include/*.hpp" + "mediasoup/*.hpp" + "main.cpp" + "media/*.cpp" +) + +add_library(taoyao SHARED ${SOURCE_FILE}) +target_link_libraries(taoyao libhilog_ndk.z.so) + +# 配置 +# cmake -B build +# Windows:cmake -B build -G "Unix Makefiles" +# 编译 +# cmake --build build +# 标准线程:-lpthread diff --git a/taoyao-client-harmony/taoyao/include/MediaClient.hpp b/taoyao-client-harmony/taoyao/client/src/main/cpp/include/AudioPublisher.hpp similarity index 59% rename from taoyao-client-harmony/taoyao/include/MediaClient.hpp rename to taoyao-client-harmony/taoyao/client/src/main/cpp/include/AudioPublisher.hpp index f7b3e96..f7883f8 100644 --- a/taoyao-client-harmony/taoyao/include/MediaClient.hpp +++ b/taoyao-client-harmony/taoyao/client/src/main/cpp/include/AudioPublisher.hpp @@ -1,8 +1,5 @@ #pragma once -/** - * 媒体终端 - */ namespace acgist { } \ No newline at end of file diff --git a/taoyao-client-harmony/taoyao/include/Publisher.hpp b/taoyao-client-harmony/taoyao/client/src/main/cpp/include/MediaPublisher.hpp similarity index 98% rename from taoyao-client-harmony/taoyao/include/Publisher.hpp rename to taoyao-client-harmony/taoyao/client/src/main/cpp/include/MediaPublisher.hpp index 7eb2543..7cfff5c 100644 --- a/taoyao-client-harmony/taoyao/include/Publisher.hpp +++ b/taoyao-client-harmony/taoyao/client/src/main/cpp/include/MediaPublisher.hpp @@ -7,6 +7,4 @@ namespace acgist { - - } \ No newline at end of file diff --git a/taoyao-client-harmony/taoyao/include/MediaRecorder.hpp b/taoyao-client-harmony/taoyao/client/src/main/cpp/include/MediaRecorder.hpp similarity index 61% rename from taoyao-client-harmony/taoyao/include/MediaRecorder.hpp rename to taoyao-client-harmony/taoyao/client/src/main/cpp/include/MediaRecorder.hpp index 07b7629..4a088fe 100644 --- a/taoyao-client-harmony/taoyao/include/MediaRecorder.hpp +++ b/taoyao-client-harmony/taoyao/client/src/main/cpp/include/MediaRecorder.hpp @@ -1,8 +1,5 @@ #pragma once -/** - * 媒体录制 - */ namespace acgist { } \ No newline at end of file diff --git a/taoyao-client-harmony/taoyao/include/VideoPublisher.hpp b/taoyao-client-harmony/taoyao/client/src/main/cpp/include/VideoPublisher.hpp similarity index 59% rename from taoyao-client-harmony/taoyao/include/VideoPublisher.hpp rename to taoyao-client-harmony/taoyao/client/src/main/cpp/include/VideoPublisher.hpp index c41be2f..4a088fe 100644 --- a/taoyao-client-harmony/taoyao/include/VideoPublisher.hpp +++ b/taoyao-client-harmony/taoyao/client/src/main/cpp/include/VideoPublisher.hpp @@ -1,8 +1,5 @@ #pragma once -/** - * 视频推送器 - */ namespace acgist { } \ No newline at end of file diff --git a/taoyao-client-harmony/taoyao/client/src/main/cpp/main.cpp b/taoyao-client-harmony/taoyao/client/src/main/cpp/main.cpp new file mode 100644 index 0000000..9a35099 --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/main/cpp/main.cpp @@ -0,0 +1,16 @@ +#include +#include +#include + +#include "main.hpp" + +extern "C" JNIEXPORT jstring JNICALL +Java_com_acgist_taoyao_slice_MainAbilitySlice_stringFromJNI(JNIEnv *env, jobject obj) { + std::string hello = "Hello from JNI C++ codes"; + int len = hello.size(); + jchar res[len]; + for (int i = 0; i < len; i++) { + res[i] = (jchar)hello[i]; + } + return env->NewString(res, len); +} diff --git a/taoyao-client-harmony/taoyao/include/main.hpp b/taoyao-client-harmony/taoyao/client/src/main/cpp/main.hpp similarity index 100% rename from taoyao-client-harmony/taoyao/include/main.hpp rename to taoyao-client-harmony/taoyao/client/src/main/cpp/main.hpp diff --git a/taoyao-client-harmony/taoyao/client/src/main/cpp/media/AudioPublisher.cpp b/taoyao-client-harmony/taoyao/client/src/main/cpp/media/AudioPublisher.cpp new file mode 100644 index 0000000..39fd603 --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/main/cpp/media/AudioPublisher.cpp @@ -0,0 +1,5 @@ +#include "../include/AudioPublisher.hpp" + +namespace acgist { + +} \ No newline at end of file diff --git a/taoyao-client-harmony/taoyao/client/src/main/cpp/media/MediaPublisher.cpp b/taoyao-client-harmony/taoyao/client/src/main/cpp/media/MediaPublisher.cpp new file mode 100644 index 0000000..e69de29 diff --git a/taoyao-client-harmony/taoyao/client/src/main/cpp/media/MediaRecorder.cpp b/taoyao-client-harmony/taoyao/client/src/main/cpp/media/MediaRecorder.cpp new file mode 100644 index 0000000..75e8d63 --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/main/cpp/media/MediaRecorder.cpp @@ -0,0 +1,5 @@ +#include "../include/MediaRecorder.hpp" + +namespace acgist { + +} \ No newline at end of file diff --git a/taoyao-client-harmony/taoyao/client/src/main/cpp/media/VideoPublisher.cpp b/taoyao-client-harmony/taoyao/client/src/main/cpp/media/VideoPublisher.cpp new file mode 100644 index 0000000..fc40e38 --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/main/cpp/media/VideoPublisher.cpp @@ -0,0 +1,5 @@ +#include "../include/VideoPublisher.hpp" + +namespace acgist { + +} \ No newline at end of file diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/MainAbility.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/MainAbility.java new file mode 100644 index 0000000..3c077ff --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/MainAbility.java @@ -0,0 +1,16 @@ +package com.acgist.taoyao; + +import com.acgist.taoyao.slice.MainAbilitySlice; +import com.acgist.taoyao.slice.SettingAbilitySlice; +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; + +public class MainAbility extends Ability { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setMainRoute(MainAbilitySlice.class.getName()); + super.addActionRoute("main", MainAbilitySlice.class.getName()); + super.addActionRoute("setting", SettingAbilitySlice.class.getName()); + } +} diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/MediaAbility.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/MediaAbility.java new file mode 100644 index 0000000..10b493f --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/MediaAbility.java @@ -0,0 +1,43 @@ +package com.acgist.taoyao; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; +import ohos.rpc.IRemoteObject; +import ohos.hiviewdfx.HiLog; +import ohos.hiviewdfx.HiLogLabel; + +public class MediaAbility extends Ability { + + private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD001100, "Media"); + + @Override + public void onStart(Intent intent) { + HiLog.error(LABEL_LOG, "MediaAbility::onStart"); + super.onStart(intent); + } + + @Override + public void onBackground() { + super.onBackground(); + HiLog.info(LABEL_LOG, "MediaAbility::onBackground"); + } + + @Override + public void onStop() { + super.onStop(); + HiLog.info(LABEL_LOG, "MediaAbility::onStop"); + } + + @Override + public void onCommand(Intent intent, boolean restart, int startId) { + } + + @Override + public IRemoteObject onConnect(Intent intent) { + return null; + } + + @Override + public void onDisconnect(Intent intent) { + } +} \ No newline at end of file diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/TaoyaoApplication.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/TaoyaoApplication.java new file mode 100644 index 0000000..f345238 --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/TaoyaoApplication.java @@ -0,0 +1,16 @@ +package com.acgist.taoyao; + +import ohos.aafwk.ability.AbilityPackage; + +public class TaoyaoApplication extends AbilityPackage { + + static { + System.loadLibrary("taoyao"); + } + + @Override + public void onInitialize() { + super.onInitialize(); + } + +} diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/config/Config.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/config/Config.java new file mode 100644 index 0000000..469f4cb --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/config/Config.java @@ -0,0 +1,10 @@ +package com.acgist.taoyao.config; + +/** + * 配置 + * + * @author acgist + */ +public class Config { + +} diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/media/AudioPublisher.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/media/AudioPublisher.java new file mode 100644 index 0000000..66455bd --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/media/AudioPublisher.java @@ -0,0 +1,4 @@ +package com.acgist.taoyao.media; + +public class AudioPublisher { +} diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/media/MediaClient.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/media/MediaClient.java new file mode 100644 index 0000000..c3ea446 --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/media/MediaClient.java @@ -0,0 +1,7 @@ +package com.acgist.taoyao.media; + +/** + * 终端 + */ +public class MediaClient { +} diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/media/MediaRecorder.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/media/MediaRecorder.java new file mode 100644 index 0000000..b9b6d7b --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/media/MediaRecorder.java @@ -0,0 +1,4 @@ +package com.acgist.taoyao.media; + +public class MediaRecorder { +} diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/media/VideoPublisher.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/media/VideoPublisher.java new file mode 100644 index 0000000..47a6735 --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/media/VideoPublisher.java @@ -0,0 +1,4 @@ +package com.acgist.taoyao.media; + +public class VideoPublisher { +} diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/model/Header.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/model/Header.java new file mode 100644 index 0000000..53fa79e --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/model/Header.java @@ -0,0 +1,64 @@ +package com.acgist.taoyao.model; + +import java.io.Serializable; + +/** + * 消息头部 + * + * @author acgist + */ +public class Header implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 消息版本 + */ + private String v; + /** + * 消息标识 + */ + private Long id; + /** + * 信令标识 + */ + private String signal; + + @Override + public Header clone() { + return new Header(this.v, this.id, this.signal); + } + + public Header() { + } + + public Header(String v, Long id, String signal) { + this.v = v; + this.id = id; + this.signal = signal; + } + + public String getV() { + return v; + } + + public void setV(String v) { + this.v = v; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getSignal() { + return signal; + } + + public void setSignal(String signal) { + this.signal = signal; + } +} diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/model/Message.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/model/Message.java new file mode 100644 index 0000000..3207229 --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/model/Message.java @@ -0,0 +1,224 @@ +package com.acgist.taoyao.model; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +import com.acgist.taoyao.utils.JSONUtils; +import com.fasterxml.jackson.annotation.JsonIncludeProperties; + + +/** + * 消息 + * 接口、信令、媒体信令通用消息模型 + * + * @author acgist + */ +@JsonIncludeProperties(value = { "code", "message", "header", "body" }) +public class Message implements Cloneable, Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 状态编码 + */ + private String code; + /** + * 状态描述 + */ + private String message; + /** + * 消息头部 + */ + private Header header; + /** + * 消息主体 + */ + private Object body; + + /** + * @param code 状态编码 + */ + public void setCode(String code) { + this.code = code; + } + + /** + * @param code 状态编码 + */ + public void setCode(MessageCode code) { + this.setCode(code, null); + } + + /** + * @param code 状态编码 + * @param message 状态描述 + * + * @return this + */ + public Message setCode(MessageCode code, String message) { + this.code = code.getCode(); + this.message = message == null || message.isEmpty() ? code.getMessage() : message; + return this; + } + + /** + * @return 成功消息 + */ + public static final Message success() { + return success(null); + } + + /** + * @param body 消息主体 + * + * @return 成功消息 + */ + public static final Message success(Object body) { + final Message message = new Message(); + message.setCode(MessageCode.CODE_0000, null); + message.body = body; + return message; + } + + /** + * @return 失败消息 + */ + public static final Message fail() { + return fail(null, null, null); + } + + /** + * @param code 状态编码 + * + * @return 失败消息 + */ + public static final Message fail(MessageCode code) { + return fail(code, null, null); + } + + /** + * @param code 状态编码 + * @param body 消息主体 + * + * @return 失败消息 + */ + public static final Message fail(MessageCode code, Object body) { + return fail(code, null, body); + } + + /** + * @param message 状态描述 + * + * @return 失败消息 + */ + public static final Message fail(String message) { + return fail(null, message, null); + } + + /** + * @param message 状态描述 + * @param body 消息主体 + * + * @return 失败消息 + */ + public static final Message fail(String message, Object body) { + return fail(null, message, body); + } + + /** + * @param code 状态编码 + * @param message 状态描述 + * + * @return 失败消息 + */ + public static final Message fail(MessageCode code, String message) { + return fail(code, message, null); + } + + /** + * @param code 状态编码 + * @param message 状态描述 + * @param body 消息主体 + * + * @return 失败消息 + */ + public static final Message fail(MessageCode code, String message, Object body) { + final Message failMessage = new Message(); + failMessage.setCode(code == null ? MessageCode.CODE_9999 : code, message); + failMessage.body = body; + return failMessage; + } + + @Override + public Message clone() { + return new Message(this.code, this.message, this.header.clone(), this.body); + } + + /** + * 克隆消息排除消息主体 + * + * @return 克隆消息 + */ + public Message cloneWithoutBody() { + return new Message(this.code, this.message, this.header.clone(), null); + } + + /** + * @return Map消息主体 + */ + @SuppressWarnings({ "rawtypes", "unchecked" }) + public Map body() { + if(this.body instanceof Map) { + return (Map) this.body; + } else if(this.body == null) { + return new HashMap<>(); + } else { + throw MessageCodeException.of("信令主体类型错误:" + this.body); + } + } + + @Override + public String toString() { + return JSONUtils.toJSON(this); + } + + public Message() { + } + + public Message(String code, String message, Header header, Object body) { + this.code = code; + this.message = message; + this.header = header; + this.body = body; + } + + public String getCode() { + return code; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Header getHeader() { + return header; + } + + public void setHeader(Header header) { + this.header = header; + } + + public Object getBody() { + return body; + } + + public void setBody(Object body) { + this.body = body; + } + +} diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/model/MessageCode.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/model/MessageCode.java new file mode 100644 index 0000000..ec63d2e --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/model/MessageCode.java @@ -0,0 +1,99 @@ +package com.acgist.taoyao.model; + +/** + * 状态编码 + * + * 1xxx = 前置错误 + * 2xxx = 内部错误 + * 3xxx = 请求错误 + * 9999 = 未知错误 + * + * @author acgist + */ +public enum MessageCode { + + // 成功 + CODE_0000("0000", 200, "成功"), + // 1xxx + CODE_1000("1000", 404, "未知接口"), + CODE_1001("1001", 400, "上次请求没有完成"), + CODE_1002("1002", 400, "数据格式错误"), + CODE_1003("1003", 400, "验签失败"), + // 2xxx + CODE_2000("2000", 500, "服务错误"), + CODE_2001("2001", 504, "服务超时"), + // 3xxx + CODE_3400("3400", 400, "请求错误"), + CODE_3401("3401", 401, "没有授权"), + CODE_3403("3403", 403, "请求拒绝"), + CODE_3404("3404", 404, "资源失效"), + CODE_3405("3405", 405, "请求方法错误"), + CODE_3406("3406", 406, "请求不可接受"), + CODE_3415("3415", 415, "请求资源类型错误"), + CODE_3500("3500", 500, "系统异常"), + CODE_3502("3502", 502, "服务无效"), + CODE_3503("3503", 503, "服务正在维护"), + CODE_3504("3504", 504, "服务超时"), + // 9999 + CODE_9999("9999", 500, "未知错误"); + + /** + * HTTP状态编码前缀 + */ + private static final String HTTP_STATUS = "3"; + + /** + * 状态编码 + */ + private final String code; + /** + * 状态数值 + */ + private final Integer status; + /** + * 状态描述 + */ + private final String message; + + private MessageCode(String code, Integer status, String message) { + this.code = code; + this.status = status; + this.message = message; + } + + /** + * @param code 状态编码 + * + * @return 状态编码 + */ + public static final MessageCode of(String code) { + final MessageCode[] values = MessageCode.values(); + for (MessageCode value : values) { + if (value.code.equals(code)) { + return value; + } + } + return CODE_9999; + } + + /** + * @param status HTTP Status + * + * @return 状态编码 + */ + public static final MessageCode of(Integer status) { + return of(HTTP_STATUS + status); + } + + public String getCode() { + return code; + } + + public Integer getStatus() { + return status; + } + + public String getMessage() { + return message; + } +} diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/model/MessageCodeException.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/model/MessageCodeException.java new file mode 100644 index 0000000..be73ba0 --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/model/MessageCodeException.java @@ -0,0 +1,75 @@ +package com.acgist.taoyao.model; + +import java.util.Objects; + +/** + * 状态编码异常 + * + * @author acgist + */ +public class MessageCodeException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + /** + * 状态编码 + */ + private final MessageCode code; + + /** + * @param message 异常消息 + * + * @return 状态编码异常 + */ + public static final MessageCodeException of(String message) { + return of(null, null, message); + } + + /** + * @param t 异常 + * @param message 异常消息 + * + * @return 状态编码异常 + */ + public static final MessageCodeException of(Throwable t, String message) { + return of(t, null, message); + } + + /** + * @param code 状态编码 + * @param message 异常消息 + * + * @return 状态编码异常 + */ + public static final MessageCodeException of(MessageCode code, String message) { + return of(null, code, message); + } + + /** + * @param t 异常 + * @param code 状态编码 + * @param message 异常消息 + * + * @return 状态编码异常 + */ + public static final MessageCodeException of(Throwable t, MessageCode code, String message) { + if(code == null) { + code = MessageCode.CODE_9999; + } + if(message == null || message.isEmpty()) { + message = Objects.isNull(t) ? code.getMessage() : t.getMessage(); + } + return new MessageCodeException(t, code, message); + } + + /** + * @param t 异常 + * @param code 状态编码 + * @param message 异常消息 + */ + public MessageCodeException(Throwable t, MessageCode code, String message) { + super(message, t); + this.code = code; + } + +} diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/signal/Taoyao.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/signal/Taoyao.java new file mode 100644 index 0000000..212e32b --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/signal/Taoyao.java @@ -0,0 +1,319 @@ +package com.acgist.taoyao.signal; + +import com.acgist.taoyao.model.Header; +import com.acgist.taoyao.model.Message; +import com.acgist.taoyao.utils.CloseableUtils; +import com.acgist.taoyao.utils.JSONUtils; + +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.spec.SecretKeySpec; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.nio.ByteBuffer; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.time.LocalDateTime; +import java.util.Base64; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +/** + * 桃夭信令 + * + * @author acgist + */ +public class Taoyao { + +// private static final HiLogLabel label = new HiLogLabel(HiLog.LOG_APP, 0, "[信令]"); + + private static final ExecutorService EXECUTOR = Executors.newFixedThreadPool(8); + + /** + * 端口 + */ + private int port; + /** + * 地址 + */ + private String host; + /** + * Socket + */ + private Socket socket; + private InputStream input; + private OutputStream output; + private String username; + private String password; + private boolean close; + /** + * 是否连接 + */ + private boolean connect; + private final Cipher encrypt; + private final Cipher decrypt; + + public Taoyao(int port, String host, String algo, String secret) { + this.port = port; + this.host = host; + this.close = false; + this.connect = false; + if(algo == null || algo.isEmpty() || algo.equals("PLAINTEXT")) { + // 明文 + this.encrypt = null; + this.decrypt = null; + } else { + this.encrypt = this.buildCipher(Cipher.ENCRYPT_MODE, algo, secret); + this.decrypt = this.buildCipher(Cipher.DECRYPT_MODE, algo, secret); + } + EXECUTOR.submit(this::read); + } + + private Cipher buildCipher(int mode, String name, String secret) { + try { + final String algo = name.equals("DES") ? "DES/ECB/PKCS5Padding" : "AES/ECB/PKCS5Padding"; + final Cipher cipher = Cipher.getInstance(algo); + cipher.init(mode, new SecretKeySpec(Base64.getMimeDecoder().decode(secret), name)); + return cipher; + } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException e) { + // TODO:日志 + } + return null; + } + + /** + * 连接信令 + */ + public void connect() { + this.close(); +// HiLog.debug(this.label, "连接信令:%s:%d", this.host, this.port); + this.socket = new Socket(); + try { +// socket.setSoTimeout(5000); + this.socket.connect(new InetSocketAddress(this.host, this.port), 5000); + if(this.socket.isConnected()) { + this.input = this.socket.getInputStream(); + this.output = this.socket.getOutputStream(); + this.register(); + synchronized (this) { + this.notifyAll(); + } + } + } catch (Exception e) { + e.printStackTrace(); +// HiLog.error(this.label, "连接信令异常:%s:%d", this.host, this.port); + } + } + + private void read() { + int length = 0; + short messageLength = 0; + final byte[] bytes = new byte[1024]; + final ByteBuffer buffer = ByteBuffer.allocateDirect(16 * 1024); + while(!this.close) { + try { + while(this.input == null) { + this.connect(); + synchronized (this) { + this.wait(5000); + } + } + while ((length = this.input.read(bytes)) >= 0) { + buffer.put(bytes, 0, length); + while (buffer.position() > 0) { + if (messageLength <= 0) { + if (buffer.position() < Short.BYTES) { + // 不够消息长度 + break; + } else { + buffer.flip(); + messageLength = buffer.getShort(); + buffer.compact(); + if (messageLength > 16 * 1024) { + throw new RuntimeException("超过最大数据大小:" + messageLength); + } + } + } else { + if (buffer.position() < messageLength) { + // 不够消息长度 + break; + } else { + final byte[] message = new byte[messageLength]; + messageLength = 0; + buffer.flip(); + buffer.get(message); + buffer.compact(); + final String content = new String(this.decrypt.doFinal(message)); + EXECUTOR.submit(() -> { + Taoyao.this.on(content); + }); + } + } + } + } + } catch (Exception e) { + e.printStackTrace(); + this.connect(); + // TODO:日志 +// log.error("读取异常", e); + } + } + } + + /** + * @param message 消息 + * + * @return 加密消息 + */ + private byte[] encrypt(Message message) { + final byte[] bytes = message.toString().getBytes(); + if(this.encrypt != null) { + try { + // 加密 + final byte[] encryptBytes = this.encrypt.doFinal(bytes); + // 发送 + final ByteBuffer buffer = ByteBuffer.allocateDirect(Short.BYTES + encryptBytes.length); + buffer.putShort((short) encryptBytes.length); + buffer.put(encryptBytes); + buffer.flip(); + final byte[] sendBytes = new byte[buffer.capacity()]; + buffer.get(sendBytes); + return sendBytes; + } catch (IllegalBlockSizeException | BadPaddingException e) { + e.printStackTrace(); +// log.error("加密异常:{}", message); + } + } + return bytes; + } + + public void push(Message message) { + if(this.output == null) { + return; + } + try { + this.output.write(this.encrypt(message)); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public Message request(Message request) { + return null; + } + + private void register() { + final Header header = new Header(); + this.push(this.buildMessage( + "client::register", + "clientId", "harmony", + "name", "harmony", + "clientType", "camera", + "username", "taoyao", + "password","taoyao" + )); + } + + private void close() { + this.connect = false; + CloseableUtils.close(this.input); + CloseableUtils.close(this.output); + CloseableUtils.close(this.socket); + this.input = null; + this.output = null; + this.socket = null; + } + + private void shutdown() { + this.close(); + this.close = true; + EXECUTOR.shutdownNow(); + } + + /** + * 当前索引 + */ + private int index; + /** + * 当前终端索引 + */ + private int clientIndex = 99999; + + private static final int MAX_INDEX = 999; + + public long buildId() { + int index; + synchronized (this) { + if (++this.index > MAX_INDEX) { + this.index = 0; + } + index = this.index; + } + final LocalDateTime time = LocalDateTime.now(); + return + 100000000000000L * time.getDayOfMonth() + + 1000000000000L * time.getHour() + + 10000000000L * time.getMinute() + + 100000000L * time.getSecond() + + 1000000L * this.clientIndex + + index; + } + + private String version; + + public Message buildMessage(String signal, Object ... args) { + final Map map = new HashMap<>(); + if(args != null) { + for (int index = 0; index < args.length; index+=2) { + map.put(args[index], args[index + 1]); + } + } + return this.buildMessage(signal, map); + } + + public Message buildMessage(String signal, Object body) { + final Header header = new Header(); + header.setV(this.version == null ? "1.0.0" : this.version); + header.setId(this.buildId()); + header.setSignal(signal); + final Message message = new Message(); + message.setHeader(header); + message.setBody(body == null ? new HashMap<>() : body); + return message; + } + + private void on(String content) { + // TODO:日志 +// log.debug("收到消息:{}", new String(this.decrypt.doFinal(message))); + System.out.println(content); + final Message message = JSONUtils.toJava(content, Message.class); + if(message == null) { + return; + } + final Header header = message.getHeader(); + if(header == null) { + return; + } + final Map body = message.body(); + switch (header.getSignal()) { + case "client::register": + this.register(message, body); + break; + default: + break; + } + } + + private void register(Message message, Map body) { + final Integer index = (Integer) body.get("index"); + this.clientIndex = index; + System.out.println(clientIndex); + } + +} diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/slice/MainAbilitySlice.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/slice/MainAbilitySlice.java new file mode 100644 index 0000000..ab52d0d --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/slice/MainAbilitySlice.java @@ -0,0 +1,65 @@ +package com.acgist.taoyao.slice; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.agp.colors.RgbColor; +import ohos.agp.components.AttrHelper; +import ohos.agp.components.Button; +import ohos.agp.components.ComponentContainer.LayoutConfig; +import ohos.agp.components.DirectionalLayout; +import ohos.agp.components.Text; +import ohos.agp.components.element.ShapeElement; +import ohos.agp.utils.Color; +import ohos.media.player.Player; + +import java.io.FileDescriptor; +import java.io.FileInputStream; + +public class MainAbilitySlice extends AbilitySlice { + // Load the 'native-lib' library on application startup. + + private final DirectionalLayout layout = new DirectionalLayout(this); + + @Override + public void onStart(Intent intent) { + super.onStart(intent); + LayoutConfig config = new LayoutConfig(LayoutConfig.MATCH_PARENT, LayoutConfig.MATCH_PARENT); + layout.setLayoutConfig(config); + layout.setAlignment(17); + ShapeElement element = new ShapeElement(); + element.setShape(ShapeElement.RECTANGLE); + element.setRgbColor(new RgbColor(255, 255, 255)); + layout.setBackground(element); + Text text = new Text(this); + text.setText(stringFromJNI()); + text.setTextColor(Color.BLACK); + text.setTextSize(AttrHelper.vp2px(26, this)); + layout.addComponent(text); + Button button = new Button(this); + button.setText("设置"); + button.setTextSize(AttrHelper.vp2px(26, this)); + button.setClickedListener(listener -> super.present(new SettingAbilitySlice(), new Intent())); + layout.addComponent(button); + super.setUIContent(layout); + } + + @Override + public void onActive() { + super.onActive(); + } + + @Override + public void onForeground(Intent intent) { + super.onForeground(intent); + // 打开预览 + } + + @Override + protected void onBackground() { + super.onBackground(); + // 掐断预览 + } + + public native String stringFromJNI(); + +} diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/slice/SettingAbilitySlice.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/slice/SettingAbilitySlice.java new file mode 100644 index 0000000..c323977 --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/slice/SettingAbilitySlice.java @@ -0,0 +1,59 @@ +package com.acgist.taoyao.slice; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.agp.colors.RgbColor; +import ohos.agp.components.AttrHelper; +import ohos.agp.components.Button; +import ohos.agp.components.ComponentContainer.LayoutConfig; +import ohos.agp.components.DirectionalLayout; +import ohos.agp.components.Text; +import ohos.agp.components.element.ShapeElement; +import ohos.agp.utils.Color; + +public class SettingAbilitySlice extends AbilitySlice { + // Load the 'native-lib' library on application startup. + + private final DirectionalLayout layout = new DirectionalLayout(this); + + @Override + public void onStart(Intent intent) { + super.onStart(intent); + LayoutConfig config = new LayoutConfig(LayoutConfig.MATCH_PARENT, LayoutConfig.MATCH_PARENT); + layout.setLayoutConfig(config); + layout.setAlignment(17); + ShapeElement element = new ShapeElement(); + element.setShape(ShapeElement.RECTANGLE); + element.setRgbColor(new RgbColor(255, 255, 255)); + layout.setBackground(element); + Text text = new Text(this); + text.setText("1234"); + text.setTextColor(Color.BLACK); + text.setTextSize(AttrHelper.vp2px(26, this)); + layout.addComponent(text); + Button button = new Button(this); + button.setText("保存"); + button.setTextSize(AttrHelper.vp2px(26, this)); + button.setClickedListener(listener -> super.present(new MainAbilitySlice(), new Intent())); + layout.addComponent(button); + super.setUIContent(layout); + } + + @Override + public void onActive() { + super.onActive(); + } + + @Override + public void onForeground(Intent intent) { + super.onForeground(intent); + // 打开预览 + } + + @Override + protected void onBackground() { + super.onBackground(); + // 掐断预览 + } + +} diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/utils/CloseableUtils.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/utils/CloseableUtils.java new file mode 100644 index 0000000..af2e1e6 --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/utils/CloseableUtils.java @@ -0,0 +1,45 @@ +package com.acgist.taoyao.utils; + +import java.io.Closeable; + +/** + * 关闭资源工具 + * + * @author acgist + */ +public final class CloseableUtils { + + private CloseableUtils() { + } + + /** + * 关闭资源 + * + * @param closeable 资源 + */ + public static final void close(Closeable closeable) { + try { + if(closeable != null) { + closeable.close(); + } + } catch (Exception e) { + // TODO:日志 + } + } + + /** + * 关闭资源 + * + * @param closeable 资源 + */ + public static final void close(AutoCloseable closeable) { + try { + if(closeable != null) { + closeable.close(); + } + } catch (Exception e) { + // TODO:日志 + } + } + +} diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/utils/DateUtils.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/utils/DateUtils.java new file mode 100644 index 0000000..936a50d --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/utils/DateUtils.java @@ -0,0 +1,258 @@ +package com.acgist.taoyao.utils; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.Date; +import java.util.Objects; + +/** + * 日期工具 + * + * @author acgist + */ +public final class DateUtils { + + private DateUtils() { + } + + /** + * 日期 + * + * @author acgist + */ + public static enum DateStyle { + + YYMMDD("yyMMdd"), + YYYYMMDD("yyyyMMdd"), + YY_MM_DD("yy-MM-dd"), + YYYY_MM_DD("yyyy-MM-dd"); + + /** + * 格式 + */ + private final String format; + /** + * 格式工具 + */ + private final DateTimeFormatter dateTimeFormatter; + + private DateStyle(String format) { + this.format = format; + this.dateTimeFormatter = DateTimeFormatter.ofPattern(format); + } + + public String getFormat() { + return this.format; + } + + public DateTimeFormatter getDateTimeFormatter() { + return this.dateTimeFormatter; + } + } + + /** + * 时间 + * + * @author acgist + */ + public static enum TimeStyle { + + HH24("HH"), + HH24MM("HHmm"), + HH24_MM("HH:mm"), + HH24MMSS("HHmmss"), + HH24_MM_SS("HH:mm:ss"), + HH24MMSSSSS("HHmmssSSS"), + HH24_MM_SS_SSS("HH:mm:ss.SSS"); + + /** + * 格式 + */ + private final String format; + /** + * 格式工具 + */ + private final DateTimeFormatter dateTimeFormatter; + + private TimeStyle(String format) { + this.format = format; + this.dateTimeFormatter = DateTimeFormatter.ofPattern(format); + } + public String getFormat() { + return this.format; + } + + public DateTimeFormatter getDateTimeFormatter() { + return this.dateTimeFormatter; + } + + } + + /** + * 日期时间 + * + * @author acgist + */ + public static enum DateTimeStyle { + + // YYYY + YYYYMMDD_HH24_MM("yyyyMMdd HH:mm"), + YYYY_MM_DD_HH24_MM("yyyy-MM-dd HH:mm"), + YYYYMMDDHH24MMSS("yyyyMMddHHmmss"), + YYYYMMDDHH24MMSSSSS("yyyyMMddHHmmssSSS"), + YYYYMMDD_HH24_MM_SS("yyyyMMdd HH:mm:ss"), + YYYYMMDD_HH24_MM_SS_SSS("yyyyMMdd HH:mm:ss.SSS"), + YYYY_MM_DD_HH24_MM_SS("yyyy-MM-dd HH:mm:ss"), + YYYY_MM_DD_HH24_MM_SS_SSS("yyyy-MM-dd HH:mm:ss.SSS"), + // YY + YYMMDD_HH24_MM("yyMMdd HH:mm"), + YY_MM_DD_HH24_MM("yy-MM-dd HH:mm"), + YYMMDDHH24MMSS("yyMMddHHmmss"), + YYMMDDHH24MMSSSSS("yyMMddHHmmssSSS"), + YYMMDD_HH24_MM_SS("yyMMdd HH:mm:ss"), + YYMMDD_HH24_MM_SS_SSS("yyMMdd HH:mm:ss.SSS"), + YY_MM_DD_HH24_MM_SS("yy-MM-dd HH:mm:ss"), + YY_MM_DD_HH24_MM_SS_SSS("yy-MM-dd HH:mm:ss.SSS"), + // ISO + YY_MM_DD_HH24_MM_SS_ISO("yy-MM-dd'T'HH:mm:ss"), + YY_MM_DD_HH24_MM_SS_SSS_ISO("yy-MM-dd'T'HH:mm:ss.SSS"), + YYYY_MM_DD_HH24_MM_SS_ISO("yyyy-MM-dd'T'HH:mm:ss"), + YYYY_MM_DD_HH24_MM_SS_SSS_ISO("yyyy-MM-dd'T'HH:mm:ss.SSS"), + // UTC + YY_MM_DD_HH24_MM_SS_UTC("yy-MM-dd'T'HH:mm:ss'Z'"), + YY_MM_DD_HH24_MM_SS_SSS_UTC("yy-MM-dd'T'HH:mm:ss.SSS'Z'"), + YYYY_MM_DD_HH24_MM_SS_UTC("yyyy-MM-dd'T'HH:mm:ss'Z'"), + YYYY_MM_DD_HH24_MM_SS_SSS_UTC("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + + /** + * 格式 + */ + private final String format; + /** + * 格式工具 + */ + private final DateTimeFormatter dateTimeFormatter; + + private DateTimeStyle(String format) { + this.format = format; + this.dateTimeFormatter = DateTimeFormatter.ofPattern(format); + } + public String getFormat() { + return this.format; + } + + public DateTimeFormatter getDateTimeFormatter() { + return this.dateTimeFormatter; + } + + } + + /** + * 生成时间戳 + * + * @return 时间戳 + * + * @see #buildTime(LocalDateTime) + */ + public static final String buildTime() { + return buildTime(LocalDateTime.now()); + } + + /** + * 生成时间戳 + * + * @param localDateTime 日期时间 + * + * @return 时间戳 + */ + public static final String buildTime(LocalDateTime localDateTime) { + if (Objects.isNull(localDateTime)) { + return buildTime(); + } + return DateTimeStyle.YYYYMMDDHH24MMSS.getDateTimeFormatter().format(localDateTime); + } + + /** + * 日期转化 + * + * @param date Date + * + * @return LocalDate + */ + public static final LocalDate toLocalDate(Date date) { + return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + } + + /** + * 日期转化 + * + * @param date Date + * + * @return LocalTime + */ + public static final LocalTime toLocalTime(Date date) { + return date.toInstant().atZone(ZoneId.systemDefault()).toLocalTime(); + } + + /** + * 日期转化 + * + * @param date Date + * + * @return LocalDateTime + */ + public static final LocalDateTime toLocalDateTime(Date date) { + return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); + } + + /** + * 转换毫秒 + * + * @param localDateTime LocalDateTime + * + * @return 毫秒 + */ + public static final long toMilli(LocalDateTime localDateTime) { + return localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); + } + + /** + * 格式化日期 + * + * @param localDate LocalDate + * @param format 格式 + * + * @return 日期字符串 + */ + public static String format(LocalDate localDate, DateStyle format) { + return localDate != null && format != null ? format.getDateTimeFormatter().format(localDate) : null; + } + + /** + * 格式化时间 + * + * @param localTime LocalTime + * @param format 格式 + * + * @return 时间字符串 + */ + public static String format(LocalTime localTime, TimeStyle format) { + return localTime != null && format != null ? format.getDateTimeFormatter().format(localTime) : null; + } + + /** + * 格式化日期时间 + * + * @param localDateTime LocalDateTime + * @param format 格式 + * + * @return 日期时间字符串 + */ + public static String format(LocalDateTime localDateTime, DateTimeStyle format) { + return localDateTime != null && format != null ? format.getDateTimeFormatter().format(localDateTime) : null; + } + +} diff --git a/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/utils/JSONUtils.java b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/utils/JSONUtils.java new file mode 100644 index 0000000..0eac72f --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/main/java/com/acgist/taoyao/utils/JSONUtils.java @@ -0,0 +1,225 @@ +package com.acgist.taoyao.utils; + +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.Module; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer; +import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; +import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer; + +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.*; + +/** + * JSON工具 + * + * @author acgist + */ +public final class JSONUtils { + + private JSONUtils() { + } + + /** + * Mapper(线程安全) + */ + private static final ObjectMapper MAPPER = buildMapper(); + + /** + * Java转JSON + * + * @param object Java + * + * @return JSON + */ + public static final String toJSON(Object object) { + if (Objects.isNull(object)) { + return null; + } + try { + return MAPPER.writeValueAsString(object); + } catch (JsonProcessingException e) { + throw new RuntimeException("Java转JSON失败:" + object, e); + } + } + + /** + * JSON转Java + * + * @param Java类型 + * + * @param json JSON + * + * @return Java + */ + public static final T toJava(String json) { + if (Objects.isNull(json)) { + return null; + } + try { + return MAPPER.readValue(json, new TypeReference() { + }); + } catch (IOException e) { + throw new RuntimeException("JSON转Java失败:" + json, e); + } + } + + /** + * JSON转Java + * + * @param Java类型 + * + * @param json JSON + * @param clazz Java类型 + * + * @return Java + */ + public static final T toJava(String json, Class clazz) { + if (Objects.isNull(json) || Objects.isNull(clazz)) { + return null; + } + try { + return MAPPER.readValue(json, clazz); + } catch (IOException e) { + throw new RuntimeException("JSON转Java失败:" + json, e); + } + } + + /** + * JSON转Java + * + * @param Java类型 + * + * @param json JSON + * @param type Java类型 + * + * @return Java + */ + public static final T toJava(String json, TypeReference type) { + if (Objects.isNull(json) || Objects.isNull(type)) { + return null; + } + try { + return MAPPER.readValue(json, type); + } catch (IOException e) { + throw new RuntimeException("JSON转Java失败:" + json, e); + } + } + + /** + * JSON转Map + * + * @param K类型 + * @param V类型 + * + * @param json JSON + * + * @return Map + */ + public static final Map toMap(String json) { + if (Objects.isNull(json)) { + return new HashMap<>(); + } + try { + return MAPPER.readValue(json, new TypeReference>() { + }); + } catch (IOException e) { + throw new RuntimeException("JSON转Map失败:" + json, e); + } + } + + /** + * JSON转List + * + * @param 元素类型 + * + * @param json JSON + * + * @return List + */ + public static final List toList(String json) { + if (Objects.isNull(json)) { + return new ArrayList<>(); + } + try { + return MAPPER.readValue(json, new TypeReference>() { + }); + } catch (IOException e) { + throw new RuntimeException("JSON转List失败:" + json, e); + } + } + + /** + * JSON转List + * + * @param 元素类型 + * + * @param json JSON + * @param clazz 类型 + * + * @return List + */ + public static final List toList(String json, Class clazz) { + if (Objects.isNull(json)) { + return new ArrayList<>(); + } + try { + return MAPPER.readValue(json, new TypeReference>() { + }); + } catch (IOException e) { + throw new RuntimeException("JSON转List失败:" + json, e); + } + } + + /** + * @return Mapper + */ + public static final ObjectMapper buildMapper() { + final ObjectMapper mapper = new ObjectMapper(); + return mapper + .setTimeZone(TimeZone.getDefault()) + .setDateFormat(new SimpleDateFormat(DateUtils.DateTimeStyle.YYYY_MM_DD_HH24_MM_SS.getFormat())) + .registerModules(buildCustomModule(), buildJavaTimeModule()) + .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS) + .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .setSerializationInclusion(Include.NON_NULL); + } + + /** + * @return Java类型转换模块 + */ + private static final Module buildCustomModule() { + final SimpleModule customModule = new SimpleModule("CustomModule"); + // 注意不能转换Long类型数据:请求数据类型变化 +// customModule.addSerializer(Long.class, ToStringSerializer.instance); + return customModule; + } + + /** + * @return Java时间类型模块 + */ + private static final JavaTimeModule buildJavaTimeModule() { + final JavaTimeModule javaTimeModule = new JavaTimeModule(); + javaTimeModule.addSerializer(LocalTime.class, new LocalTimeSerializer(DateUtils.TimeStyle.HH24_MM_SS.getDateTimeFormatter())); + javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateUtils.DateStyle.YYYY_MM_DD.getDateTimeFormatter())); + javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateUtils.DateTimeStyle.YYYY_MM_DD_HH24_MM_SS.getDateTimeFormatter())); + javaTimeModule.addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateUtils.TimeStyle.HH24_MM_SS.getDateTimeFormatter())); + javaTimeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateUtils.DateStyle.YYYY_MM_DD.getDateTimeFormatter())); + javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateUtils.DateTimeStyle.YYYY_MM_DD_HH24_MM_SS.getDateTimeFormatter())); + return javaTimeModule; + } + +} diff --git a/taoyao-client-harmony/taoyao/client/src/main/resources/base/element/integer.json b/taoyao-client-harmony/taoyao/client/src/main/resources/base/element/integer.json new file mode 100644 index 0000000..b2e5a25 --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/main/resources/base/element/integer.json @@ -0,0 +1,8 @@ +{ + "integer": [ + { + "name": "timeout", + "value": 5000 + } + ] +} \ No newline at end of file diff --git a/taoyao-client-harmony/taoyao/client/src/main/resources/base/element/string.json b/taoyao-client-harmony/taoyao/client/src/main/resources/base/element/string.json new file mode 100644 index 0000000..2a2049b --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/main/resources/base/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "main_label", + "value": "桃夭" + }, + { + "name": "main_description", + "value": "桃夭鸿蒙终端前台页面" + }, + { + "name": "media_description", + "value": "桃夭鸿蒙终端媒体服务" + }, + { + "name": "encryptAlgo", + "value": "DES" + }, + { + "name": "encryptSecret", + "value": "2SPWy+TF1zM=" + } + ] +} \ No newline at end of file diff --git a/taoyao-client-harmony/taoyao/client/src/main/resources/base/media/icon.png b/taoyao-client-harmony/taoyao/client/src/main/resources/base/media/icon.png new file mode 100644 index 0000000..ea915d0 Binary files /dev/null and b/taoyao-client-harmony/taoyao/client/src/main/resources/base/media/icon.png differ diff --git a/taoyao-client-harmony/taoyao/client/src/ohosTest/java/com/acgist/taoyao/ExampleOhosTest.java b/taoyao-client-harmony/taoyao/client/src/ohosTest/java/com/acgist/taoyao/ExampleOhosTest.java new file mode 100644 index 0000000..ecec392 --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/ohosTest/java/com/acgist/taoyao/ExampleOhosTest.java @@ -0,0 +1,14 @@ +package com.acgist.taoyao; + +import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ExampleOhosTest { + @Test + public void testBundleName() { + final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); + assertEquals("com.acgist.taoyao", actualBundleName); + } +} \ No newline at end of file diff --git a/taoyao-client-harmony/taoyao/client/src/test/java/com/acgist/taoyao/ExampleTest.java b/taoyao-client-harmony/taoyao/client/src/test/java/com/acgist/taoyao/ExampleTest.java new file mode 100644 index 0000000..9cdb765 --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/test/java/com/acgist/taoyao/ExampleTest.java @@ -0,0 +1,9 @@ +package com.acgist.taoyao; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/taoyao-client-harmony/taoyao/client/src/test/java/com/acgist/taoyao/TaoyaoTest.java b/taoyao-client-harmony/taoyao/client/src/test/java/com/acgist/taoyao/TaoyaoTest.java new file mode 100644 index 0000000..da1e685 --- /dev/null +++ b/taoyao-client-harmony/taoyao/client/src/test/java/com/acgist/taoyao/TaoyaoTest.java @@ -0,0 +1,17 @@ +package com.acgist.taoyao; + +import com.acgist.taoyao.model.Message; +import com.acgist.taoyao.signal.Taoyao; +import ohos.hiviewdfx.HiLog; +import org.junit.Test; + +public class TaoyaoTest { + + @Test + public void test() throws InterruptedException { + final Taoyao taoyao = new Taoyao(9999, "localhost", "DES", "2SPWy+TF1zM="); + taoyao.connect(); + Thread.sleep(Long.MAX_VALUE); + } + +} diff --git a/taoyao-client-harmony/taoyao/gradle.properties b/taoyao-client-harmony/taoyao/gradle.properties new file mode 100644 index 0000000..e69de29 diff --git a/taoyao-client-harmony/taoyao/gradle/wrapper/gradle-wrapper.properties b/taoyao-client-harmony/taoyao/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..3622263 --- /dev/null +++ b/taoyao-client-harmony/taoyao/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,2 @@ +#Sun Mar 19 12:32:25 CST 2023 +distributionUrl=https\://repo.huaweicloud.com/gradle/gradle-7.3-bin.zip diff --git a/taoyao-client-harmony/taoyao/include/AudioPublisher.hpp b/taoyao-client-harmony/taoyao/include/AudioPublisher.hpp deleted file mode 100644 index 90b3fbf..0000000 --- a/taoyao-client-harmony/taoyao/include/AudioPublisher.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -/** - * 音频推送器 - */ -namespace acgist { - -} \ No newline at end of file diff --git a/taoyao-client-harmony/taoyao/include/Taoyao.hpp b/taoyao-client-harmony/taoyao/include/Taoyao.hpp deleted file mode 100644 index 396bad6..0000000 --- a/taoyao-client-harmony/taoyao/include/Taoyao.hpp +++ /dev/null @@ -1,96 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#define BUFFER_SIZE 8092 - -namespace acgist { - -/** - * 信令 - */ -class Taoyao { -private: - // 端口 - int port; - // 地址 - std::string address; - // 通道 - int socketChannel; - // 接收线程 - std::thread acceptThread; - // 超时 - struct timeval timeout; - // 地址 - struct sockaddr_in serverAddress; -private: - // 当前索引 - int index = 0; - // 最大索引 - int maxIndex = 999; - // 终端索引 - int clientIndex = 99999; - // 索引互斥 - std::mutex indexMutex; -public: - /** - * @param port 端口 - * @param address 地址 - * @param timeout 超时 - */ - Taoyao(int port, std::string address, int timeout); - /** - * - */ - virtual ~Taoyao(); -private: - /** - * 生成ID - */ - long long buildId(); - /** - * @param signal 信令标识 - * @param body 消息主体 - * @param id 消息ID - * @param v 消息版本 - * - * @returns 信令消息 - */ - std::string buildMessage(std::string signal, json body, long long id, std::string v); - /** - * 接收消息 - */ - void acceptSignal(); -public: - /** - * 连接信令 - */ - void connectSignal(); - /** - * 推送消息 - */ - void push(std::string message); - /** - * 请求消息 - */ - // void request(std::string message); - /** - * 关闭信令 - */ - void closeSignal(); -}; - -} \ No newline at end of file diff --git a/taoyao-client-harmony/taoyao/package.json b/taoyao-client-harmony/taoyao/package.json new file mode 100644 index 0000000..0db3279 --- /dev/null +++ b/taoyao-client-harmony/taoyao/package.json @@ -0,0 +1,3 @@ +{ + +} diff --git a/taoyao-client-harmony/taoyao/settings.gradle b/taoyao-client-harmony/taoyao/settings.gradle new file mode 100644 index 0000000..04de2bc --- /dev/null +++ b/taoyao-client-harmony/taoyao/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'taoyao' +include ':client' \ No newline at end of file diff --git a/taoyao-client-harmony/taoyao/src/main.cpp b/taoyao-client-harmony/taoyao/src/main.cpp deleted file mode 100644 index 4c11003..0000000 --- a/taoyao-client-harmony/taoyao/src/main.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include "../include/main.hpp" - -using std::cout; -using std::endl; - -int main(const int argc, const char **argv) { - cout << "测试" << endl; - return 0; -} diff --git a/taoyao-client-harmony/taoyao/src/media/AudioPublisher.cpp b/taoyao-client-harmony/taoyao/src/media/AudioPublisher.cpp deleted file mode 100644 index 68ab873..0000000 --- a/taoyao-client-harmony/taoyao/src/media/AudioPublisher.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "../../include/AudioPublisher.hpp" - -namespace acgist { - -} \ No newline at end of file diff --git a/taoyao-client-harmony/taoyao/src/media/MediaClient.cpp b/taoyao-client-harmony/taoyao/src/media/MediaClient.cpp deleted file mode 100644 index 8a4fc03..0000000 --- a/taoyao-client-harmony/taoyao/src/media/MediaClient.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "../../include/MediaClient.hpp" - -namespace acgist { - -} \ No newline at end of file diff --git a/taoyao-client-harmony/taoyao/src/media/MediaRecorder.cpp b/taoyao-client-harmony/taoyao/src/media/MediaRecorder.cpp deleted file mode 100644 index 81ef505..0000000 --- a/taoyao-client-harmony/taoyao/src/media/MediaRecorder.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "../../include/MediaRecorder.hpp" - -namespace acgist { - -} \ No newline at end of file diff --git a/taoyao-client-harmony/taoyao/src/media/VideoPublisher.cpp b/taoyao-client-harmony/taoyao/src/media/VideoPublisher.cpp deleted file mode 100644 index b806c48..0000000 --- a/taoyao-client-harmony/taoyao/src/media/VideoPublisher.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "../../include/VideoPublisher.hpp" - -namespace acgist { - -} \ No newline at end of file diff --git a/taoyao-client-harmony/taoyao/src/signal/Taoyao.cpp b/taoyao-client-harmony/taoyao/src/signal/Taoyao.cpp deleted file mode 100644 index 0ca1fdb..0000000 --- a/taoyao-client-harmony/taoyao/src/signal/Taoyao.cpp +++ /dev/null @@ -1,109 +0,0 @@ -#include "../../include/Taoyao.hpp" - -namespace acgist { - -Taoyao::Taoyao(int port, std::string address, int timeout = 5) { - this->port = port; - this->address = address; - this->socketChannel = 0; - this->timeout = {timeout, 0}; - memset(&this->serverAddress, 0, sizeof(this->serverAddress)); - this->serverAddress.sin_family = AF_INET; - this->serverAddress.sin_port = htons(this->port); - this->serverAddress.sin_addr.s_addr = inet_addr(this->address.c_str()); - // 接收线程 - this->acceptThread = std::thread(&acgist::Taoyao::acceptSignal, this); -} - -Taoyao::~Taoyao() { -} - -long long Taoyao::buildId() { - this->indexMutex.lock(); - int index = this->index; - if (++index > this->maxIndex) { - index = 0; - } - this->index = index; - this->indexMutex.unlock(); - time_t curtime; - time(&curtime); - tm *pCurtime = localtime(&curtime); - return ( - 100000000000000 * pCurtime->tm_mday + - 1000000000000 * pCurtime->tm_hour + - 10000000000 * pCurtime->tm_min + - 100000000 * pCurtime->tm_sec + - 1000 * this->clientIndex + - index - ); -} - -std::string Taoyao::buildMessage(std::string signal, json body, long long id = this->buildId(), std::string v = "1.0.0") { - -} - -void Taoyao::acceptSignal() { - int status; - char recvbuf[BUFFER_SIZE]; - while(true) { - if(this->socketChannel == 0) { - this->connectSignal(); - continue; - } - /** - * 0 - 服务断开 - * -1 - 网络故障:如果设置超时也会出现 - */ - status = recv(this->socketChannel, recvbuf, sizeof(recvbuf), 0); - if(status == 0) { - this->connectSignal(); - continue; - } - std::cout << "接收消息:" << status << " - " << recvbuf << std::endl; - memset(recvbuf, 0, sizeof(recvbuf)); - } -} - -void Taoyao::connectSignal() { - this->closeSignal(); - this->socketChannel = socket(AF_INET, SOCK_STREAM, 0); - setsockopt(this->socketChannel, SOL_SOCKET, SO_SNDTIMEO, &this->timeout, sizeof(this->timeout)); - setsockopt(this->socketChannel, SOL_SOCKET, SO_RCVTIMEO, &this->timeout, sizeof(this->timeout)); - if (connect(this->socketChannel, (struct sockaddr *) &this->serverAddress, sizeof(this->serverAddress)) < 0) { - std::cout << "连接失败:重试" << std::endl; - this->connectSignal(); - return; - } - std::cout << "连接成功:" << this->address << ":" << this->port << std::endl; -} - -void Taoyao::push(std::string message) { - std::cout << "发送消息:" << message << std::endl; - char sendbuf[message.length() + 1]; - strncpy(sendbuf, message.c_str(), message.length() + 1); - send(this->socketChannel, sendbuf, sizeof(sendbuf), 0); - memset(sendbuf, 0, sizeof(sendbuf)); -} - -// void Taoyao::request(std::string message) { -// } - -void Taoyao::closeSignal() { - if(this->socketChannel != 0) { - close(this->socketChannel); - this->socketChannel = 0; - } -} - -} - -int main(int argc, char const *argv[]) { - acgist::Taoyao taoyao(9999, "192.168.1.100"); - taoyao.connectSignal(); - char sendbuf[BUFFER_SIZE]; - while (fgets(sendbuf, sizeof(sendbuf), stdin) != NULL) { - taoyao.push(sendbuf); - } - return 0; -} diff --git a/taoyao-signal-server/taoyao-server/src/main/resources/application.yml b/taoyao-signal-server/taoyao-server/src/main/resources/application.yml index 27341ad..8dd92a8 100644 --- a/taoyao-signal-server/taoyao-server/src/main/resources/application.yml +++ b/taoyao-signal-server/taoyao-server/src/main/resources/application.yml @@ -132,7 +132,7 @@ taoyao: host: 0.0.0.0 port: 9999 encrypt: DES - encrypt-key: + encrypt-key: 2SPWy+TF1zM= timeout: ${taoyao.timeout} queue-size: 100000 min-thread: 4 diff --git a/taoyao-signal-server/taoyao-signal/src/main/java/com/acgist/taoyao/signal/configuration/SocketSignalAutoConfiguration.java b/taoyao-signal-server/taoyao-signal/src/main/java/com/acgist/taoyao/signal/configuration/SocketSignalAutoConfiguration.java index 12de528..5b0ab3e 100644 --- a/taoyao-signal-server/taoyao-signal/src/main/java/com/acgist/taoyao/signal/configuration/SocketSignalAutoConfiguration.java +++ b/taoyao-signal-server/taoyao-signal/src/main/java/com/acgist/taoyao/signal/configuration/SocketSignalAutoConfiguration.java @@ -3,6 +3,7 @@ package com.acgist.taoyao.signal.configuration; import java.util.Base64; import java.util.Random; +import org.apache.commons.lang3.StringUtils; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; @@ -57,7 +58,7 @@ public class SocketSignalAutoConfiguration { */ private void buildSecret(SocketProperties socketProperties) { log.info("Socket信令加密策略:{}", socketProperties.getEncrypt()); - if(socketProperties.getEncrypt() == null) { + if(socketProperties.getEncrypt() == null || StringUtils.isNotEmpty(socketProperties.getEncryptKey())) { return; } final Random random = new Random();