std::string Talk::CreateVideoMessage(const std::string& receiver_id , const NIMSessionType session_type , const std::string& client_msg_id , const IMVideo& video , const std::string& file_path , const MessageSetting& msg_setting , __int64 timetag/* = 0*/) { Json::Value values; values[kNIMMsgKeyToAccount] = receiver_id; values[kNIMMsgKeyToType] = session_type; values[kNIMMsgKeyClientMsgid] = client_msg_id; values[kNIMMsgKeyAttach] = video.ToJsonString(); values[kNIMMsgKeyType] = kNIMMessageTypeVideo; values[kNIMMsgKeyLocalFilePath] = file_path; values[kNIMMsgKeyLocalTalkId] = receiver_id; values[kNIMMsgKeyLocalResId] = client_msg_id; msg_setting.ToJsonValue(values); //选填 if (timetag > 0) values[kNIMMsgKeyTime] = timetag; return GetJsonStringWithNoStyled(values); }
bool StrListToJsonString(const std::list<std::string>& list, std::string& out) { Json::Value json_ids; for (auto it = list.begin(); it != list.end(); it++) { json_ids.append(*it); } out = GetJsonStringWithNoStyled(json_ids); return true; }
bool Talk::StopSendMsg(const std::string& client_msg_id, const NIMMessageType& type, const std::string& json_extension/* = ""*/) { if (client_msg_id.empty()) return false; Json::Value values; values[kNIMMsgKeyClientMsgid] = client_msg_id; values[kNIMMsgKeyType] = type; NIM_SDK_GET_FUNC(nim_talk_stop_send_msg)(GetJsonStringWithNoStyled(values).c_str(), json_extension.c_str()); return true; }
std::string ChatRoom::CreateRoomMessage(const NIMChatRoomMsgType msg_type , const std::string& client_msg_id , const std::string& attach , const std::string& ext/* = ""*/ , bool resend/* = false*/) { Json::Value values; values[kNIMChatRoomMsgKeyType] = msg_type; values[kNIMChatRoomMsgKeyAttach] = attach; values[kNIMChatRoomMsgKeyClientMsgid] = client_msg_id; values[kNIMChatRoomMsgKeyResendFlag] = resend ? 1 : 0; values[kNIMChatRoomMsgKeyExt] = ext; return GetJsonStringWithNoStyled(values); }
std::string Talk::CreateTipMessage(const std::string& receiver_id , const NIMSessionType session_type , const std::string& client_msg_id , const Json::Value& tips , const MessageSetting& msg_setting , __int64 timetag/* = 0*/) { Json::Value values; values[kNIMMsgKeyToAccount] = receiver_id; values[kNIMMsgKeyToType] = session_type; values[kNIMMsgKeyClientMsgid] = client_msg_id; values[kNIMMsgKeyServerExt] = GetJsonStringWithNoStyled(tips); values[kNIMMsgKeyType] = kNIMMessageTypeTips; values[kNIMMsgKeyLocalTalkId] = receiver_id; msg_setting.ToJsonValue(values); //选填 if (timetag > 0) values[kNIMMsgKeyTime] = timetag; return GetJsonStringWithNoStyled(values); }
void Client::SetMultiportPushConfigAsync(bool switch_on, const MultiportPushConfigCallback& cb, const std::string& json_extension/* = ""*/) { MultiportPushConfigCallback* cb_pointer = nullptr; if (cb) { cb_pointer = new MultiportPushConfigCallback(cb); } Json::Value values; Json::FastWriter fw; values[kNIMMultiportPushConfigContentKeyOpen] = switch_on ? 1 : 2; NIM_SDK_GET_FUNC(nim_client_set_multiport_push_config)(GetJsonStringWithNoStyled(values).c_str() , json_extension.c_str() , &CallbackMultiportPushConfig , cb_pointer); }
std::string SystemMsg::CreateCustomNotificationMsg(const std::string& receiver_id , const NIMSysMsgType type , const std::string& client_msg_id , const std::string& content , bool support_offline , const std::string& apns_text/* = ""*/) { Json::Value values; values[kNIMSysMsgKeyToAccount] = receiver_id; values[kNIMSysMsgKeyType] = type; values[kNIMSysMsgKeyAttach] = content; values[kNIMSysMsgKeyLocalClientMsgId] = client_msg_id; values[kNIMSysMsgKeyCustomSaveFlag] = support_offline ? 1 : 0; values[kNIMSysMsgKeyCustomApnsText] = apns_text; return GetJsonStringWithNoStyled(values); }
bool User::GetUserNameCardOnline(const std::list<std::string>& accids, const GetUserNameCardCallback& cb, const std::string& json_extension /*= ""*/) { if (accids.empty()) return false; GetUserNameCardCallback* cb_pointer = nullptr; if (cb) { cb_pointer = new GetUserNameCardCallback(cb); } Json::Value values; for (auto iter = accids.cbegin(); iter != accids.cend(); ++iter) values.append(*iter); NIM_SDK_GET_FUNC(nim_user_get_user_name_card_online)(GetJsonStringWithNoStyled(values).c_str(), json_extension.c_str(), &CallbackGetUserNameCard, cb_pointer); return true; }
bool Tool::GetAudioTextAsync(const AudioInfo& audio_info, const GetAudioTextCallback& cb, const std::string& json_extension) { if (audio_info.mime_type_.empty() || audio_info.samplerate_.empty() || audio_info.url_.empty() || audio_info.duration_ <= 0) return false; GetAudioTextCallback* cb_pointer = nullptr; if (cb) { cb_pointer = new GetAudioTextCallback(cb); } Json::Value json_value; json_value[nim::kNIMTransAudioKeyMime] = audio_info.mime_type_; json_value[nim::kNIMTransAudioKeySample] = audio_info.samplerate_; json_value[nim::kNIMTransAudioKeyAudioUrl] = audio_info.url_; json_value[nim::kNIMTransAudioKeyDuration] = audio_info.duration_; NIM_SDK_GET_FUNC(nim_tool_get_audio_text_async)(GetJsonStringWithNoStyled(json_value).c_str(), json_extension.c_str(), &CallbackGetAudioText, cb_pointer); return true; }
bool Client::Init(const std::string& app_data_dir , const std::string& app_install_dir , const SDKConfig &config) { #ifdef NIM_SDK_DLL_IMPORT #if !defined (WIN32) static const char *kSdkNimDll = "libnim.so"; #elif defined (_DEBUG) || defined (DEBUG) static const char *kSdkNimDll = "nim_d.dll"; #else static const char *kSdkNimDll = "nim.dll"; #endif if (NULL == g_nim_sdk_instance) { g_nim_sdk_instance = new SDKInstance(); } if (!g_nim_sdk_instance->LoadSdkDll(app_install_dir.c_str(), kSdkNimDll)) return false; #endif Json::Value config_root; //sdk能力参数(必填) Json::Value config_values; config_values[nim::kNIMDataBaseEncryptKey] = config.database_encrypt_key_; config_values[nim::kNIMPreloadAttach] = config.preload_attach_; config_values[nim::kNIMPreloadImageQuality] = config.preload_image_quality_; config_values[nim::kNIMPreloadImageResize] = config.preload_image_resize_; config_values[nim::kNIMSDKLogLevel] = config.sdk_log_level_; config_values[nim::kNIMSyncSessionAck] = config.sync_session_ack_; config_values["custom_timeout"] = config.custom_timeout_; config_root[nim::kNIMGlobalConfig] = config_values; if (config.use_private_server_) { Json::Value srv_config; srv_config[nim::kNIMLbsAddress] = config.lbs_address_; srv_config[nim::kNIMNosLbsAddress] = config.nos_lbs_address_; for (auto iter = config.default_link_address_.begin(); iter != config.default_link_address_.end(); ++iter) srv_config[nim::kNIMDefaultLinkAddress].append(*iter); for (auto iter = config.default_nos_upload_address_.begin(); iter != config.default_nos_upload_address_.end(); ++iter) srv_config[nim::kNIMDefaultNosUploadAddress].append(*iter); for (auto iter = config.default_nos_download_address_.begin(); iter != config.default_nos_download_address_.end(); ++iter) srv_config[nim::kNIMDefaultNosDownloadAddress].append(*iter); for (auto iter = config.default_nos_access_address_.begin(); iter != config.default_nos_access_address_.end(); ++iter) srv_config[nim::kNIMDefaultNosAccessAddress].append(*iter); srv_config[nim::kNIMRsaPublicKeyModule] = config.rsa_public_key_module_; srv_config[nim::kNIMRsaVersion] = config.rsa_version_; config_root[nim::kNIMPrivateServerSetting] = srv_config; } return NIM_SDK_GET_FUNC(nim_client_init)(app_data_dir.c_str(), app_install_dir.c_str(), GetJsonStringWithNoStyled(config_root).c_str()); }