NIM 跨平台 C++ SDK
载入中...
搜索中...
未找到
v2_nim_api.hpp
浏览该文件的文档.
1#ifndef V2_NIM_API_H
2#define V2_NIM_API_H
17#if defined(WIN32) || defined(_WIN32)
18#include "wtypes.h"
19#else
20#include <dlfcn.h>
21#endif
22#ifdef ENABLE_NIM_V1
24namespace nim {
26} // namespace nim
27#endif
28namespace v2 {
30public:
37 static V2NIMClient& get();
38
55 auto error = initImpl(option);
56#ifdef ENABLE_NIM_V1
57 if (!error && !nim::nim_sdk_instance) {
59 if (!nim::nim_sdk_instance->LoadSdkDll("", internal::NIM_SDK_NAME)) {
61 nim::nim_sdk_instance = nullptr;
62 throw std::runtime_error("[V2NIMClient] load v1 sdk failed");
63 }
64 }
65#endif
66 return error;
67 }
68
71
84 auto error = uninitImpl();
85#ifdef ENABLE_NIM_V1
86 if (!error && nim::nim_sdk_instance) {
89 nim::nim_sdk_instance = nullptr;
90 }
91#endif
92 return error;
93 }
94
97
109
116 virtual V2NIMLoginService& getLoginService() const = 0;
117
125
133
141
149
157
164 virtual V2NIMTeamService& getTeamService() const = 0;
165
173
180 virtual V2NIMUserService& getUserService() const = 0;
181
189
196 virtual V2NIMAIService& getAIService() const = 0;
197
205
213};
214
216public:
217 virtual ~V2NIMChatroomClient() = default;
233 static nstd::optional<V2NIMError> init(const V2NIMInitOption& option);
234
242 static void uninit();
243
261
274 static void destroyInstance(uint32_t instanceId);
275
291 static nstd::shared_ptr<V2NIMChatroomClient> getInstance(uint32_t instanceId);
292
301
310 static void destroyAll();
311
319 virtual uint32_t getInstanceId() = 0;
320
333
365 virtual void enter(nstd::string roomId,
366 V2NIMChatroomEnterParams enterParams,
368 V2NIMFailureCallback failure) = 0;
369
376 virtual void exit() = 0;
377
385
393
401
423
436};
437
439namespace internal {
441public:
443 virtual void uninit() = 0;
445 virtual void destroyInstance(uint32_t instanceId) = 0;
446 virtual nstd::shared_ptr<V2NIMChatroomClient> getInstance(uint32_t instanceId) = 0;
448 virtual void destroyAll() = 0;
449};
451} // namespace internal
452
454 static const char* sdkFunctionV2InstanceGet = "v2_nim_instance_impl_get";
455 static V2NIMClient* nimInstance{nullptr};
456 if (nimInstance == nullptr) {
457 void** instances = internal::callSdkFunction<void**>(internal::NIM_SDK_NAME, sdkFunctionV2InstanceGet);
458 if (instances) {
459 nimInstance = reinterpret_cast<V2NIMClient*>(instances[internal::V2_NIM_INTERNEL_INSTANCE]);
465 }
466 }
467 if (!nimInstance) {
468 throw std::runtime_error("[V2NIMClient] get instance failed");
469 }
470 return *nimInstance;
471}
472
474 static const char* sdkFunctionV2InstanceGet = "v2_nim_chatroom_instance_impl_get";
476 void** instances = internal::callSdkFunction<void**>(internal::NIM_CHATROOM_SDK_NAME, sdkFunctionV2InstanceGet);
477 if (instances) {
482 }
483 }
485 throw std::runtime_error("[V2NIMChatroomClient] init, internalChatroomSdkExport is null");
486 }
488}
489
492 throw std::runtime_error("[V2NIMChatroomClient] uninit, internalChatroomSdkExport is null");
493 }
495}
496
499 throw std::runtime_error("[V2NIMChatroomClient] newInstance, internalChatroomSdkExport is null");
500 }
502}
503
504inline void V2NIMChatroomClient::destroyInstance(uint32_t instanceId) {
506 throw std::runtime_error("[V2NIMChatroomClient] destroyInstance, internalChatroomSdkExport is null");
507 }
509}
510
513 throw std::runtime_error("[V2NIMChatroomClient] getInstance, internalChatroomSdkExport is null");
514 }
516}
517
520 throw std::runtime_error("[V2NIMChatroomClient] getInstanceList, internalChatroomSdkExport is null");
521 }
523}
524
527 throw std::runtime_error("[V2NIMChatroomClient] destroyAll, internalChatroomSdkExport is null");
528 }
530}
531} // namespace v2
532#endif
SDK库辅助类,提供加载/卸载SDK库以及获取接口的方法
Definition: nim_sdk_util.h:38
void UnLoadSdkDll()
Definition: nim_sdk_util.cpp:62
Definition: ne_stl_continuous_container.h:15
Definition: ne_stl_smart_ptr.h:30
Definition: ne_stl_string.h:19
AI 数字人服务
Definition: v2_nim_ai_service.hpp:15
Definition: v2_nim_api.hpp:215
virtual V2NIMStorageService & getStorageService()=0
获取存储服务
virtual void removeChatroomClientListener(V2NIMChatroomClientListener listener)=0
移除聊天室实例监听器
static nstd::shared_ptr< V2NIMChatroomClient > getInstance(uint32_t instanceId)
获取聊天室客户端实例
Definition: v2_nim_api.hpp:511
static nstd::vector< nstd::shared_ptr< V2NIMChatroomClient > > getInstanceList()
获取聊天室实例列表
Definition: v2_nim_api.hpp:518
virtual void addChatroomClientListener(V2NIMChatroomClientListener listener)=0
添加聊天室实例监听器
virtual void exit()=0
退出聊天室
virtual V2NIMChatroomInfo getChatroomInfo()=0
查询聊天室信息
virtual V2NIMChatroomService & getChatroomService()=0
获取聊天室服务
static void destroyAll()
销毁所有聊天室客户端实例
Definition: v2_nim_api.hpp:525
virtual void enter(nstd::string roomId, V2NIMChatroomEnterParams enterParams, V2NIMSuccessCallback< V2NIMChatroomEnterResult > success, V2NIMFailureCallback failure)=0
进入聊天室
virtual uint32_t getInstanceId()=0
获取聊天室客户端实例 ID
static void destroyInstance(uint32_t instanceId)
销毁聊天室客户端实例
Definition: v2_nim_api.hpp:504
static nstd::optional< V2NIMError > init(const V2NIMInitOption &option)
初始化
Definition: v2_nim_api.hpp:473
virtual nstd::optional< V2NIMError > updateAppKey(const nstd::string &appKey)=0
重新设置 App key,您可以在不重新初始化的情况下切换 App key
virtual ~V2NIMChatroomClient()=default
static nstd::shared_ptr< V2NIMChatroomClient > newInstance()
创建聊天室客户端实例
Definition: v2_nim_api.hpp:497
static void uninit()
反初始化
Definition: v2_nim_api.hpp:490
聊天室服务
Definition: v2_nim_chatroom_service.hpp:17
Definition: v2_nim_api.hpp:29
virtual nstd::optional< V2NIMError > initImpl(const V2NIMInitOption &option)=0
virtual V2NIMConversationService & getConversationService() const =0
获取会话服务
virtual V2NIMSettingService & getSettingService() const =0
获取设置服务
virtual V2NIMLoginService & getLoginService() const =0
获取登录服务
nstd::optional< V2NIMError > uninit()
反初始化
Definition: v2_nim_api.hpp:83
nstd::optional< V2NIMError > init(const V2NIMInitOption &option)
初始化
Definition: v2_nim_api.hpp:54
virtual nstd::optional< V2NIMError > uninitImpl()=0
static V2NIMClient & get()
获取 IM 客户端实例
Definition: v2_nim_api.hpp:453
virtual V2NIMUserService & getUserService() const =0
获取用户资料服务
virtual V2NIMSignallingService & getSignallingService() const =0
获取信令服务
virtual nstd::optional< V2NIMError > updateAppKey(const nstd::string &appKey)=0
重新设置 App key,您可以在不重新初始化的情况下切换 App key
virtual V2NIMNotificationService & getNotificationService() const =0
获取通知服务
virtual V2NIMStorageService & getStorageService() const =0
获取存储服务
virtual V2NIMMessageService & getMessageService() const =0
获取消息服务
virtual V2NIMFriendService & getFriendService() const =0
获取好友服务
virtual V2NIMConversationGroupService & getConversationGroupService() const =0
获取会话分组服务
virtual V2NIMAIService & getAIService() const =0
获取 AI 服务
virtual V2NIMSubscriptionService & getSubscriptionService() const =0
获取订阅服务
virtual V2NIMTeamService & getTeamService() const =0
获取群组服务
会话分组服务
Definition: v2_nim_conversation_group_service.hpp:14
会话服务
Definition: v2_nim_conversation_service.hpp:15
好友服务
Definition: v2_nim_friend_service.hpp:14
登录服务
Definition: v2_nim_login_service.hpp:14
消息服务
Definition: v2_nim_message_service.hpp:14
通知服务
Definition: v2_nim_notification_service.hpp:14
通知服务
Definition: v2_nim_setting_service.hpp:14
信令服务
Definition: v2_nim_signalling_service.hpp:17
存储服务
Definition: v2_nim_storage_service.hpp:14
Definition: v2_nim_subscription_service.hpp:8
通用成功
Definition: v2_nim_def_callback.hpp:7
群组服务
Definition: v2_nim_team_service.hpp:15
用户资料服务
Definition: v2_nim_user_service.hpp:14
Definition: v2_nim_internal.hpp:91
Definition: v2_nim_api.hpp:440
virtual nstd::vector< nstd::shared_ptr< V2NIMChatroomClient > > getInstanceList()=0
virtual nstd::shared_ptr< V2NIMChatroomClient > newInstance()=0
virtual nstd::shared_ptr< V2NIMChatroomClient > getInstance(uint32_t instanceId)=0
virtual nstd::optional< V2NIMError > init(const V2NIMInitOption &option)=0
virtual void destroyInstance(uint32_t instanceId)=0
Definition: v2_nim_internal.hpp:35
Definition: v2_nim_internal.hpp:42
Definition: v2_nim_internal.hpp:53
namespace nim
nim::SDKInstance * nim_sdk_instance
Definition: nim_qchat_helper.h:12
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
V2NIMChatroomSdkExport * internalChatroomSdkExport
Definition: v2_nim_api.hpp:450
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
@ 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
SDK库辅助方法
Definition: ne_stl_optional.h:16
Definition: ne_stl_bind.h:132
Definition: v2_nim_def_callback.hpp:204
Definition: v2_nim_def_struct.hpp:1744
Definition: v2_nim_def_struct.hpp:1773
Definition: v2_nim_def_struct.hpp:117