|
|
@@ -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;
|
|
|
+}
|