NIM 跨平台 C++ SDK
载入中...
搜索中...
未找到
v2_nim_internal.hpp
浏览该文件的文档.
1#ifndef V2_NIM_INTERNAL_H
2#define V2_NIM_INTERNAL_H
5
6#if defined(WIN32) || defined(_WIN32)
7#include <Windows.h>
8#else
9#include <dlfcn.h>
10#endif
11namespace v2 {
13 : code(code) {
14 auto iter = V2NIM_ERROR_DESC_MAPPING.find(code);
15 if (iter != V2NIM_ERROR_DESC_MAPPING.end()) {
16 desc = iter->second;
17 }
18 if (!pair.first.empty()) {
19 detail.emplace(std::move(pair));
20 }
21}
23 return detail[key];
24}
25inline bool V2NIMTeamRefer::operator<(const v2::V2NIMTeamRefer& other) const {
26 return teamId < other.teamId;
27}
28inline bool V2NIMTeamRefer::operator==(const V2NIMTeamRefer& other) const {
29 return (teamId == other.teamId) && (teamType == other.teamType);
30}
31inline std::string V2NIMTeamRefer::referToKey(V2NIMTeamRefer refer) {
32 return refer.teamId + "|" + std::to_string(refer.teamType);
33}
35 auto pos = key.find('|');
36 V2NIMTeamRefer refer;
37 refer.teamId = key.substr(0, pos);
38 refer.teamType = static_cast<V2NIMTeamType>(std::stoi(key.substr(pos + 1)));
39 return refer;
40}
41inline size_t hash_value(const V2NIMTeamRefer& val) {
42 return val.hash_value();
43}
44namespace internal {
45enum {
50};
51enum {
54};
55// V2NIMClientAntispamUtilInternal
57public:
59};
61
62// V2NIMConversationIdUtilInternal
64public:
65 virtual nstd::string p2pConversationId(const nstd::string& accountId) = 0;
66 virtual nstd::string teamConversationId(const nstd::string& teamId) = 0;
67 virtual nstd::string superTeamConversationId(const nstd::string& superTeamId) = 0;
68 virtual V2NIMConversationType parseConversationType(const nstd::string& conversationId) = 0;
69 virtual nstd::string parseConversationTargetId(const nstd::string& conversationId) = 0;
70};
72
73// V2NIMMessageUtilInternal
75public:
78 nstd::string name,
79 nstd::string sceneName,
80 uint32_t width,
81 uint32_t height) = 0;
82 virtual nstd::optional<V2NIMMessage> createAudioMessage(nstd::string audioPath, nstd::string name, nstd::string sceneName, uint32_t duration) = 0;
84 nstd::string name,
85 nstd::string sceneName,
86 uint32_t duration,
87 uint32_t width,
88 uint32_t height) = 0;
90 virtual nstd::optional<V2NIMMessage> createLocationMessage(double latitude, double longitude, nstd::string address) = 0;
93 int32_t subType) = 0;
97 const nstd::string& channelId,
98 int32_t status,
100 const nstd::string& text) = 0;
103 virtual nstd::string imageThumbUrl(const nstd::string& url, int32_t thumbSize) = 0;
104 virtual nstd::string videoCoverUrl(const nstd::string& url, int32_t offset, int32_t thumbSize, const nstd::string& type) = 0;
106 double longitude,
107 const nstd::string& address) = 0;
108};
110
111// V2NIMChatroomMessageUtilInternal
113public:
116 nstd::string name,
117 nstd::string sceneName,
118 uint32_t width,
119 uint32_t height) = 0;
121 nstd::string name,
122 nstd::string sceneName,
123 uint32_t duration) = 0;
125 nstd::string name,
126 nstd::string sceneName,
127 uint32_t duration,
128 uint32_t width,
129 uint32_t height) = 0;
131 virtual nstd::optional<V2NIMChatroomMessage> createLocationMessage(double latitude, double longitude, nstd::string address) = 0;
134 int32_t subType) = 0;
137};
139
140#ifdef WIN32
141static const char* NIM_SDK_NAME = "nim.dll";
142static const char* NIM_CHATROOM_SDK_NAME = "nim_chatroom.dll";
143#elif __APPLE__
144static const char* NIM_SDK_NAME = "libnim.dylib";
145static const char* NIM_CHATROOM_SDK_NAME = "libnim_chatroom.dylib";
146#else
147static const char* NIM_SDK_NAME = "libnim.so";
148static const char* NIM_CHATROOM_SDK_NAME = "libnim_chatroom.so";
149#endif
150template <typename T>
151inline T callSdkFunction(const char* sdkName, const char* functionName) {
152#ifdef WIN32
153 auto* sdkHandle = ::LoadLibraryA(sdkName);
154 if (sdkHandle == nullptr) {
155 throw std::runtime_error("LoadLibraryA error: " + std::to_string(::GetLastError()));
156 }
157 auto* instanceFunction = ::GetProcAddress(static_cast<HMODULE>(sdkHandle), functionName);
158 if (instanceFunction == nullptr) {
159 throw std::runtime_error("GetProcAddress error: " + std::to_string(::GetLastError()));
160 }
161#else
162 // 获取当前模块所在路径
163 auto* sdkHandle = dlopen(sdkName, RTLD_LAZY);
164 if (sdkHandle == nullptr) {
165 throw std::runtime_error("dlopen error: " + std::string(dlerror()));
166 }
167 auto* instanceFunction = dlsym(sdkHandle, functionName);
168 if (instanceFunction == nullptr) {
169 throw std::runtime_error("dlsym error: " + std::string(dlerror()));
170 }
171#endif
172 return reinterpret_cast<T (*)()>(instanceFunction)();
173}
174} // namespace internal
177}
179 nstd::string name,
180 nstd::string sceneName,
181 uint32_t width,
182 uint32_t height) {
183 return internal::internalMessageUtil->createImageMessage(imagePath, name, sceneName, width, height);
184}
186 nstd::string name,
187 nstd::string sceneName,
188 uint32_t duration) {
189 return internal::internalMessageUtil->createAudioMessage(audioPath, name, sceneName, duration);
190}
192 nstd::string name,
193 nstd::string sceneName,
194 uint32_t duration,
195 uint32_t width,
196 uint32_t height) {
197 return internal::internalMessageUtil->createVideoMessage(videoPath, name, sceneName, duration, width, height);
198}
200 return internal::internalMessageUtil->createFileMessage(filePath, name, sceneName);
201}
203 return internal::internalMessageUtil->createLocationMessage(latitude, longitude, address);
204}
206 return internal::internalMessageUtil->createCustomMessage(text, rawAttachment);
207}
209 int32_t subType) {
211}
214}
217}
219 const nstd::string& channelId,
220 int32_t status,
222 const nstd::string& text) {
223 return internal::internalMessageUtil->createCallMessage(type, channelId, status, durations, text);
224}
225
228}
230 nstd::string name,
231 nstd::string sceneName,
232 uint32_t width,
233 uint32_t height) {
234 return internal::internalChatroomMessageUtil->createImageMessage(imagePath, name, sceneName, width, height);
235}
237 nstd::string name,
238 nstd::string sceneName,
239 uint32_t duration) {
240 return internal::internalChatroomMessageUtil->createAudioMessage(audioPath, name, sceneName, duration);
241}
243 nstd::string name,
244 nstd::string sceneName,
245 uint32_t duration,
246 uint32_t width,
247 uint32_t height) {
248 return internal::internalChatroomMessageUtil->createVideoMessage(videoPath, name, sceneName, duration, width, height);
249}
251 nstd::string name,
252 nstd::string sceneName) {
253 return internal::internalChatroomMessageUtil->createFileMessage(filePath, name, sceneName);
254}
256 double longitude,
257 nstd::string address) {
258 return internal::internalChatroomMessageUtil->createLocationMessage(latitude, longitude, address);
259}
262}
265 int32_t subType) {
267}
270}
273}
276}
279}
280inline nstd::string V2NIMStorageUtil::imageThumbUrl(const nstd::string& url, int32_t thumbSize) {
281 return internal::internalMessageUtil->imageThumbUrl(url, thumbSize);
282}
283inline nstd::string V2NIMStorageUtil::videoCoverUrl(const nstd::string& url, int32_t offset, int32_t thumbSize, const nstd::string& type) {
284 return internal::internalMessageUtil->videoCoverUrl(url, offset, thumbSize, type);
285}
287 double longitude,
288 const nstd::string& address) {
289 return internal::internalMessageUtil->createLocationMessageAttachment(latitude, longitude, address);
290}
293}
296}
299}
302}
305}
308}
309
310} // namespace v2
311#endif
Definition: ne_stl_continuous_container.h:15
Definition: ne_stl_smart_ptr.h:31
Definition: ne_stl_string.h:19
_string substr(std::size_t pos=0, std::size_t len=container_npos::value) const
Definition: ne_stl_string.h:560
static nstd::optional< V2NIMChatroomMessage > createTextMessage(nstd::string text)
创建文本消息
Definition: v2_nim_internal.hpp:226
static nstd::optional< V2NIMChatroomMessage > createCustomMessageWithAttachment(nstd::shared_ptr< V2NIMMessageCustomAttachment > attachment, int32_t subType)
创建群聊自定义消息
Definition: v2_nim_internal.hpp:263
static nstd::optional< V2NIMChatroomMessage > createLocationMessage(double latitude, double longitude, nstd::string address)
创建位置消息
Definition: v2_nim_internal.hpp:255
static nstd::optional< V2NIMChatroomMessage > createFileMessage(nstd::string filePath, nstd::string name, nstd::string sceneName)
创建文件消息
Definition: v2_nim_internal.hpp:250
static nstd::optional< V2NIMChatroomMessage > createTipsMessage(nstd::string text)
创建提示消息
Definition: v2_nim_internal.hpp:268
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:229
static nstd::optional< V2NIMChatroomMessage > createForwardMessage(V2NIMChatroomMessage message)
创建转发消息
Definition: v2_nim_internal.hpp:271
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:242
static nstd::optional< V2NIMChatroomMessage > createCustomMessage(nstd::string rawAttachment)
创建自定义消息
Definition: v2_nim_internal.hpp:260
static nstd::optional< V2NIMChatroomMessage > createAudioMessage(nstd::string audioPath, nstd::string name, nstd::string sceneName, uint32_t duration)
创建音频消息
Definition: v2_nim_internal.hpp:236
static V2NIMClientAntispamResult checkTextAntispam(nstd::string text, nstd::string replace)
文本本地反垃圾
Definition: v2_nim_internal.hpp:306
static nstd::string superTeamConversationId(const nstd::string &superTeamId)
获取超级群会话ID
Definition: v2_nim_internal.hpp:297
static V2NIMConversationType parseConversationType(const nstd::string &conversationId)
获取会话ID对应的会话类型
Definition: v2_nim_internal.hpp:300
static nstd::string p2pConversationId(const nstd::string &accountId)
获取点对点会话ID
Definition: v2_nim_internal.hpp:291
static nstd::string teamConversationId(const nstd::string &teamId)
获取群组会话ID
Definition: v2_nim_internal.hpp:294
static nstd::string parseConversationTargetId(const nstd::string &conversationId)
获取会话ID对应的目标ID
Definition: v2_nim_internal.hpp:303
static nstd::shared_ptr< V2NIMMessageLocationAttachment > createLocationMessageAttachment(double latitude, double longitude, const nstd::string &address)
构造地理位置消息附件
Definition: v2_nim_internal.hpp:286
static nstd::optional< nstd::string > messageSerialization(const V2NIMMessage &message)
将 V2NIMMessage 序列化为字符串
Definition: v2_nim_internal.hpp:274
static nstd::optional< V2NIMMessage > messageDeserialization(const nstd::string &messageString)
将字符串反序列化为 V2NIMMessage
Definition: v2_nim_internal.hpp:277
static nstd::optional< V2NIMMessage > createCustomMessage(nstd::string text, nstd::string rawAttachment)
创建自定义消息
Definition: v2_nim_internal.hpp:205
static nstd::optional< V2NIMMessage > createFileMessage(nstd::string filePath, nstd::string name, nstd::string sceneName)
创建文件消息
Definition: v2_nim_internal.hpp:199
static nstd::optional< V2NIMMessage > createAudioMessage(nstd::string audioPath, nstd::string name, nstd::string sceneName, uint32_t duration)
创建音频消息
Definition: v2_nim_internal.hpp:185
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:178
static nstd::optional< V2NIMMessage > createLocationMessage(double latitude, double longitude, nstd::string address)
创建位置消息
Definition: v2_nim_internal.hpp:202
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:191
static nstd::optional< V2NIMMessage > createTipsMessage(nstd::string text)
创建提示消息
Definition: v2_nim_internal.hpp:212
static nstd::optional< V2NIMMessage > createCustomMessageWithAttachment(nstd::shared_ptr< V2NIMMessageCustomAttachment > attachment, int32_t subType)
创建群聊自定义消息
Definition: v2_nim_internal.hpp:208
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:218
static nstd::optional< V2NIMMessage > createForwardMessage(V2NIMMessage message)
创建转发消息
Definition: v2_nim_internal.hpp:215
static nstd::optional< V2NIMMessage > createTextMessage(nstd::string text)
创建文本消息
Definition: v2_nim_internal.hpp:175
static nstd::string videoCoverUrl(const nstd::string &url, int32_t offset, int32_t thumbSize, const nstd::string &type)
获取视频封面
Definition: v2_nim_internal.hpp:283
static nstd::string imageThumbUrl(const nstd::string &url, int32_t thumbSize)
获取图片缩略图
Definition: v2_nim_internal.hpp:280
Definition: v2_nim_internal.hpp:112
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:56
virtual V2NIMClientAntispamResult checkTextAntispam(nstd::string text, nstd::string replace)=0
Definition: v2_nim_internal.hpp:63
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:74
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:147
V2NIMClientAntispamUtilInternal * internalClientAntispamUtil
Definition: v2_nim_internal.hpp:60
V2NIMChatroomMessageUtilInternal * internalChatroomMessageUtil
Definition: v2_nim_internal.hpp:138
V2NIMMessageUtilInternal * internalMessageUtil
Definition: v2_nim_internal.hpp:109
V2NIMConversationIdUtilInternal * internalConversationIdUtil
Definition: v2_nim_internal.hpp:71
@ V2_NIM_CHATROOM_MESSAGE_UTIL
Definition: v2_nim_internal.hpp:53
@ V2_NIM_CHATROOM_SDK_EXPORT
Definition: v2_nim_internal.hpp:52
T callSdkFunction(const char *sdkName, const char *functionName)
Definition: v2_nim_internal.hpp:151
@ V2_NIM_INTERNEL_INSTANCE
Definition: v2_nim_internal.hpp:46
@ V2_NIM_INTERNEL_CONVERSATION_ID_UTIL
Definition: v2_nim_internal.hpp:48
@ V2_NIM_INTERNEL_CLIENT_ANTI_SPAM_UTIL
Definition: v2_nim_internal.hpp:47
@ V2_NIM_INTERNEL_MESSAGE_UTIL
Definition: v2_nim_internal.hpp:49
static const char * NIM_CHATROOM_SDK_NAME
Definition: v2_nim_internal.hpp:148
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:571
V2NIMTeamType
Definition: v2_nim_def_enum.hpp:1300
size_t hash_value(const V2NIMTeamRefer &val)
Definition: v2_nim_internal.hpp:41
V2NIMConversationType
Definition: v2_nim_def_enum.hpp:932
Definition: ne_stl_optional.h:16
Definition: v2_nim_def_struct.hpp:2106
Definition: v2_nim_def_struct.hpp:1042
uint32_t code
错误码, 详见 V2NIMErrorCode
Definition: v2_nim_def_struct.hpp:9
nstd::string & operator[](const nstd::string &key)
Definition: v2_nim_internal.hpp:22
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:746
群摘要
Definition: v2_nim_def_struct.hpp:1516
bool operator==(const V2NIMTeamRefer &other) const
Definition: v2_nim_internal.hpp:28
V2NIMTeamType teamType
群组类型
Definition: v2_nim_def_struct.hpp:1520
bool operator<(const V2NIMTeamRefer &other) const
Definition: v2_nim_internal.hpp:25
static std::string referToKey(V2NIMTeamRefer refer)
Definition: v2_nim_internal.hpp:31
nstd::string teamId
群组ID
Definition: v2_nim_def_struct.hpp:1518
static V2NIMTeamRefer keyToRefer(std::string key)
Definition: v2_nim_internal.hpp:34
size_t hash_value() const
Definition: v2_nim_def_struct.hpp:1527