1
This commit is contained in:
35
.gitignore
vendored
Normal file
35
.gitignore
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
/build
|
||||
/.vs
|
||||
/out/build/x64-Debug
|
||||
86
CMakeLists.txt
Normal file
86
CMakeLists.txt
Normal file
@@ -0,0 +1,86 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
set(MODULE_NAME "tencent_sdk")
|
||||
# 设置项目名为当前目录名
|
||||
project(${MODULE_NAME})
|
||||
|
||||
|
||||
#set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build" FORCE)
|
||||
#set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
|
||||
#set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -O0")
|
||||
# 搜索源文件和头文件
|
||||
file(GLOB_RECURSE SOURCE_FILES "${PROJECT_SOURCE_DIR}/src/*.cpp")
|
||||
file(GLOB_RECURSE HEADER_FILES
|
||||
"${PROJECT_SOURCE_DIR}/src/*.h"
|
||||
)
|
||||
|
||||
# 将源文件分配到 Source Files 文件夹
|
||||
foreach(source IN LISTS SOURCE_FILES)
|
||||
get_filename_component(source_path "${source}" PATH)
|
||||
file(RELATIVE_PATH source_path_rel "${PROJECT_SOURCE_DIR}" "${source_path}")
|
||||
string(REPLACE "/" "\\" source_path_rel_win "${source_path_rel}")
|
||||
source_group("Source Files\\${source_path_rel_win}" FILES "${source}")
|
||||
endforeach()
|
||||
|
||||
# 将头文件分配到 Header Files 文件夹
|
||||
foreach(header IN LISTS HEADER_FILES)
|
||||
get_filename_component(header_path "${header}" PATH)
|
||||
file(RELATIVE_PATH header_path_rel "${PROJECT_SOURCE_DIR}" "${header_path}")
|
||||
string(REPLACE "/" "\\" header_path_rel_win "${header_path_rel}")
|
||||
source_group("Header Files\\${header_path_rel_win}" FILES "${header}")
|
||||
endforeach()
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
|
||||
# 安装复制
|
||||
set(CMAKE_INSTALL_ALWAYS_COPY TRUE)
|
||||
|
||||
set(YLIB ${CMAKE_INSTALL_PREFIX}/../ylib)
|
||||
set(FASTWEB ${CMAKE_INSTALL_PREFIX}/../fastweb)
|
||||
|
||||
# 包含路径
|
||||
if(MSVC)
|
||||
|
||||
else()
|
||||
include_directories(
|
||||
/usr/local/include/ylib
|
||||
/usr/local/include/fastweb
|
||||
/opt/lua54/include
|
||||
/usr/local/include
|
||||
|
||||
|
||||
)
|
||||
add_definitions(-DfPIC)
|
||||
endif()
|
||||
|
||||
# 添加共享库
|
||||
add_library(${MODULE_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES})
|
||||
|
||||
if(MSVC)
|
||||
|
||||
else()
|
||||
link_directories(
|
||||
${MODULE_NAME}
|
||||
|
||||
)
|
||||
|
||||
|
||||
target_link_libraries(${MODULE_NAME}
|
||||
/opt/lua54/lib/liblua.a
|
||||
/usr/local/lib/libtencentcloud-sdk-cpp-core.so
|
||||
/usr/local/lib/libtencentcloud-sdk-cpp-trtc.so
|
||||
|
||||
hpsocket
|
||||
ylib
|
||||
crypto
|
||||
ssl
|
||||
curl
|
||||
pthread
|
||||
stdc++
|
||||
|
||||
)
|
||||
|
||||
endif()
|
||||
|
||||
|
||||
install(TARGETS ${MODULE_NAME} DESTINATION $<IF:$<CONFIG:Debug>,${FASTWEB}/bin/debug/module/${MODULE_NAME},${FASTWEB}/bin/release/module/${MODULE_NAME}>)
|
||||
23
LICENSE
Normal file
23
LICENSE
Normal file
@@ -0,0 +1,23 @@
|
||||
Software License
|
||||
|
||||
Copyright (C) 2024 [liuyingjie]
|
||||
|
||||
License Terms
|
||||
|
||||
Usage Rights
|
||||
|
||||
1. Any individual or entity is free to use, copy, and distribute the binary form of this software without modification to the source code, without the need to disclose the source code.
|
||||
2. If the source code is modified, the modifications must be open-sourced under the same license. This means that the modifications must be disclosed and accompanied by a copy of this license.
|
||||
|
||||
Future Versions Updates
|
||||
|
||||
1. From this version onwards, all future releases will be governed by the terms of the latest version of the license. This license will automatically be nullified and replaced by the new version.
|
||||
2. Users must comply with the terms of the new license issued in future releases.
|
||||
|
||||
Liability and Disclaimer
|
||||
|
||||
This software is provided "as is", without any express or implied warranties, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non-infringement. In no event shall the author or copyright holder be liable for any claims, damages, or other liabilities, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software.
|
||||
|
||||
Contact Information
|
||||
|
||||
If you have any questions, please contact us: 1585346868@qq.com Or visit our website fwlua.com.
|
||||
25
build.sh
Normal file
25
build.sh
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
# 编译 SDK
|
||||
cd "$SCRIPT_DIR/3rdparty"
|
||||
if [ ! -f tencentcloud-sdk-cpp-master.zip ]; then
|
||||
wget https://download.fwlua.com/other/tencentcloud-sdk-cpp-master.zip
|
||||
fi
|
||||
|
||||
rm -rf tencentcloud-sdk-cpp-master
|
||||
unzip tencentcloud-sdk-cpp-master.zip
|
||||
cd tencentcloud-sdk-cpp-master
|
||||
# 后面加入了哪个功能再修改
|
||||
./build.sh build -DBUILD_MODULES="trtc"
|
||||
./build.sh install
|
||||
|
||||
# 安装
|
||||
cd "$SCRIPT_DIR"
|
||||
rm -rf build
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
cp -f libtencent_sdk.so ../target
|
||||
87
src/tencent_sdk_trtc.cpp
Normal file
87
src/tencent_sdk_trtc.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
#include "tencent_sdk_trtc.h"
|
||||
#include "dll_interface.h"
|
||||
|
||||
|
||||
|
||||
#include <tencentcloud/core/Credential.h>
|
||||
#include <tencentcloud/core/profile/ClientProfile.h>
|
||||
#include <tencentcloud/core/profile/HttpProfile.h>
|
||||
#include <tencentcloud/trtc/v20190722/TrtcClient.h>
|
||||
#include <tencentcloud/trtc/v20190722/model/DismissRoomByStrRoomIdRequest.h>
|
||||
#include <tencentcloud/trtc/v20190722/model/DismissRoomByStrRoomIdResponse.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
using namespace TencentCloud;
|
||||
using namespace TencentCloud::Trtc::V20190722;
|
||||
using namespace TencentCloud::Trtc::V20190722::Model;
|
||||
|
||||
extern "C" {
|
||||
#ifdef _WIN32
|
||||
DLL_EXPORT
|
||||
#endif
|
||||
int fastweb_module_regist(void* sol2, void* lua)
|
||||
{
|
||||
sol::state* state = static_cast<sol::state*>(sol2);
|
||||
module::tencent_sdk_trtc::regist(state);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
module::tencent_sdk_trtc::tencent_sdk_trtc()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
module::tencent_sdk_trtc::~tencent_sdk_trtc()
|
||||
{
|
||||
// cos_http_io_deinitialize();
|
||||
}
|
||||
|
||||
std::pair<bool,std::string> module::tencent_sdk_trtc::dismissRoomByStrRoomId(const std::string& secret_id,const std::string& secret_key,long long sdkappid,const std::string& room_id)
|
||||
{
|
||||
// 密钥信息从环境变量读取,需要提前在环境变量中设置 TENCENTCLOUD_SECRET_ID 和 TENCENTCLOUD_SECRET_KEY
|
||||
// 使用环境变量方式可以避免密钥硬编码在代码中,提高安全性
|
||||
// 生产环境建议使用更安全的密钥管理方案,如密钥管理系统(KMS)、容器密钥注入等
|
||||
// 请参见:https://cloud.tencent.com/document/product/1278/85305
|
||||
// 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取
|
||||
Credential cred = Credential(secret_id.c_str(), secret_key.c_str());
|
||||
// 使用临时密钥示例
|
||||
// Credential cred = Credential("SecretId", "SecretKey", "Token");
|
||||
// 实例化一个http选项,可选的,没有特殊需求可以跳过
|
||||
HttpProfile httpProfile = HttpProfile();
|
||||
httpProfile.SetEndpoint("trtc.tencentcloudapi.com");
|
||||
|
||||
// 实例化一个client选项,可选的,没有特殊需求可以跳过
|
||||
ClientProfile clientProfile = ClientProfile();
|
||||
clientProfile.SetHttpProfile(httpProfile);
|
||||
// 实例化要请求产品的client对象,clientProfile是可选的
|
||||
TrtcClient client = TrtcClient(cred, "ap-beijing", clientProfile);
|
||||
|
||||
// 实例化一个请求对象,每个接口都会对应一个request对象
|
||||
DismissRoomByStrRoomIdRequest req = DismissRoomByStrRoomIdRequest();
|
||||
req.SetSdkAppId(sdkappid);
|
||||
req.SetRoomId(room_id.c_str());
|
||||
// 返回的resp是一个DismissRoomByStrRoomIdResponse的实例,与请求对象对应
|
||||
auto outcome = client.DismissRoomByStrRoomId(req);
|
||||
if (!outcome.IsSuccess())
|
||||
{
|
||||
return std::make_pair(false, outcome.GetError().PrintAll());
|
||||
}
|
||||
DismissRoomByStrRoomIdResponse resp = outcome.GetResult();
|
||||
// 输出json格式的字符串回包
|
||||
return std::make_pair(true, resp.ToJsonString());
|
||||
}
|
||||
void module::tencent_sdk_trtc::regist(sol::state* lua)
|
||||
{
|
||||
lua->new_usertype<module::tencent_sdk_trtc>("fw_tencent_sdk_trtc",
|
||||
"new", sol::constructors<module::tencent_sdk_trtc()>(),
|
||||
"dismissRoomByStrRoomId", &module::tencent_sdk_trtc::dismissRoomByStrRoomId
|
||||
);
|
||||
}
|
||||
|
||||
void module::tencent_sdk_trtc::regist_global(const char* name, sol::state* lua)
|
||||
{
|
||||
lua->registry()[name] = this;
|
||||
(*lua)[name] = this;
|
||||
}
|
||||
32
src/tencent_sdk_trtc.h
Normal file
32
src/tencent_sdk_trtc.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include "basemodule.h"
|
||||
#include <utility>
|
||||
namespace module
|
||||
{
|
||||
class tencent_sdk_trtc : public module::base {
|
||||
public:
|
||||
tencent_sdk_trtc();
|
||||
~tencent_sdk_trtc() override;
|
||||
static void regist(sol::state* lua);
|
||||
|
||||
|
||||
/**
|
||||
* @brief 解散房间
|
||||
* @param secret_id 密钥ID
|
||||
* @param secret_key 密钥
|
||||
* @param sdkappid SDKAPPID
|
||||
* @param room_id 房间ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
std::pair<bool,std::string> dismissRoomByStrRoomId(
|
||||
const std::string& secret_id,
|
||||
const std::string& secret_key,
|
||||
long long sdkappid,
|
||||
const std::string& room_id
|
||||
);
|
||||
private:
|
||||
virtual void regist_global(const char* name, sol::state* lua);
|
||||
virtual void delete_global() { delete this; }
|
||||
};
|
||||
}
|
||||
|
||||
24
target/tencent_sdk_trtc.lua
Normal file
24
target/tencent_sdk_trtc.lua
Normal file
@@ -0,0 +1,24 @@
|
||||
local tencent_sdk_trtc = {}
|
||||
tencent_sdk_trtc.__index = tencent_sdk_trtc
|
||||
|
||||
--[[
|
||||
创建一个新的 tencent_cos 对象
|
||||
@return 返回一个新的 tencent_sdk_trtc 对象
|
||||
]]
|
||||
function tencent_sdk_trtc.new(db)
|
||||
local instance = setmetatable({}, tencent_sdk_trtc)
|
||||
if db == nil then
|
||||
instance.module = fw_tencent_sdk_trtc.new()
|
||||
else
|
||||
instance.module = db
|
||||
end
|
||||
|
||||
return instance
|
||||
end
|
||||
|
||||
|
||||
function tencent_sdk_trtc:dismissRoomByStrRoomId(secret_id,secret_key,sdkappid,room_id)
|
||||
return self.module:dismissRoomByStrRoomId(secret_id,secret_key,sdkappid,room_id)
|
||||
end
|
||||
|
||||
return tencent_sdk_trtc
|
||||
Reference in New Issue
Block a user