NIM 跨平台 C++ SDK
载入中...
搜索中...
未找到
v2_nim_internal.hpp
浏览该文件的文档.
1#ifndef V2_NIM_INTERNAL_H
2#define V2_NIM_INTERNAL_H
4#if defined(WIN32) || defined(_WIN32)
5#include <Windows.h>
6#else
7#include <dlfcn.h>
8#endif
9namespace v2 {
11 : code(code) {
12 auto iter = V2NIM_ERROR_DESC_MAPPING.find(code);
13 if (iter != V2NIM_ERROR_DESC_MAPPING.end()) {
14 desc = iter->second;
15 }
16 if (!pair.first.empty()) {
17 detail.emplace(std::move(pair));
18 }
19}
21 return detail[key];
22}
23namespace internal {
24enum {
29};
30enum {
33};
34// V2NIMClientAntispamUtilInternal
36public:
38};
40
41// V2NIMConversationIdUtilInternal
43public:
44 virtual nstd::string p2pConversationId(const nstd::string& accountId) = 0;
45 virtual nstd::string teamConversationId(const nstd::string& teamId) = 0;
46 virtual nstd::string superTeamConversationId(const nstd::string& superTeamId) = 0;
47 virtual V2NIMConversationType parseConversationType(const nstd::string& conversationId) = 0;
48 virtual nstd::string parseConversationTargetId(const nstd::string& conversationId) = 0;
49};
51
52// V2NIMMessageUtilInternal
54public:
57 nstd::string name,
58 nstd::string sceneName,
59 uint32_t width,
60 uint32_t height) = 0;
61 virtual nstd::optional<V2NIMMessage> createAudioMessage(nstd::string audioPath, nstd::string name, nstd::string sceneName, uint32_t duration) = 0;
63 nstd::string name,
64 nstd::string sceneName,
65 uint32_t duration,
66 uint32_t width,
67 uint32_t height) = 0;
69 virtual nstd::optional<V2NIMMessage> createLocationMessage(double latitude, double longitude, nstd::string address) = 0;
72 int32_t subType) = 0;
76 const nstd::string& channelId,
77 int32_t status,
79 const nstd::string& text) = 0;
82 virtual nstd::string imageThumbUrl(const nstd::string& url, int32_t thumbSize) = 0;
83 virtual nstd::string videoCoverUrl(const nstd::string& url, int32_t offset, int32_t thumbSize, const nstd::string& type) = 0;
85 double longitude,
86 const nstd::string& address) = 0;
87};
89
90// V2NIMChatroomMessageUtilInternal
92public:
95 nstd::string name,
96 nstd::string sceneName,
97 uint32_t width,
98 uint32_t height) = 0;
100 nstd::string name,
101 nstd::string sceneName,
102 uint32_t duration) = 0;
104 nstd::string name,
105 nstd::string sceneName,
106 uint32_t duration,
107 uint32_t width,
108 uint32_t height) = 0;
110 virtual nstd::optional<V2NIMChatroomMessage> createLocationMessage(double latitude, double longitude, nstd::string address) = 0;
113 int32_t subType) = 0;
116};
118
119#ifdef WIN32
120static const char* NIM_SDK_NAME = "nim.dll";
121static const char* NIM_CHATROOM_SDK_NAME = "nim_chatroom.dll";
122#elif __APPLE__
123static const char* NIM_SDK_NAME = "libnim.dylib";
124static const char* NIM_CHATROOM_SDK_NAME = "libnim_chatroom.dylib";
125#else
126static const char* NIM_SDK_NAME = "libnim.so";
127static const char* NIM_CHATROOM_SDK_NAME = "libnim_chatroom.so";
128#endif
129template <typename T>
130inline T callSdkFunction(const char* sdkName, const char* functionName) {
131#ifdef WIN32
132 auto* sdkHandle = ::LoadLibraryA(sdkName);
133 if (sdkHandle == nullptr) {
134 throw std::runtime_error("LoadLibraryA error: " + std::to_string(::GetLastError()));
135 }
136 auto* instanceFunction = ::GetProcAddress(static_cast<HMODULE>(sdkHandle), functionName);
137 if (instanceFunction == nullptr) {
138 throw std::runtime_error("GetProcAddress error: " + std::to_string(::GetLastError()));
139 }
140#else
141 auto* sdkHandle = dlopen(sdkName, RTLD_LAZY);
142 if (sdkHandle == nullptr) {
143 throw std::runtime_error("dlopen error: " + std::string(dlerror()));
144 }
145 auto* instanceFunction = dlsym(sdkHandle, functionName);
146 if (instanceFunction == nullptr) {
147 throw std::runtime_error("dlsym error: " + std::string(dlerror()));
148 }
149#endif
150 return reinterpret_cast<T (*)()>(instanceFunction)();
151}
152} // namespace internal
155}
157 nstd::string name,
158 nstd::string sceneName,
159 uint32_t width,
160 uint32_t height) {
161 return internal::internalMessageUtil->createImageMessage(imagePath, name, sceneName, width, height);
162}
164 nstd::string name,
165 nstd::string sceneName,
166 uint32_t duration) {
167 return internal::internalMessageUtil->createAudioMessage(audioPath, name, sceneName, duration);
168}
170 nstd::string name,
171 nstd::string sceneName,
172 uint32_t duration,
173 uint32_t width,
174 uint32_t height) {
175 return internal::internalMessageUtil->createVideoMessage(videoPath, name, sceneName, duration, width, height);
176}
178 return internal::internalMessageUtil->createFileMessage(filePath, name, sceneName);
179}
181 return internal::internalMessageUtil->createLocationMessage(latitude, longitude, address);
182}
184 return internal::internalMessageUtil->createCustomMessage(text, rawAttachment);
185}
187 int32_t subType) {
189}
192}
195}
197 const nstd::string& channelId,
198 int32_t status,
200 const nstd::string& text) {
201 return internal::internalMessageUtil->createCallMessage(type, channelId, status, durations, text);
202}
203
206}
208 nstd::string name,
209 nstd::string sceneName,
210 uint32_t width,
211 uint32_t height) {
212 return internal::internalChatroomMessageUtil->createImageMessage(imagePath, name, sceneName, width, height);
213}
215 nstd::string name,
216 nstd::string sceneName,
217 uint32_t duration) {
218 return internal::internalChatroomMessageUtil->createAudioMessage(audioPath, name, sceneName, duration);
219}
221 nstd::string name,
222 nstd::string sceneName,
223 uint32_t duration,
224 uint32_t width,
225 uint32_t height) {
226 return internal::internalChatroomMessageUtil->createVideoMessage(videoPath, name, sceneName, duration, width, height);
227}
229 nstd::string name,
230 nstd::string sceneName) {
231 return internal::internalChatroomMessageUtil->createFileMessage(filePath, name, sceneName);
232}
234 double longitude,
235 nstd::string address) {
236 return internal::internalChatroomMessageUtil->createLocationMessage(latitude, longitude, address);
237}
240}
243 int32_t subType) {
245}
248}
251}
254}
257}
258inline nstd::string V2NIMStorageUtil::imageThumbUrl(const nstd::string& url, int32_t thumbSize) {
259 return internal::internalMessageUtil->imageThumbUrl(url, thumbSize);
260}
261inline nstd::string V2NIMStorageUtil::videoCoverUrl(const nstd::string& url, int32_t offset, int32_t thumbSize, const nstd::string& type) {
262 return internal::internalMessageUtil->videoCoverUrl(url, offset, thumbSize, type);
263}
265 double longitude,
266 const nstd::string& address) {
267 return internal::internalMessageUtil->createLocationMessageAttachment(latitude, longitude, address);
268}
271}
274}
277}
280}
283}
286}
287
288} // namespace v2
289#endif
Definition: ne_stl_continuous_container.h:15
Definition: ne_stl_smart_ptr.h:30
Definition: ne_stl_string.h:19
static nstd::optional< V2NIMChatroomMessage > createTextMessage(nstd::string text)
创建文本消息
Definition: v2_nim_internal.hpp:204
static nstd::optional< V2NIMChatroomMessage > createCustomMessageWithAttachment(nstd::shared_ptr< V2NIMMessageCustomAttachment > attachment, int32_t subType)
创建群聊自定义消息
Definition: v2_nim_internal.hpp:241
static nstd::optional< V2NIMChatroomMessage > createLocationMessage(double latitude, double longitude, nstd::string address)
创建位置消息
Definition: v2_nim_internal.hpp:233
static nstd::optional< V2NIMChatroomMessage > createFileMessage(nstd::string filePath, nstd::string name, nstd::string sceneName)
创建文件消息
Definition: v2_nim_internal.hpp:228
static nstd::optional< V2NIMChatroomMessage > createTipsMessage(nstd::string text)
创建提示消息
Definition: v2_nim_internal.hpp:246
static nstd::optional< V2NIMChatroomMessage > createImageMessage(nstd::string imagePath, nstd::string name, nstd::string sceneName, uint32_t width, uint32_t height)
创建图片消息
Definition: v2_nim_internal.hpp:207
static nstd::optional< V2NIMChatroomMessage > createForwardMessage(V2NIMChatroomMessage message)
创建转发消息
Definition: v2_nim_internal.hpp:249
static nstd::optional< V2NIMChatroomMessage > createVideoMessage(nstd::string videoPath, nstd::string name, nstd::string sceneName, uint32_t duration, uint32_t width, uint32_t height)
创建视频消息
Definition: v2_nim_internal.hpp:220
static nstd::optional< V2NIMChatroomMessage > createCustomMessage(nstd::string rawAttachment)
创建自定义消息
Definition: v2_nim_internal.hpp:238
static nstd::optional< V2NIMChatroomMessage > createAudioMessage(nstd::string audioPath, nstd::string name, nstd::string sceneName, uint32_t duration)
创建音频消息
Definition: v2_nim_internal.hpp:214
static V2NIMClientAntispamResult checkTextAntispam(nstd::string text, nstd::string replace)
文本本地反垃圾
Definition: v2_nim_internal.hpp:284
static nstd::string superTeamConversationId(const nstd::string &superTeamId)
获取超级群会话ID
Definition: v2_nim_internal.hpp:275
static V2NIMConversationType parseConversationType(const nstd::string &conversationId)
获取会话ID对应的会话类型
Definition: v2_nim_internal.hpp:278
static nstd::string p2pConversationId(const nstd::string &accountId)
获取点对点会话ID
Definition: v2_nim_internal.hpp:269
static nstd::string teamConversationId(const nstd::string &teamId)
获取群组会话ID
Definition: v2_nim_internal.hpp:272
static nstd::string parseConversationTargetId(const nstd::string &conversationId)
获取会话ID对应的目标ID
Definition: v2_nim_internal.hpp:281
static nstd::shared_ptr< V2NIMMessageLocationAttachment > createLocationMessageAttachment(double latitude, double longitude, const nstd::string &address)
构造地理位置消息附件
Definition: v2_nim_internal.hpp:264
static nstd::optional< nstd::string > messageSerialization(const V2NIMMessage &message)
将 V2NIMMessage 序列化为字符串
Definition: v2_nim_internal.hpp:252
static nstd::optional< V2NIMMessage > messageDeserialization(const nstd::string &messageString)
将字符串反序列化为 V2NIMMessage
Definition: v2_nim_internal.hpp:255
static nstd::optional< V2NIMMessage > createCustomMessage(nstd::string text, nstd::string rawAttachment)
创建自定义消息
Definition: v2_nim_internal.hpp:183
static nstd::optional< V2NIMMessage > createFileMessage(nstd::string filePath, nstd::string name, nstd::string sceneName)
创建文件消息
Definition: v2_nim_internal.hpp:177
static nstd::optional< V2NIMMessage > createAudioMessage(nstd::string audioPath, nstd::string name, nstd::string sceneName, uint32_t duration)
创建音频消息
Definition: v2_nim_internal.hpp:163
static nstd::optional< V2NIMMessage > createImageMessage(nstd::string imagePath, nstd::string name, nstd::string sceneName, uint32_t width, uint32_t height)
创建图片消息
Definition: v2_nim_internal.hpp:156
static nstd::optional< V2NIMMessage > createLocationMessage(double latitude, double longitude, nstd::string address)
创建位置消息
Definition: v2_nim_internal.hpp:180
static nstd::optional< V2NIMMessage > createVideoMessage(nstd::string videoPath, nstd::string name, nstd::string sceneName, uint32_t duration, uint32_t width, uint32_t height)
创建视频消息
Definition: v2_nim_internal.hpp:169
static nstd::optional< V2NIMMessage > createTipsMessage(nstd::string text)
创建提示消息
Definition: v2_nim_internal.hpp:190
static nstd::optional< V2NIMMessage > createCustomMessageWithAttachment(nstd::shared_ptr< V2NIMMessageCustomAttachment > attachment, int32_t subType)
创建群聊自定义消息
Definition: v2_nim_internal.hpp:186
static nstd::optional< V2NIMMessage > createCallMessage(int32_t type, const nstd::string &channelId, int32_t status, const nstd::vector< V2NIMMessageCallDuration > &durations, const nstd::string &text)
构造话单消息
Definition: v2_nim_internal.hpp:196
static nstd::optional< V2NIMMessage > createForwardMessage(V2NIMMessage message)
创建转发消息
Definition: v2_nim_internal.hpp:193
static nstd::optional< V2NIMMessage > createTextMessage(nstd::string text)
创建文本消息
Definition: v2_nim_internal.hpp:153
static nstd::string videoCoverUrl(const nstd::string &url, int32_t offset, int32_t thumbSize, const nstd::string &type)
获取视频封面
Definition: v2_nim_internal.hpp:261
static nstd::string imageThumbUrl(const nstd::string &url, int32_t thumbSize)
获取图片缩略图
Definition: v2_nim_internal.hpp:258
Definition: v2_nim_internal.hpp:91
virtual nstd::optional< V2NIMChatroomMessage > createForwardMessage(V2NIMChatroomMessage message)=0
virtual nstd::optional< V2NIMChatroomMessage > createLocationMessage(double latitude, double longitude, nstd::string address)=0
virtual nstd::optional< V2NIMChatroomMessage > createTextMessage(nstd::string text)=0
virtual nstd::optional< V2NIMChatroomMessage > createCustomMessageWithAttachment(nstd::shared_ptr< V2NIMMessageCustomAttachment > attachment, int32_t subType)=0
virtual nstd::optional< V2NIMChatroomMessage > createFileMessage(nstd::string filePath, nstd::string name, nstd::string sceneName)=0
virtual nstd::optional< V2NIMChatroomMessage > createImageMessage(nstd::string imagePath, nstd::string name, nstd::string sceneName, uint32_t width, uint32_t height)=0
virtual nstd::optional< V2NIMChatroomMessage > createVideoMessage(nstd::string videoPath, nstd::string name, nstd::string sceneName, uint32_t duration, uint32_t width, uint32_t height)=0
virtual nstd::optional< V2NIMChatroomMessage > createCustomMessage(nstd::string rawAttachment)=0
virtual nstd::optional< V2NIMChatroomMessage > createTipsMessage(nstd::string text)=0
virtual nstd::optional< V2NIMChatroomMessage > createAudioMessage(nstd::string audioPath, nstd::string name, nstd::string sceneName, uint32_t duration)=0
Definition: v2_nim_internal.hpp:35
virtual V2NIMClientAntispamResult checkTextAntispam(nstd::string text, nstd::string replace)=0
Definition: v2_nim_internal.hpp:42
virtual nstd::string p2pConversationId(const nstd::string &accountId)=0
virtual nstd::string teamConversationId(const nstd::string &teamId)=0
virtual nstd::string parseConversationTargetId(const nstd::string &conversationId)=0
virtual nstd::string superTeamConversationId(const nstd::string &superTeamId)=0
virtual V2NIMConversationType parseConversationType(const nstd::string &conversationId)=0
Definition: v2_nim_internal.hpp:53
virtual nstd::string imageThumbUrl(const nstd::string &url, int32_t thumbSize)=0
virtual nstd::optional< V2NIMMessage > createCustomMessageWithAttachment(nstd::shared_ptr< V2NIMMessageCustomAttachment > attachment, int32_t subType)=0
virtual nstd::optional< V2NIMMessage > createLocationMessage(double latitude, double longitude, nstd::string address)=0
virtual nstd::optional< V2NIMMessage > createTextMessage(nstd::string text)=0
virtual nstd::optional< V2NIMMessage > createAudioMessage(nstd::string audioPath, nstd::string name, nstd::string sceneName, uint32_t duration)=0
virtual nstd::optional< V2NIMMessage > createCustomMessage(nstd::string text, nstd::string rawAttachment)=0
virtual nstd::optional< V2NIMMessage > createForwardMessage(V2NIMMessage message)=0
virtual nstd::optional< V2NIMMessage > createFileMessage(nstd::string filePath, nstd::string name, nstd::string sceneName)=0
virtual nstd::optional< V2NIMMessage > createTipsMessage(nstd::string text)=0
virtual nstd::shared_ptr< V2NIMMessageLocationAttachment > createLocationMessageAttachment(double latitude, double longitude, const nstd::string &address)=0
virtual nstd::optional< V2NIMMessage > messageDeserialization(const nstd::string &message)=0
virtual nstd::string videoCoverUrl(const nstd::string &url, int32_t offset, int32_t thumbSize, const nstd::string &type)=0
virtual nstd::optional< V2NIMMessage > createImageMessage(nstd::string imagePath, nstd::string name, nstd::string sceneName, uint32_t width, uint32_t height)=0
virtual nstd::optional< V2NIMMessage > createVideoMessage(nstd::string videoPath, nstd::string name, nstd::string sceneName, uint32_t duration, uint32_t width, uint32_t height)=0
virtual nstd::optional< V2NIMMessage > createCallMessage(int32_t type, const nstd::string &channelId, int32_t status, const nstd::vector< V2NIMMessageCallDuration > &durations, const nstd::string &text)=0
virtual nstd::optional< nstd::string > messageSerialization(const V2NIMMessage &message)=0
phmap::priv::Pair< const K, V > Pair
Definition: ne_stl_map.h:11
static const char * NIM_SDK_NAME
Definition: v2_nim_internal.hpp:126
V2NIMClientAntispamUtilInternal * internalClientAntispamUtil
Definition: v2_nim_internal.hpp:39
V2NIMChatroomMessageUtilInternal * internalChatroomMessageUtil
Definition: v2_nim_internal.hpp:117
V2NIMMessageUtilInternal * internalMessageUtil
Definition: v2_nim_internal.hpp:88
V2NIMConversationIdUtilInternal * internalConversationIdUtil
Definition: v2_nim_internal.hpp:50
@ V2_NIM_CHATROOM_MESSAGE_UTIL
Definition: v2_nim_internal.hpp:32
@ V2_NIM_CHATROOM_SDK_EXPORT
Definition: v2_nim_internal.hpp:31
T callSdkFunction(const char *sdkName, const char *functionName)
Definition: v2_nim_internal.hpp:130
@ V2_NIM_INTERNEL_INSTANCE
Definition: v2_nim_internal.hpp:25
@ V2_NIM_INTERNEL_CONVERSATION_ID_UTIL
Definition: v2_nim_internal.hpp:27
@ V2_NIM_INTERNEL_CLIENT_ANTI_SPAM_UTIL
Definition: v2_nim_internal.hpp:26
@ V2_NIM_INTERNEL_MESSAGE_UTIL
Definition: v2_nim_internal.hpp:28
static const char * NIM_CHATROOM_SDK_NAME
Definition: v2_nim_internal.hpp:127
Definition: v2_nim_ai_service.hpp:4
static const std::map< uint32_t, const char *const > V2NIM_ERROR_DESC_MAPPING
Definition: v2_nim_def_enum.hpp:559
V2NIMConversationType
Definition: v2_nim_def_enum.hpp:909
Definition: ne_stl_optional.h:16
Definition: v2_nim_def_struct.hpp:1856
Definition: v2_nim_def_struct.hpp:919
uint32_t code
错误码, 详见 V2NIMErrorCode
Definition: v2_nim_def_struct.hpp:9
nstd::string & operator[](const nstd::string &key)
Definition: v2_nim_internal.hpp:20
nstd::map< nstd::string, nstd::string > detail
错误详情
Definition: v2_nim_def_struct.hpp:13
nstd::string desc
错误描述
Definition: v2_nim_def_struct.hpp:11
V2NIMError()=default
Definition: v2_nim_def_struct.hpp:643