This commit is contained in:
acgist
2023-12-09 09:54:15 +08:00
parent 5bcc93bfa3
commit afe92f49bf
43 changed files with 0 additions and 958 deletions

View File

@@ -1,19 +0,0 @@
# 桃夭终端
## 支持版本
* 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

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

View File

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

View File

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

View File

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

View File

@@ -1,6 +0,0 @@
{
"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

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

View File

@@ -1,48 +0,0 @@
#!/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

@@ -1,64 +0,0 @@
@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

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

View File

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

View File

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

View File

@@ -1,49 +0,0 @@
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
bind.cpp
media/Room.cpp
media/Client.cpp
media/LocalClient.cpp
media/RemoteClient.cpp
media/MediaManager.cpp
media/SessionClient.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
libhilog_ndk.z.so
)

View File

@@ -1,97 +0,0 @@
/**
* 方法绑定
*/
#include <map>
#include <string>
#include "hilog/log.h"
#include "napi/native_api.h"
#include "./include/Room.hpp"
#include "./include/MediaManager.hpp"
#include "./include/SessionClient.hpp"
namespace acgist {
acgist::MediaManager* mediaManager = nullptr;
std::map<std::string, acgist::Room*> roomMap;
std::map<std::string, acgist::SessionClient*> sessionMap;
static void init() {
OH_LOG_INFO(LOG_APP, "加载libtaoyao");
// TODO输出编码能力
mediaManager = new MediaManager();
mediaManager->initPeerConnectionFactory();
}
static void shutdown() {
OH_LOG_INFO(LOG_APP, "卸载libtaoyao");
if (mediaManager != nullptr) {
delete mediaManager;
mediaManager = nullptr;
}
}
static napi_value sessionCall(napi_env env, napi_callback_info info) { return 0; }
static napi_value sessionPause(napi_env env, napi_callback_info info) { return 0; }
static napi_value sessionResume(napi_env env, napi_callback_info info) { return 0; }
static napi_value sessionExchange(napi_env env, napi_callback_info info) { return 0; }
static napi_value sessionClose(napi_env env, napi_callback_info info) { return 0; }
static napi_value mediaConsume(napi_env env, napi_callback_info info) { return 0; }
static napi_value mediaConsumerClose(napi_env env, napi_callback_info info) { return 0; }
static napi_value mediaConsumerPause(napi_env env, napi_callback_info info) { return 0; }
static napi_value mediaConsumerResume(napi_env env, napi_callback_info info) { return 0; }
static napi_value mediaProducerClose(napi_env env, napi_callback_info info) { return 0; }
static napi_value mediaProducerPause(napi_env env, napi_callback_info info) { return 0; }
static napi_value mediaProducerResume(napi_env env, napi_callback_info info) { return 0; }
static napi_value roomClientList(napi_env env, napi_callback_info info) { return 0; }
static napi_value roomClose(napi_env env, napi_callback_info info) { return 0; }
static napi_value roomEnter(napi_env env, napi_callback_info info) { return 0; }
static napi_value roomExpel(napi_env env, napi_callback_info info) { return 0; }
static napi_value roomInvite(napi_env env, napi_callback_info info) { return 0; }
static napi_value roomLeave(napi_env env, napi_callback_info info) { return 0; }
}
EXTERN_C_START
static napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor desc[] = {
{ "sessionCall", nullptr, acgist::sessionCall, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "sessionPause", nullptr, acgist::sessionPause, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "sessionResume", nullptr, acgist::sessionResume, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "sessionExchange", nullptr, acgist::sessionExchange, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "sessionClose", nullptr, acgist::sessionClose, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "mediaConsume", nullptr, acgist::mediaConsume, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "mediaConsumerClose", nullptr, acgist::mediaConsumerClose, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "mediaConsumerPause", nullptr, acgist::mediaConsumerPause, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "mediaConsumerResume", nullptr, acgist::mediaConsumerResume, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "mediaProducerClose", nullptr, acgist::mediaProducerClose, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "mediaProducerPause", nullptr, acgist::mediaProducerPause, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "mediaProducerResume", nullptr, acgist::mediaProducerResume, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "roomClientList", nullptr, acgist::roomClientList, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "roomClose", nullptr, acgist::roomClose, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "roomEnter", nullptr, acgist::roomEnter, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "roomExpel", nullptr, acgist::roomExpel, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "roomInvite", nullptr, acgist::roomInvite, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "roomLeave", nullptr, acgist::roomLeave, nullptr, nullptr, nullptr, napi_default, nullptr },
};
napi_define_properties(env, exports, sizeof(desc) / sizeof(napi_property_descriptor), 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);
acgist::init();
}

View File

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

View File

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

View File

@@ -1,32 +0,0 @@
/**
* 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:
MediaManager();
~MediaManager();
public:
webrtc::PeerConnectionFactory* peerConnectionFactoryPtr;
public:
void initPeerConnectionFactory();
webrtc::PeerConnection* buildPeerConnection();
void startCapture();
void startAudioCapture();
void startVideoCapture();
};
}
#endif // taoyao_MediaManager_HPP

View File

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

View File

@@ -1,18 +0,0 @@
/**
* 房间
*
* @author acgist
*/
#ifndef taoyao_Room_HPP
#define taoyao_Room_HPP
namespace acgist {
class Room {
};
}
#endif // taoyao_Room_HPP

View File

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

View File

@@ -1,18 +0,0 @@
/**
* 会话终端
*
* @author acgist
*/
#ifndef taoyao_SessionClient_HPP
#define taoyao_SessionClient_HPP
namespace acgist {
class SessionClient {
};
}
#endif // taoyao_SessionClient_HPP

View File

@@ -1,20 +0,0 @@
#include "../include/MediaManager.hpp"
#include "api/peer_connection_interface.h"
acgist::MediaManager::MediaManager() {
this->peerConnectionFactoryPtr = nullptr;
}
acgist::MediaManager::~MediaManager() {
if(this->peerConnectionFactoryPtr != nullptr) {
// delete this->peerConnectionFactoryPtr;
this->peerConnectionFactoryPtr->Release();
this->peerConnectionFactoryPtr = nullptr;
}
}
void acgist::MediaManager::initPeerConnectionFactory() {
webrtc::PeerConnectionFactoryDependencies dependencies;
// webrtc::PeerConnectionFactory::Create(dependencies);
}

View File

@@ -1,18 +0,0 @@
export const sessionCall : () => void;
export const sessionPause : () => void;
export const sessionResume : () => void;
export const sessionExchange: () => void;
export const sessionClose : () => void;
export const mediaConsume : () => void;
export const mediaConsumerClose : () => void;
export const mediaConsumerPause : () => void;
export const mediaConsumerResume: () => void;
export const mediaProducerClose : () => void;
export const mediaProducerPause : () => void;
export const mediaProducerResume: () => void;
export const roomClientList : () => void;
export const roomClose : () => void;
export const roomEnter : () => void;
export const roomExpel : () => void;
export const roomInvite: () => void;
export const roomLeave : () => void;

View File

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

View File

@@ -1,33 +0,0 @@
import hilog from '@ohos.hilog';
import window from '@ohos.window';
import UIAbility from '@ohos.app.ability.UIAbility';
export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.info(0x0000, 'EntryAbility', 'onCreate');
}
onDestroy() {
hilog.info(0x0000, 'EntryAbility', 'onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
hilog.info(0x0000, 'EntryAbility', 'onWindowStageCreate');
windowStage.loadContent('pages/Index', (err, data) => {
});
}
onWindowStageDestroy() {
hilog.info(0x0000, 'EntryAbility', 'onWindowStageDestroy');
}
onForeground() {
hilog.info(0x0000, 'EntryAbility', 'onForeground');
}
onBackground() {
hilog.info(0x0000, 'EntryAbility', 'onBackground');
}
};

View File

@@ -1,31 +0,0 @@
import { signal } from "../taoyao/TaoyaoSignal";
@Entry
@Component
struct Index {
build() {
Row() {
Column() {
Button("连接信令")
.fontSize(20)
.fontWeight(FontWeight.Bold)
.onClick(() => {
signal.connect();
});
}
.width('50%');
Column() {
Button("断开信令")
.fontSize(20)
.fontWeight(FontWeight.Bold)
.onClick(() => {
signal.close();
});
}
.width('50%');
}
.height('100%');
}
}

View File

@@ -1,35 +0,0 @@
/**
* 配置
*
* @author acgist
*/
class Signal {
// 终端名称
name: string = "鸿蒙";
// 终端ID
clientId: string = "harmony";
// 终端类型
clientType: string = "MOBILE";
// 信令账号
username: string = "taoyao";
// 信令密码
password: string = "taoyao";
};
class Setting {
// 信令地址
signalAddress: string = "wss://192.168.8.204:8888/websocket.signal";
// 信令版本
version: string = "1.0.0";
// 信令配置
signal: Signal = new Signal();
};
const setting = new Setting();
export {
setting
}

View File

@@ -1,211 +0,0 @@
/**
* 信令连接
*
* @author acgist
*/
import hilog from '@ohos.hilog';
import webSocket from '@ohos.net.webSocket';
import { setting } from './Setting';
import libtaoyao from 'libtaoyao.so'
interface BusinessError<T = void> extends Error {
code: number;
data?: T;
}
class TaoyaoSignal {
// WebSocket信令连接
socket: webSocket.WebSocket;
// 是否关闭
closed: boolean = false;
// 是否连接成功
connected: boolean = false;
// 心跳定时
heartbeatTimer: number;
// 同步请求
callbackMapping = new Map();
// 当前消息索引
index: number = 0;
// 最大消息索引
maxIndex: number = 999;
// 当前终端索引
clientIndex: number = 99999;
connect() {
if(this.socket) {
this.socket.close();
}
this.connected = false;
hilog.info(0x0000, 'TaoyaoSignal', '连接信令:%s', setting.signalAddress);
this.socket = webSocket.createWebSocket();
this.socket.on('open', (err: BusinessError, value: Object) => {
hilog.info(0x0000, 'TaoyaoSignal', '打开信令:%s', setting.signalAddress);
this.register();
this.connected = true;
});
this.socket.on('message', (err: BusinessError, value: string | ArrayBuffer) => {
hilog.debug(0x0000, 'TaoyaoSignal', '信令消息:%s', value);
try {
this.onMessage(value);
} catch (error) {
hilog.error(0x0000, 'TaoyaoSignal', '处理信令消息异常:%s', value, error);
}
});
this.socket.on('close', (err: BusinessError, value: Object) => {
hilog.error(0x0000, 'TaoyaoSignal', '关闭信令:%s', setting.signalAddress, err);
this.reconnect();
});
this.socket.on('error', (err: BusinessError) => {
hilog.error(0x0000, 'TaoyaoSignal', '信令异常:%s', setting.signalAddress, err);
this.reconnect();
});
this.socket.connect(setting.signalAddress, (err: BusinessError, value: boolean) => {
hilog.info(0x0000, 'TaoyaoSignal', '信令连接成功:%s', setting.signalAddress);
});
};
reconnect() {
if(!this.closed) {
setTimeout(() => this.connect(), 5000);
}
}
close() {
hilog.info(0x0000, 'TaoyaoSignal', '关闭信令:%s', setting.signalAddress);
this.closed = true;
this.connected = false;
if(this.socket) {
this.socket.close();
}
}
async register() {
const response: any = await this.request("client::register", {
name : setting.signal.name,
clientId : setting.signal.clientId,
clientType: setting.signal.clientType,
username : setting.signal.username,
password : setting.signal.password,
battery : 100,
charging : true,
});
const { body } = response;
const { index } = body;
this.clientIndex = index;
hilog.info(0x0000, "TaoyaoSignal", "信令注册成功:%d", index);
this.heartbeat();
}
heartbeat() {
if(this.heartbeatTimer) {
clearInterval(this.heartbeatTimer);
}
this.heartbeatTimer = setInterval(() => {
this.send("client::heartbeat", {
battery : 100,
charging: true,
});
}, 30 * 1000);
};
buildId() {
if (++this.index > this.maxIndex) {
this.index = 0;
}
const date = new Date();
return (
100000000000000 * date.getDate() +
1000000000000 * date.getHours() +
10000000000 * date.getMinutes() +
100000000 * date.getSeconds() +
1000 * this.clientIndex +
this.index
);
}
send(signal, body) {
const header = {
v: setting.version,
id: this.buildId(),
signal
};
const message = {
header,
body
};
try {
this.socket.send(JSON.stringify(message));
} catch (error) {
hilog.error(0x0000, 'TaoyaoSignal', '发送消息异常:%o', message, error);
}
}
async request(signal, body) {
const id = this.buildId();
return new Promise((resolve, reject) => {
const header = {
v: setting.version,
id,
signal
};
const message = {
header,
body
};
// 设置超时
const rejectTimeout = setTimeout(() => {
this.callbackMapping.delete(id);
reject("请求超时");
}, 5000);
// 请求回调
this.callbackMapping.set(id, (response) => {
resolve(response);
clearTimeout(rejectTimeout);
// 默认不用继续处理
return true;
});
// 发送消息
try {
this.socket.send(JSON.stringify(message));
} catch (error) {
hilog.error(0x0000, 'TaoyaoSignal', '发送消息异常:%o', message, error);
reject(error);
}
});
}
onMessage(message) {
const json = JSON.parse(message);
const {
header,
body,
} = json;
const {
id
} = header;
if (this.callbackMapping.has(id)) {
hilog.info(0x0000, "TaoyaoSignal", "处理同步消息:%s", message);
try {
if(
this.callbackMapping.get(id)(json)
) {
return;
}
} finally {
this.callbackMapping.delete(id);
}
}
hilog.info(0x0000, "TaoyaoSignal", "处理异步消息:%s", message);
// TODO
}
}
const signal = new TaoyaoSignal();
export {
signal
}

View File

@@ -1,57 +0,0 @@
{
"module": {
"name" : "media",
"type" : "entry",
"pages": "$profile:main_pages",
"description": "$string:module_desc",
"mainElement": "EntryAbility",
"installationFree" : false,
"deliveryWithInstall": true,
"deviceTypes": [
"default",
"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"
]
}
]
}
],
"requestPermissions": [
{
"name": "ohos.permission.CAMERA",
"usedScene": {
"when": "always"
}
},
{
"name": "ohos.permission.INTERNET",
"usedScene": {
"when": "always"
}
},
{
"name": "ohos.permission.MICROPHONE",
"usedScene": {
"when": "always"
}
}
]
}
}

View File

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

View File

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

View File

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

View File

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