NIM 跨平台 C++ SDK
载入中...
搜索中...
未找到
v2_nim_api.hpp
浏览该文件的文档.
1#ifndef V2_NIM_API_H
2#define V2_NIM_API_H
19#if defined(WIN32) || defined(_WIN32)
20#include "wtypes.h"
21#else
22#include <dlfcn.h>
23#endif
24#ifdef ENABLE_NIM_V1
26namespace nim {
28} // namespace nim
29#endif
30namespace v2 {
32public:
39 static V2NIMClient& get();
40
57 auto error = initImpl(option);
58#ifdef ENABLE_NIM_V1
59 if (!error && !nim::nim_sdk_instance) {
61 if (!nim::nim_sdk_instance->LoadSdkDll("", internal::NIM_SDK_NAME)) {
63 nim::nim_sdk_instance = nullptr;
64 throw std::runtime_error("[V2NIMClient] load v1 sdk failed");
65 }
66 }
67#endif
68 return error;
69 }
70
73
86 auto error = uninitImpl();
87#ifdef ENABLE_NIM_V1
88 if (!error && nim::nim_sdk_instance) {
91 nim::nim_sdk_instance = nullptr;
92 }
93#endif
94 return error;
95 }
96
99
111
118 virtual V2NIMLoginService& getLoginService() const = 0;
119
127
135
143
151
159
166 virtual V2NIMTeamService& getTeamService() const = 0;
167
175
182 virtual V2NIMUserService& getUserService() const = 0;
183
191
198 virtual V2NIMAIService& getAIService() const = 0;
199
207
215
223};
224
226public:
227 virtual ~V2NIMChatroomClient() = default;
243 static nstd::optional<V2NIMError> init(const V2NIMInitOption& option);
244
252 static void uninit();
253
271
284 static void destroyInstance(uint32_t instanceId);
285
301 static nstd::shared_ptr<V2NIMChatroomClient> getInstance(uint32_t instanceId);
302
311
320 static void destroyAll();
321
329 virtual uint32_t getInstanceId() = 0;
330
343
375 virtual void enter(nstd::string roomId,
376 V2NIMChatroomEnterParams enterParams,
378 V2NIMFailureCallback failure) = 0;
379
386 virtual void exit() = 0;
387
395
403
411
419
441
454};
455
457namespace internal {
459public:
461 virtual void uninit() = 0;
463 virtual void destroyInstance(uint32_t instanceId) = 0;
464 virtual nstd::shared_ptr<V2NIMChatroomClient> getInstance(uint32_t instanceId) = 0;
466 virtual void destroyAll() = 0;
467};
469} // namespace internal
470
472 static const char* sdkFunctionV2InstanceGet = "v2_nim_instance_impl_get";
473 static V2NIMClient* nimInstance{nullptr};
474 if (nimInstance == nullptr) {
475 void** instances = internal::callSdkFunction<void**>(internal::NIM_SDK_NAME, sdkFunctionV2InstanceGet);
476 if (instances) {
477 nimInstance = reinterpret_cast<V2NIMClient*>(instances[internal::V2_NIM_INTERNEL_INSTANCE]);
483 }
484 }
485 if (!nimInstance) {
486 throw std::runtime_error("[V2NIMClient] get instance failed");
487 }
488 return *nimInstance;
489}
490
492 static const char* sdkFunctionV2InstanceGet = "v2_nim_chatroom_instance_impl_get";
494 void** instances = internal::callSdkFunction<void**>(internal::NIM_CHATROOM_SDK_NAME, sdkFunctionV2InstanceGet);
495 if (instances) {
500 }
501 }
503 throw std::runtime_error("[V2NIMChatroomClient] init, internalChatroomSdkExport is null");
504 }
506}
507
510 throw std::runtime_error("[V2NIMChatroomClient] uninit, internalChatroomSdkExport is null");
511 }
513}
514
517 throw std::runtime_error("[V2NIMChatroomClient] newInstance, internalChatroomSdkExport is null");
518 }
520}
521
522inline void V2NIMChatroomClient::destroyInstance(uint32_t instanceId) {
524 throw std::runtime_error("[V2NIMChatroomClient] destroyInstance, internalChatroomSdkExport is null");
525 }
527}
528
531 throw std::runtime_error("[V2NIMChatroomClient] getInstance, internalChatroomSdkExport is null");
532 }
534}
535
538 throw std::runtime_error("[V2NIMChatroomClient] getInstanceList, internalChatroomSdkExport is null");
539 }
541}
542
545 throw std::runtime_error("[V2NIMChatroomClient] destroyAll, internalChatroomSdkExport is null");
546 }
548}
549} // namespace v2
550#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:225
virtual V2NIMStorageService & getStorageService()=0
获取存储服务
virtual V2NIMChatroomQueueService & getChatroomQueueService()=0
获取聊天室队列服务
virtual void removeChatroomClientListener(V2NIMChatroomClientListener listener)=0
移除聊天室实例监听器
static nstd::shared_ptr< V2NIMChatroomClient > getInstance(uint32_t instanceId)
获取聊天室客户端实例
Definition: v2_nim_api.hpp:529
static nstd::vector< nstd::shared_ptr< V2NIMChatroomClient > > getInstanceList()
获取聊天室实例列表
Definition: v2_nim_api.hpp:536
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:543
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:522
static nstd::optional< V2NIMError > init(const V2NIMInitOption &option)
初始化
Definition: v2_nim_api.hpp:491
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:515
static void uninit()
反初始化
Definition: v2_nim_api.hpp:508
Definition: v2_nim_chatroom_queue_service.hpp:8
聊天室服务
Definition: v2_nim_chatroom_service.hpp:17
Definition: v2_nim_api.hpp:31
virtual nstd::optional< V2NIMError > initImpl(const V2NIMInitOption &option)=0
virtual V2NIMConversationService & getConversationService() const =0
获取会话服务
virtual V2NIMSettingService & getSettingService() const =0
获取设置服务
virtual V2NIMPassthroughService & getPassthroughService() const =0
获取透传服务
virtual V2NIMLoginService & getLoginService() const =0
获取登录服务
nstd::optional< V2NIMError > uninit()
反初始化
Definition: v2_nim_api.hpp:85
nstd::optional< V2NIMError > init(const V2NIMInitOption &option)
初始化
Definition: v2_nim_api.hpp:56
virtual nstd::optional< V2NIMError > uninitImpl()=0
static V2NIMClient & get()
获取 IM 客户端实例
Definition: v2_nim_api.hpp:471
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_passthrough_service.hpp:8
通知服务
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:458
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:468
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:1773
Definition: v2_nim_def_struct.hpp:1802
Definition: v2_nim_def_struct.hpp:121