├── Resources └── Icon128.png ├── Source └── XMPPChat │ ├── Private │ ├── XMPPChatPrivatePCH.h │ ├── XMPPChat.cpp │ └── Chat.cpp │ ├── Public │ ├── XMPPChat.h │ └── Chat.h │ └── XMPPChat.Build.cs ├── XMPPChat.uplugin └── LICENSE /Resources/Icon128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DescendentStudios/XMPPChatPlugin/HEAD/Resources/Icon128.png -------------------------------------------------------------------------------- /Source/XMPPChat/Private/XMPPChatPrivatePCH.h: -------------------------------------------------------------------------------- 1 | // Copyright 1998-2015 Epic Games, Inc. All Rights Reserved. 2 | 3 | #include "XMPPChat.h" 4 | 5 | // You should place include statements to your module's private header files here. You only need to 6 | // add includes for headers that are used in most of your module's source files though. -------------------------------------------------------------------------------- /Source/XMPPChat/Public/XMPPChat.h: -------------------------------------------------------------------------------- 1 | // Copyright 1998-2015 Epic Games, Inc. All Rights Reserved. 2 | 3 | #pragma once 4 | 5 | #include "ModuleManager.h" 6 | 7 | class FXMPPChatModule : public IModuleInterface 8 | { 9 | public: 10 | 11 | /** IModuleInterface implementation */ 12 | virtual void StartupModule() override; 13 | virtual void ShutdownModule() override; 14 | }; -------------------------------------------------------------------------------- /XMPPChat.uplugin: -------------------------------------------------------------------------------- 1 | { 2 | "FileVersion": 3, 3 | "Version": 1, 4 | "VersionName": "1.0", 5 | "FriendlyName": "XMPPChat", 6 | "Description": "Use XMPP Module from Blueprint", 7 | "Category": "Network", 8 | "CreatedBy": "", 9 | "CreatedByURL": "", 10 | "DocsURL": "", 11 | "MarketplaceURL": "", 12 | "SupportURL": "", 13 | "Modules": [ 14 | { 15 | "Name": "XMPPChat", 16 | "Type": "Runtime", 17 | "LoadingPhase": "PreDefault" 18 | } 19 | ], 20 | "EnabledByDefault": false, 21 | "CanContainContent": false, 22 | "IsBetaVersion": false, 23 | "Installed": false 24 | } -------------------------------------------------------------------------------- /Source/XMPPChat/Private/XMPPChat.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 1998-2015 Epic Games, Inc. All Rights Reserved. 2 | 3 | #include "XMPPChatPrivatePCH.h" 4 | 5 | #define LOCTEXT_NAMESPACE "FXMPPChatModule" 6 | 7 | void FXMPPChatModule::StartupModule() 8 | { 9 | // This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module 10 | } 11 | 12 | void FXMPPChatModule::ShutdownModule() 13 | { 14 | // This function may be called during shutdown to clean up your module. For modules that support dynamic reloading, 15 | // we call this function before unloading the module. 16 | } 17 | 18 | #undef LOCTEXT_NAMESPACE 19 | 20 | IMPLEMENT_MODULE(FXMPPChatModule, XMPPChat) -------------------------------------------------------------------------------- /Source/XMPPChat/XMPPChat.Build.cs: -------------------------------------------------------------------------------- 1 | // Copyright 1998-2015 Epic Games, Inc. All Rights Reserved. 2 | 3 | using UnrealBuildTool; 4 | 5 | public class XMPPChat : ModuleRules 6 | { 7 | public XMPPChat(TargetInfo Target) 8 | { 9 | 10 | PublicIncludePaths.AddRange( 11 | new string[] { 12 | "XMPPChat/Public" 13 | // ... add public include paths required here ... 14 | } 15 | ); 16 | 17 | 18 | PrivateIncludePaths.AddRange( 19 | new string[] { 20 | "XMPPChat/Private", 21 | // ... add other private include paths required here ... 22 | } 23 | ); 24 | 25 | 26 | PublicDependencyModuleNames.AddRange( 27 | new string[] 28 | { 29 | "Core", 30 | // ... add other public dependencies that you statically link with here ... 31 | } 32 | ); 33 | 34 | 35 | PrivateDependencyModuleNames.AddRange( 36 | new string[] 37 | { 38 | "CoreUObject", 39 | "Engine", 40 | "Slate", 41 | "SlateCore", 42 | "XMPP", 43 | // ... add private dependencies that you statically link with here ... 44 | } 45 | ); 46 | 47 | 48 | DynamicallyLoadedModuleNames.AddRange( 49 | new string[] 50 | { 51 | // ... add any modules that your module loads dynamically here ... 52 | } 53 | ); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Source/XMPPChat/Public/Chat.h: -------------------------------------------------------------------------------- 1 | // (c) 2015 Descendent Studios, Inc. 2 | 3 | #pragma once 4 | 5 | #include "Engine.h" 6 | #include "Xmpp.h" 7 | #include "Chat.generated.h" 8 | 9 | 10 | DECLARE_LOG_CATEGORY_EXTERN(LogChat, Warning, All); 11 | 12 | /** 13 | * BP Enum EUXmppPresenceStatus mapping to non-BP EXmppPresenceStatus 14 | */ 15 | UENUM(BlueprintType) 16 | namespace EUXmppPresenceStatus 17 | { 18 | enum Type 19 | { 20 | Online, 21 | Offline, 22 | Away, 23 | ExtendedAway, 24 | DoNotDisturb, 25 | Chat 26 | }; 27 | } 28 | 29 | /** 30 | * BP Enum EUXmppLoginStatus mapping to non-BP EXmppLoginStatus 31 | * Possible XMPP login states 32 | */ 33 | UENUM(BlueprintType) 34 | namespace EUXmppLoginStatus 35 | { 36 | enum Type 37 | { 38 | LoggedIn, 39 | LoggedOut 40 | }; 41 | } 42 | 43 | /** 44 | * BP Enum EXmppChatMemberRole mapping to non-BP EUChatMemberRole 45 | * Role of a chat room member 46 | */ 47 | UENUM(BlueprintType) 48 | namespace EUChatMemberRole 49 | { 50 | enum Type 51 | { 52 | Owner, 53 | Moderator, 54 | Member, 55 | None, 56 | Outcast 57 | }; 58 | } 59 | 60 | namespace UChatUtil 61 | { 62 | inline EXmppPresenceStatus::Type GetEXmppPresenceStatus(const EUXmppPresenceStatus::Type Status) 63 | { 64 | switch (Status) 65 | { 66 | case EUXmppPresenceStatus::Online: return EXmppPresenceStatus::Online; 67 | case EUXmppPresenceStatus::Offline: return EXmppPresenceStatus::Offline; 68 | case EUXmppPresenceStatus::Away: return EXmppPresenceStatus::Away; 69 | case EUXmppPresenceStatus::ExtendedAway: return EXmppPresenceStatus::ExtendedAway; 70 | case EUXmppPresenceStatus::DoNotDisturb: return EXmppPresenceStatus::DoNotDisturb; 71 | default: 72 | case EUXmppPresenceStatus::Chat: return EXmppPresenceStatus::Chat; 73 | } 74 | } 75 | 76 | inline EUXmppPresenceStatus::Type GetEUXmppPresenceStatus(const EXmppPresenceStatus::Type Status) 77 | { 78 | switch (Status) 79 | { 80 | case EXmppPresenceStatus::Online: return EUXmppPresenceStatus::Online; 81 | case EXmppPresenceStatus::Offline: return EUXmppPresenceStatus::Offline; 82 | case EXmppPresenceStatus::Away: return EUXmppPresenceStatus::Away; 83 | case EXmppPresenceStatus::ExtendedAway: return EUXmppPresenceStatus::ExtendedAway; 84 | case EXmppPresenceStatus::DoNotDisturb: return EUXmppPresenceStatus::DoNotDisturb; 85 | default: 86 | case EXmppPresenceStatus::Chat: return EUXmppPresenceStatus::Chat; 87 | } 88 | } 89 | 90 | inline EUXmppLoginStatus::Type GetEUXmppLoginStatus(EXmppLoginStatus::Type status) 91 | { 92 | switch (status) 93 | { 94 | case EXmppLoginStatus::LoggedIn: return EUXmppLoginStatus::LoggedIn; 95 | default: 96 | case EXmppLoginStatus::LoggedOut: return EUXmppLoginStatus::LoggedOut; 97 | } 98 | } 99 | 100 | inline EUChatMemberRole::Type GetEUChatMemberRole(const EXmppChatMemberRole::Type Status) 101 | { 102 | switch (Status) 103 | { 104 | case EXmppChatMemberRole::Owner: return EUChatMemberRole::Owner; 105 | case EXmppChatMemberRole::Moderator: return EUChatMemberRole::Moderator; 106 | case EXmppChatMemberRole::Member: return EUChatMemberRole::Member; 107 | case EXmppChatMemberRole::None: return EUChatMemberRole::None; 108 | default: 109 | case EXmppChatMemberRole::Outcast: return EUChatMemberRole::Outcast; 110 | } 111 | } 112 | } 113 | 114 | /** Generate a delegates for callback events */ 115 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnChatLoginComplete, const FString&, UserJid, bool, bWasSuccess, const FString&, Error); 116 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnChatLogoutComplete, const FString&, UserJid, bool, bWasSuccess, const FString&, Error); 117 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnChatLogingChanged, const FString&, UserJid, EUXmppLoginStatus::Type, LoginStatus); 118 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnChatReceiveMessage, const FString&, UserJid, const FString&, Type, const FString&, Message); 119 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnPrivateChatReceiveMessage, const FString&, UserJid, const FString&, Message); 120 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnMUCReceiveMessage, const FString&, RoomId, const FString&, UserJid, const FString&, Message); 121 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnMUCRoomJoinPublicComplete, bool, bSuccess, const FString&, RoomId, const FString&, Error); 122 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnMUCRoomJoinPrivateComplete, bool, bSuccess, const FString&, RoomId, const FString&, Error); 123 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnMUCRoomMemberJoin, const FString&, RoomId, const FString&, UserJid); 124 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnMUCRoomMemberExit, const FString&, RoomId, const FString&, UserJid); 125 | DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnMUCRoomMemberChanged, const FString&, RoomId, const FString&, UserJid); 126 | 127 | /** 128 | * BP version of FXmppChatMember 129 | * Member of a chat room 130 | */ 131 | UCLASS(BlueprintType, Blueprintable) 132 | class UChatMember : public UObject 133 | { 134 | public: 135 | 136 | GENERATED_UCLASS_BODY() 137 | 138 | UPROPERTY(BlueprintReadOnly, Category = "Chat|Member") 139 | FString Nickname; 140 | 141 | UPROPERTY(BlueprintReadOnly, Category = "Chat|Member") 142 | FString MemberJid; 143 | 144 | /** state of basic online status */ 145 | UPROPERTY(BlueprintReadOnly, Category = "Chat|Member") 146 | TEnumAsByte Status; 147 | 148 | /** connected an available to receive messages */ 149 | UPROPERTY(BlueprintReadOnly, Category = "Chat|Member") 150 | bool bIsAvailable; 151 | 152 | /** time when presence was sent by the user */ 153 | UPROPERTY(BlueprintReadOnly, Category = "Chat|Member") 154 | FDateTime SentTime; 155 | 156 | /** client id user is logged in from */ 157 | UPROPERTY(BlueprintReadOnly, Category = "Chat|Member") 158 | FString ClientResource; 159 | 160 | /** string that will be parsed for further displayed presence info */ 161 | UPROPERTY(BlueprintReadOnly, Category = "Chat|Member") 162 | FString StatusStr; 163 | 164 | UPROPERTY(BlueprintReadOnly, Category = "Chat|Member") 165 | TEnumAsByte Affiliation; 166 | 167 | void ConvertFrom(const FXmppChatMember& ChatMember); 168 | }; 169 | 170 | 171 | /** 172 | * Chat class representing a connection to a chat server 173 | */ 174 | UCLASS(BlueprintType, Blueprintable) 175 | class UChat : public UObject 176 | { 177 | GENERATED_UCLASS_BODY() 178 | 179 | protected: 180 | TSharedPtr XmppConnection; 181 | 182 | // Map BP Enum EUXmppPresenceStatus mapping to non-BP EXmppPresenceStatus 183 | EXmppPresenceStatus::Type GetEXmppPresenceStatus(const EUXmppPresenceStatus::Type Status); 184 | 185 | // Map non-BP EXmppLoginStatus to BP Enum EUXmppLoginStatus 186 | EUXmppLoginStatus::Type GetEUXmppLoginStatus(EXmppLoginStatus::Type status); 187 | 188 | // has this chat's delegates been set up, etc. 189 | bool bInited; 190 | 191 | // has this chat been completed? 192 | bool bDone; 193 | 194 | public: 195 | // Delegates for BP events 196 | 197 | UPROPERTY(BlueprintAssignable, Category = "Chat|State") 198 | FOnChatLoginComplete OnChatLoginComplete; 199 | 200 | UPROPERTY(BlueprintAssignable, Category = "Chat|State") 201 | FOnChatLogoutComplete OnChatLogoutComplete; 202 | 203 | UPROPERTY(BlueprintAssignable, Category = "Chat|State") 204 | FOnChatLogingChanged OnChatLogingChanged; 205 | 206 | UPROPERTY(BlueprintAssignable, Category = "Chat|Message") 207 | FOnChatReceiveMessage OnChatReceiveMessage; 208 | 209 | UPROPERTY(BlueprintAssignable, Category = "Chat|Message") 210 | FOnPrivateChatReceiveMessage OnPrivateChatReceiveMessage; 211 | 212 | UPROPERTY(BlueprintAssignable, Category = "Chat|MUC") 213 | FOnMUCReceiveMessage OnMUCReceiveMessage; 214 | 215 | UPROPERTY(BlueprintAssignable, Category = "Chat|MUC") 216 | FOnMUCRoomJoinPublicComplete OnMUCRoomJoinPublicComplete; 217 | 218 | UPROPERTY(BlueprintAssignable, Category = "Chat|MUC") 219 | FOnMUCRoomJoinPrivateComplete OnMUCRoomJoinPrivateComplete; 220 | 221 | UPROPERTY(BlueprintAssignable, Category = "Chat|MUC") 222 | FOnMUCRoomMemberJoin OnMUCRoomMemberJoin; 223 | 224 | UPROPERTY(BlueprintAssignable, Category = "Chat|MUC") 225 | FOnMUCRoomMemberExit OnMUCRoomMemberExit; 226 | 227 | UPROPERTY(BlueprintAssignable, Category = "Chat|MUC") 228 | FOnMUCRoomMemberChanged OnMUCRoomMemberChanged; 229 | 230 | public: 231 | // Callbacks for delegates 232 | 233 | void OnLoginCompleteFunc(const FXmppUserJid& UserJid, bool bWasSuccess, const FString& Error); 234 | void OnLogoutCompleteFunc(const FXmppUserJid& UserJid, bool bWasSuccess, const FString& Error); 235 | void OnLogingChangedFunc(const FXmppUserJid& UserJid, EXmppLoginStatus::Type LoginStatus); 236 | 237 | void OnChatReceiveMessageFunc(const TSharedRef& Connection, const FXmppUserJid& FromJid, const TSharedRef& Message); 238 | void OnPrivateChatReceiveMessageFunc(const TSharedRef& Connection, const FXmppUserJid& FromJid, const TSharedRef& Message); 239 | 240 | void OnMUCReceiveMessageFunc(const TSharedRef& Connection, const FXmppRoomId& RoomId, const FXmppUserJid& UserJid, const TSharedRef& ChatMsg); 241 | void OnMUCRoomJoinPublicCompleteFunc(const TSharedRef& Connection, bool bSuccess, const FXmppRoomId& RoomId, const FString& Error); 242 | void OnMUCRoomJoinPrivateCompleteFunc(const TSharedRef& Connection, bool bSuccess, const FXmppRoomId& RoomId, const FString& Error); 243 | 244 | void OnMUCRoomMemberJoinFunc(const TSharedRef& Connection, const FXmppRoomId& RoomId, const FXmppUserJid& UserJid); 245 | void OnMUCRoomMemberExitFunc(const TSharedRef& Connection, const FXmppRoomId& RoomId, const FXmppUserJid& UserJid); 246 | void OnMUCRoomMemberChangedFunc(const TSharedRef& Connection, const FXmppRoomId& RoomId, const FXmppUserJid& UserJid); 247 | 248 | protected: 249 | FDelegateHandle OnLoginCompleteHandle; 250 | FDelegateHandle OnLogoutCompleteHandle; 251 | FDelegateHandle OnLogingChangedHandle; 252 | FDelegateHandle OnPrivateChatReceiveMessageHandle; 253 | FDelegateHandle OnChatReceiveMessageHandle; 254 | FDelegateHandle OnMUCReceiveMessageHandle; 255 | FDelegateHandle OnMUCRoomJoinPublicCompleteHandle; 256 | FDelegateHandle OnMUCRoomJoinPrivateCompleteHandle; 257 | FDelegateHandle OnMUCRoomMemberJoinHandle; 258 | FDelegateHandle OnMUCRoomMemberExitHandle; 259 | FDelegateHandle OnMUCRoomMemberChangedHandle; 260 | 261 | protected: 262 | void Init(); 263 | void DeInit(); 264 | 265 | public: 266 | ~UChat(); 267 | 268 | /***************** Base **************************/ 269 | 270 | UFUNCTION(BlueprintCallable, Category = "Chat|State") 271 | void Finish(); 272 | 273 | /***************** Login/Logout **************************/ 274 | 275 | void Login(const FString& UserId, const FString& Auth, const FXmppServer& XmppServer); 276 | 277 | UFUNCTION(BlueprintCallable, Category = "Chat|State") 278 | void Login(const FString& UserId, const FString& Auth, const FString& ServerAddr, const FString& Domain, const FString& ClientResource); 279 | 280 | UFUNCTION(BlueprintCallable, Category = "Chat|State") 281 | void Logout(); 282 | 283 | /***************** Chat **************************/ 284 | 285 | UFUNCTION(BlueprintCallable, Category = "Chat|Message") 286 | void Message(const FString& UserName, const FString& Recipient, const FString& Type, const FString& MessagePayload); 287 | 288 | UFUNCTION(BlueprintCallable, Category = "Chat|Message") 289 | void PrivateChat(const FString& UserName, const FString& Recipient, const FString& Body); 290 | 291 | /***************** Presence **************************/ 292 | 293 | UFUNCTION(BlueprintCallable, Category = "Chat|Presence") 294 | void Presence(bool bIsAvailable, EUXmppPresenceStatus::Type Status, const FString& StatusStr); 295 | 296 | UFUNCTION(BlueprintCallable, Category = "Chat|Presence") 297 | void PresenceQuery(const FString& User); 298 | 299 | UFUNCTION(BlueprintCallable, Category = "Chat|Presence") 300 | void PresenceGetRosterMembers(TArray& Members); 301 | 302 | /***************** MUC **************************/ 303 | 304 | UFUNCTION(BlueprintCallable, Category = "Chat|MUC") 305 | void MucCreate(const FString& UserName, const FString& RoomId, bool bIsPrivate = false, const FString& Password = ""); 306 | 307 | UFUNCTION(BlueprintCallable, Category = "Chat|MUC") 308 | void MucJoin(const FString& RoomId, const FString& Nickname, const FString& Password); 309 | 310 | UFUNCTION(BlueprintCallable, Category = "Chat|MUC") 311 | void MucExit(const FString& RoomId); 312 | 313 | UFUNCTION(BlueprintCallable, Category = "Chat|MUC") 314 | void MucChat(const FString& RoomId, const FString& Body); 315 | 316 | UFUNCTION(BlueprintCallable, Category = "Chat|MUC") 317 | void MucConfig(const FString& UserName, const FString& RoomId, bool bIsPrivate, const FString& Password); 318 | 319 | UFUNCTION(BlueprintCallable, Category = "Chat|MUC") 320 | void MucRefresh(const FString& RoomId); 321 | 322 | UFUNCTION(BlueprintCallable, Category = "Chat|MUC") 323 | void MucGetMembers(const FString& RoomId, TArray& Members); 324 | 325 | /***************** PubSub **************************/ 326 | 327 | UFUNCTION(BlueprintCallable, Category = "Chat|PubSub") 328 | void PubSubCreate(const FString& NodeId); 329 | 330 | UFUNCTION(BlueprintCallable, Category = "Chat|PubSub") 331 | void PubSubDestroy(const FString& NodeId); 332 | 333 | UFUNCTION(BlueprintCallable, Category = "Chat|PubSub") 334 | void PubSubSubscribe(const FString& NodeId); 335 | 336 | UFUNCTION(BlueprintCallable, Category = "Chat|PubSub") 337 | void PubSubUnsubscribe(const FString& NodeId); 338 | 339 | UFUNCTION(BlueprintCallable, Category = "Chat|PubSub") 340 | void PubSubPublish(const FString& NodeId, const FString& Payload); 341 | }; -------------------------------------------------------------------------------- /Source/XMPPChat/Private/Chat.cpp: -------------------------------------------------------------------------------- 1 | // (c) 2015 Descendent Studios, Inc. 2 | 3 | #include "XMPPChatPrivatePCH.h" 4 | #include "Chat.h" 5 | 6 | #include "ModuleManager.h" 7 | #include "Xmpp.h" 8 | #include "XmppConnection.h" 9 | 10 | DEFINE_LOG_CATEGORY(LogChat); 11 | 12 | UChatMember::UChatMember(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer), 13 | Status(EUXmppPresenceStatus::Offline), 14 | bIsAvailable(false), 15 | Affiliation(EUChatMemberRole::Member) 16 | { 17 | } 18 | 19 | void UChatMember::ConvertFrom(const FXmppChatMember& ChatMember) 20 | { 21 | Nickname = ChatMember.Nickname; 22 | MemberJid = ChatMember.MemberJid.GetFullPath(); 23 | Status = UChatUtil::GetEUXmppPresenceStatus(ChatMember.UserPresence.Status); 24 | bIsAvailable = ChatMember.UserPresence.bIsAvailable; 25 | SentTime = ChatMember.UserPresence.SentTime; 26 | //ClientResource = ChatMember.UserPresence.ClientResource; 27 | //NickName = ChatMember.UserPresence.NickName; 28 | StatusStr = ChatMember.UserPresence.StatusStr; 29 | Affiliation = UChatUtil::GetEUChatMemberRole(ChatMember.Affiliation); 30 | } 31 | 32 | /***************** Base **************************/ 33 | 34 | UChat::UChat(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer), bInited(false), bDone(false) 35 | { 36 | } 37 | 38 | UChat::~UChat() 39 | { 40 | DeInit(); 41 | } 42 | 43 | void UChat::Init() 44 | { 45 | if (XmppConnection.IsValid() && !bInited) 46 | { 47 | bInited = true; 48 | 49 | IXmppConnection::FOnXmppLoginComplete& OnXMPPLoginCompleteDelegate = XmppConnection->OnLoginComplete(); 50 | OnLoginCompleteHandle = OnXMPPLoginCompleteDelegate.AddUObject(this, &UChat::OnLoginCompleteFunc); 51 | 52 | IXmppConnection::FOnXmppLogoutComplete& OnXMPPLogoutCompleteDelegate = XmppConnection->OnLogoutComplete(); 53 | OnLogoutCompleteHandle = OnXMPPLogoutCompleteDelegate.AddUObject(this, &UChat::OnLogoutCompleteFunc); 54 | 55 | IXmppConnection::FOnXmppLogingChanged& OnXMPPLogingChangedDelegate = XmppConnection->OnLoginChanged(); 56 | OnLogingChangedHandle = OnXMPPLogingChangedDelegate.AddUObject(this, &UChat::OnLogingChangedFunc); 57 | 58 | if (XmppConnection->Messages().IsValid()) 59 | { 60 | IXmppMessages::FOnXmppMessageReceived& OnXMPPReceiveMessageDelegate = XmppConnection->Messages()->OnReceiveMessage(); 61 | OnChatReceiveMessageHandle = OnXMPPReceiveMessageDelegate.AddUObject(this, &UChat::OnChatReceiveMessageFunc); 62 | } 63 | 64 | if (XmppConnection->PrivateChat().IsValid()) 65 | { 66 | IXmppChat::FOnXmppChatReceived& OnXMPPChatReceivedDelegate = XmppConnection->PrivateChat()->OnReceiveChat(); 67 | OnPrivateChatReceiveMessageHandle = OnXMPPChatReceivedDelegate.AddUObject(this, &UChat::OnPrivateChatReceiveMessageFunc); 68 | } 69 | 70 | if (XmppConnection->MultiUserChat().IsValid()) 71 | { 72 | IXmppMultiUserChat::FOnXmppRoomChatReceived& OnXMPPMUCReceiveMessageDelegate = XmppConnection->MultiUserChat()->OnRoomChatReceived(); 73 | OnMUCReceiveMessageHandle = OnXMPPMUCReceiveMessageDelegate.AddUObject(this, &UChat::OnMUCReceiveMessageFunc); 74 | 75 | IXmppMultiUserChat::FOnXmppRoomJoinPublicComplete& OnXMPPMUCRoomJoinPublicDelegate = XmppConnection->MultiUserChat()->OnJoinPublicRoom(); 76 | OnMUCRoomJoinPublicCompleteHandle = OnXMPPMUCRoomJoinPublicDelegate.AddUObject(this, &UChat::OnMUCRoomJoinPublicCompleteFunc); 77 | 78 | IXmppMultiUserChat::FOnXmppRoomJoinPrivateComplete& OnXMPPMUCRoomJoinPrivateDelegate = XmppConnection->MultiUserChat()->OnJoinPrivateRoom(); 79 | OnMUCRoomJoinPrivateCompleteHandle = OnXMPPMUCRoomJoinPrivateDelegate.AddUObject(this, &UChat::OnMUCRoomJoinPrivateCompleteFunc); 80 | 81 | IXmppMultiUserChat::FOnXmppRoomMemberJoin& OnXMPPRoomMemberJoinDelegate = XmppConnection->MultiUserChat()->OnRoomMemberJoin(); 82 | OnMUCRoomMemberJoinHandle = OnXMPPRoomMemberJoinDelegate.AddUObject(this, &UChat::OnMUCRoomMemberJoinFunc); 83 | 84 | IXmppMultiUserChat::FOnXmppRoomMemberExit& OnXMPPRoomMemberExitDelegate = XmppConnection->MultiUserChat()->OnRoomMemberExit(); 85 | OnMUCRoomMemberExitHandle = OnXMPPRoomMemberExitDelegate.AddUObject(this, &UChat::OnMUCRoomMemberExitFunc); 86 | 87 | IXmppMultiUserChat::FOnXmppRoomMemberChanged& OnXMPPRoomMemberChangedDelegate = XmppConnection->MultiUserChat()->OnRoomMemberChanged(); 88 | OnMUCRoomMemberChangedHandle = OnXMPPRoomMemberChangedDelegate.AddUObject(this, &UChat::OnMUCRoomMemberChangedFunc); 89 | } 90 | } 91 | } 92 | 93 | void UChat::DeInit() 94 | { 95 | if (XmppConnection.IsValid()) 96 | { 97 | bInited = false; 98 | 99 | if (OnLoginCompleteHandle.IsValid()) { XmppConnection->OnLoginComplete().Remove(OnLoginCompleteHandle); } 100 | if (OnLogoutCompleteHandle.IsValid()) { XmppConnection->OnLogoutComplete().Remove(OnLogoutCompleteHandle); } 101 | if (OnLogingChangedHandle.IsValid()) { XmppConnection->OnLoginChanged().Remove(OnLogingChangedHandle); } 102 | if (OnChatReceiveMessageHandle.IsValid()) { XmppConnection->Messages()->OnReceiveMessage().Remove(OnChatReceiveMessageHandle); } 103 | if (OnPrivateChatReceiveMessageHandle.IsValid()) { XmppConnection->PrivateChat()->OnReceiveChat().Remove(OnPrivateChatReceiveMessageHandle); } 104 | if (OnMUCReceiveMessageHandle.IsValid()) { XmppConnection->MultiUserChat()->OnRoomChatReceived().Remove(OnMUCReceiveMessageHandle); } 105 | if (OnMUCRoomJoinPublicCompleteHandle.IsValid()) { XmppConnection->MultiUserChat()->OnJoinPublicRoom().Remove(OnMUCRoomJoinPublicCompleteHandle); } 106 | if (OnMUCRoomJoinPrivateCompleteHandle.IsValid()) { XmppConnection->MultiUserChat()->OnJoinPrivateRoom().Remove(OnMUCRoomJoinPrivateCompleteHandle); } 107 | if (OnMUCRoomMemberJoinHandle.IsValid()) { XmppConnection->MultiUserChat()->OnRoomMemberJoin().Remove(OnMUCRoomMemberJoinHandle); } 108 | if (OnMUCRoomMemberExitHandle.IsValid()) { XmppConnection->MultiUserChat()->OnRoomMemberExit().Remove(OnMUCRoomMemberExitHandle); } 109 | if (OnMUCRoomMemberChangedHandle.IsValid()) { XmppConnection->MultiUserChat()->OnRoomMemberChanged().Remove(OnMUCRoomMemberChangedHandle); } 110 | 111 | FXmppModule::Get().RemoveConnection(XmppConnection.ToSharedRef()); 112 | } 113 | } 114 | 115 | void UChat::Finish() 116 | { 117 | if (XmppConnection.IsValid()) 118 | { 119 | if (XmppConnection->GetLoginStatus() == EXmppLoginStatus::LoggedIn) 120 | { 121 | Logout(); 122 | } 123 | else 124 | { 125 | bDone = true; 126 | } 127 | } 128 | } 129 | 130 | /***************** Login/Logout **************************/ 131 | 132 | void UChat::Login(const FString& UserId, const FString& Auth, const FString& ServerAddr, const FString& Domain, const FString& ClientResource) 133 | { 134 | FXmppServer XmppServer; 135 | XmppServer.ServerAddr = ServerAddr; 136 | XmppServer.Domain = Domain; 137 | XmppServer.ClientResource = ClientResource; 138 | 139 | Login(UserId, Auth, XmppServer); 140 | } 141 | 142 | void UChat::Login(const FString& UserId, const FString& Auth, const FXmppServer& XmppServer) 143 | { 144 | FXmppModule& Module = FModuleManager::GetModuleChecked("XMPP"); 145 | 146 | UE_LOG(LogChat, Log, TEXT("UChat::Login enabled=%s UserId=%s"), (Module.IsXmppEnabled() ? TEXT("true") : TEXT("false")), *UserId ); 147 | 148 | XmppConnection = Module.CreateConnection(UserId); 149 | 150 | if (XmppConnection.IsValid()) 151 | { 152 | //UE_LOG(LogChat, Log, TEXT("UChat::Login XmppConnection is %s"), typeid(*XmppConnection).name() ); 153 | UE_LOG(LogChat, Log, TEXT("UChat::Login XmppConnection valid") ); 154 | 155 | Init(); 156 | 157 | XmppConnection->SetServer(XmppServer); 158 | 159 | XmppConnection->Login(UserId, Auth); 160 | } 161 | else 162 | { 163 | UE_LOG(LogChat, Error, TEXT("UChat::Login XmppConnection not valid, failed. UserId=%s"), *UserId ); 164 | } 165 | } 166 | 167 | void UChat::OnLoginCompleteFunc(const FXmppUserJid& UserJid, bool bWasSuccess, const FString& Error) 168 | { 169 | UE_LOG(LogChat, Log, TEXT("UChat::OnLoginComplete UserJid=%s Success=%s Error=%s"), *UserJid.GetFullPath(), bWasSuccess ? TEXT("true") : TEXT("false"), *Error); 170 | 171 | OnChatLoginComplete.Broadcast(UserJid.GetFullPath(), bWasSuccess, Error); 172 | } 173 | 174 | void UChat::OnLogoutCompleteFunc(const FXmppUserJid& UserJid, bool bWasSuccess, const FString& Error) 175 | { 176 | UE_LOG(LogChat, Log, TEXT("UChat::OnLogoutComplete UserJid=%s Success=%s Error=%s"), *UserJid.GetFullPath(), bWasSuccess ? TEXT("true") : TEXT("false"), *Error); 177 | 178 | OnChatLogoutComplete.Broadcast(UserJid.GetFullPath(), bWasSuccess, Error); 179 | } 180 | 181 | void UChat::OnLogingChangedFunc(const FXmppUserJid& UserJid, EXmppLoginStatus::Type LoginStatus) 182 | { 183 | UE_LOG(LogChat, Log, TEXT("UChat::OnLogingChanged UserJid=%s LoginStatus=%d"), *UserJid.GetFullPath(), static_cast(LoginStatus)); 184 | 185 | OnChatLogingChanged.Broadcast(UserJid.GetFullPath(), UChatUtil::GetEUXmppLoginStatus(LoginStatus)); 186 | } 187 | 188 | void UChat::Logout() 189 | { 190 | if (XmppConnection.IsValid() && (XmppConnection->GetLoginStatus() == EXmppLoginStatus::LoggedIn)) 191 | { 192 | XmppConnection->Logout(); 193 | } 194 | } 195 | 196 | /***************** Chat **************************/ 197 | 198 | void UChat::OnChatReceiveMessageFunc(const TSharedRef& Connection, const FXmppUserJid& FromJid, const TSharedRef& Message) 199 | { 200 | UE_LOG(LogChat, Log, TEXT("UChat::OnChatReceiveMessage UserJid=%s Type=%s Message=%s"), *FromJid.GetFullPath(), *Message->Type, *Message->Payload); 201 | 202 | OnChatReceiveMessage.Broadcast(FromJid.GetFullPath(), Message->Type, Message->Payload); 203 | } 204 | 205 | void UChat::OnPrivateChatReceiveMessageFunc(const TSharedRef& Connection, const FXmppUserJid& FromJid, const TSharedRef& Message) 206 | { 207 | UE_LOG(LogChat, Log, TEXT("UChat::OnPrivateChatReceiveMessage UserJid=%s Message=%s"), *FromJid.GetFullPath(), *Message->Body); 208 | 209 | OnPrivateChatReceiveMessage.Broadcast(FromJid.GetFullPath(), Message->Body); 210 | } 211 | 212 | void UChat::Message(const FString& UserName, const FString& Recipient, const FString& Type, const FString& MessagePayload) 213 | { 214 | if (XmppConnection->Messages().IsValid()) 215 | { 216 | FXmppMessage Message; 217 | Message.FromJid.Id = UserName; 218 | Message.ToJid.Id = Recipient; 219 | Message.Type = Type; 220 | Message.Payload = MessagePayload; 221 | XmppConnection->Messages()->SendMessage(Recipient, Message); 222 | } 223 | } 224 | 225 | void UChat::PrivateChat(const FString& UserName, const FString& Recipient, const FString& Body) 226 | { 227 | if (XmppConnection->PrivateChat().IsValid()) 228 | { 229 | FXmppChatMessage ChatMessage; 230 | ChatMessage.FromJid.Id = UserName; 231 | ChatMessage.ToJid.Id = Recipient; 232 | ChatMessage.Body = Body; 233 | XmppConnection->PrivateChat()->SendChat(Recipient, ChatMessage); 234 | } 235 | } 236 | 237 | 238 | /***************** Presence **************************/ 239 | 240 | void UChat::Presence(bool bIsAvailable, EUXmppPresenceStatus::Type Status, const FString& StatusStr) 241 | { 242 | if (XmppConnection->Presence().IsValid()) 243 | { 244 | FXmppUserPresence XmppPresence = XmppConnection->Presence()->GetPresence(); 245 | XmppPresence.bIsAvailable = bIsAvailable; 246 | XmppPresence.Status = UChatUtil::GetEXmppPresenceStatus(Status); 247 | XmppConnection->Presence()->UpdatePresence(XmppPresence); 248 | } 249 | } 250 | 251 | void UChat::PresenceQuery(const FString& User) 252 | { 253 | if (XmppConnection->Presence().IsValid()) 254 | { 255 | XmppConnection->Presence()->QueryPresence(User); 256 | } 257 | } 258 | 259 | void UChat::PresenceGetRosterMembers(TArray& Members) 260 | { 261 | if (XmppConnection->Presence().IsValid()) 262 | { 263 | TArray MemberJids; 264 | XmppConnection->Presence()->GetRosterMembers(MemberJids); 265 | 266 | for (auto& Jid : MemberJids) 267 | { 268 | Members.Push(Jid.Id); 269 | } 270 | } 271 | } 272 | 273 | // TODO: 274 | // FXmppUserPresenceJingle and FXmppUserPresence 275 | // TArray> FXmppPresenceJingle::GetRosterPresence(const FString& UserId) 276 | // virtual FOnXmppPresenceReceived& OnReceivePresence() override { return OnXmppPresenceReceivedDelegate; } 277 | // Needed? 278 | // virtual bool UpdatePresence(const FXmppUserPresence& Presence) override; 279 | // virtual const FXmppUserPresence& GetPresence() const override; 280 | 281 | /***************** MUC **************************/ 282 | 283 | void UChat::OnMUCReceiveMessageFunc(const TSharedRef& Connection, const FXmppRoomId& RoomId, const FXmppUserJid& UserJid, const TSharedRef& ChatMsg) 284 | { 285 | if (Connection->MultiUserChat().IsValid()) 286 | { 287 | OnMUCReceiveMessage.Broadcast(static_cast(RoomId), UserJid.Resource, *ChatMsg->Body); 288 | } 289 | } 290 | 291 | void UChat::OnMUCRoomJoinPublicCompleteFunc(const TSharedRef& Connection, bool bSuccess, const FXmppRoomId& RoomId, const FString& Error) 292 | { 293 | OnMUCRoomJoinPublicComplete.Broadcast(bSuccess, static_cast(RoomId), Error); 294 | } 295 | 296 | void UChat::OnMUCRoomJoinPrivateCompleteFunc(const TSharedRef& Connection, bool bSuccess, const FXmppRoomId& RoomId, const FString& Error) 297 | { 298 | OnMUCRoomJoinPrivateComplete.Broadcast(bSuccess, static_cast(RoomId), Error); 299 | } 300 | 301 | void UChat::OnMUCRoomMemberJoinFunc(const TSharedRef& Connection, const FXmppRoomId& RoomId, const FXmppUserJid& UserJid) 302 | { 303 | UE_LOG(LogChat, Log, TEXT("UChat::OnMUCRoomMemberJoin RoomId=%s UserJid=%s"), *static_cast(RoomId), *UserJid.GetFullPath()); 304 | OnMUCRoomMemberJoin.Broadcast(static_cast(RoomId), UserJid.Resource); 305 | } 306 | 307 | void UChat::OnMUCRoomMemberExitFunc(const TSharedRef& Connection, const FXmppRoomId& RoomId, const FXmppUserJid& UserJid) 308 | { 309 | UE_LOG(LogChat, Log, TEXT("UChat::OnMUCRoomMemberExit RoomId=%s UserJid=%s"), *static_cast(RoomId), *UserJid.GetFullPath()); 310 | OnMUCRoomMemberExit.Broadcast(static_cast(RoomId), UserJid.Resource); 311 | } 312 | 313 | void UChat::OnMUCRoomMemberChangedFunc(const TSharedRef& Connection, const FXmppRoomId& RoomId, const FXmppUserJid& UserJid) 314 | { 315 | UE_LOG(LogChat, Log, TEXT("UChat::OnMUCRoomMemberChanged RoomId=%s UserJid=%s"), *static_cast(RoomId), *UserJid.GetFullPath()); 316 | OnMUCRoomMemberChanged.Broadcast(static_cast(RoomId), UserJid.Resource); 317 | } 318 | 319 | void UChat::MucCreate(const FString& UserName, const FString& RoomId, bool bIsPrivate, const FString& Password) 320 | { 321 | if (XmppConnection.IsValid() && XmppConnection->MultiUserChat().IsValid()) 322 | { 323 | FXmppRoomConfig RoomConfig; 324 | RoomConfig.RoomName = RoomId; 325 | RoomConfig.bIsPersistent = false; 326 | RoomConfig.bIsPrivate = bIsPrivate; 327 | RoomConfig.Password = Password; 328 | XmppConnection->MultiUserChat()->CreateRoom(RoomId, UserName, RoomConfig); 329 | } 330 | } 331 | 332 | void UChat::MucJoin(const FString& RoomId, const FString& Nickname, const FString& Password) 333 | { 334 | if (XmppConnection.IsValid() && XmppConnection->MultiUserChat().IsValid()) 335 | { 336 | if (Password.IsEmpty()) 337 | { 338 | XmppConnection->MultiUserChat()->JoinPublicRoom(RoomId, Nickname); 339 | } 340 | else 341 | { 342 | XmppConnection->MultiUserChat()->JoinPrivateRoom(RoomId, Nickname, Password); 343 | } 344 | } 345 | } 346 | 347 | void UChat::MucExit(const FString& RoomId) 348 | { 349 | if (XmppConnection.IsValid() && XmppConnection->MultiUserChat().IsValid()) 350 | { 351 | XmppConnection->MultiUserChat()->ExitRoom(RoomId); 352 | } 353 | } 354 | 355 | void UChat::MucChat(const FString& RoomId, const FString& Body) 356 | { 357 | if (XmppConnection.IsValid() && XmppConnection->MultiUserChat().IsValid()) 358 | { 359 | XmppConnection->MultiUserChat()->SendChat(RoomId, Body); 360 | } 361 | } 362 | 363 | void UChat::MucConfig(const FString& UserName, const FString& RoomId, bool bIsPrivate, const FString& Password) 364 | { 365 | if (XmppConnection.IsValid() && XmppConnection->MultiUserChat().IsValid()) 366 | { 367 | FXmppRoomConfig RoomConfig; 368 | RoomConfig.bIsPrivate = bIsPrivate; 369 | RoomConfig.Password = Password; 370 | XmppConnection->MultiUserChat()->ConfigureRoom(RoomId, RoomConfig); 371 | } 372 | } 373 | 374 | void UChat::MucRefresh(const FString& RoomId) 375 | { 376 | if (XmppConnection.IsValid() && XmppConnection->MultiUserChat().IsValid()) 377 | { 378 | XmppConnection->MultiUserChat()->RefreshRoomInfo(RoomId); 379 | } 380 | } 381 | 382 | void UChat::MucGetMembers(const FString& RoomId, TArray& Members) 383 | { 384 | if (XmppConnection.IsValid() && XmppConnection->MultiUserChat().IsValid()) 385 | { 386 | TArray< FXmppChatMemberRef > OutMembers; 387 | XmppConnection->MultiUserChat()->GetMembers(RoomId, OutMembers); 388 | 389 | Members.Empty(); 390 | Members.Reserve(OutMembers.Num()); 391 | for (auto& Member : OutMembers) 392 | { 393 | UChatMember* UMember = NewObject(); 394 | UMember->ConvertFrom(Member.Get()); 395 | Members.Add(UMember); 396 | } 397 | } 398 | } 399 | 400 | /***************** PubSub **************************/ 401 | 402 | void UChat::PubSubCreate(const FString& NodeId) 403 | { 404 | if (XmppConnection.IsValid() && XmppConnection->PubSub().IsValid()) 405 | { 406 | FXmppPubSubConfig PubSubConfig; 407 | XmppConnection->PubSub()->CreateNode(NodeId, PubSubConfig); 408 | } 409 | } 410 | 411 | void UChat::PubSubDestroy(const FString& NodeId) 412 | { 413 | if (XmppConnection.IsValid() && XmppConnection->PubSub().IsValid()) 414 | { 415 | XmppConnection->PubSub()->DestroyNode(NodeId); 416 | } 417 | } 418 | 419 | void UChat::PubSubSubscribe(const FString& NodeId) 420 | { 421 | if (XmppConnection.IsValid() && XmppConnection->PubSub().IsValid()) 422 | { 423 | XmppConnection->PubSub()->Subscribe(NodeId); 424 | } 425 | } 426 | 427 | void UChat::PubSubUnsubscribe(const FString& NodeId) 428 | { 429 | if (XmppConnection.IsValid() && XmppConnection->PubSub().IsValid()) 430 | { 431 | XmppConnection->PubSub()->Unsubscribe(NodeId); 432 | } 433 | } 434 | 435 | void UChat::PubSubPublish(const FString& NodeId, const FString& Payload) 436 | { 437 | if (XmppConnection.IsValid() && XmppConnection->PubSub().IsValid()) 438 | { 439 | FXmppPubSubMessage Message; 440 | Message.Payload = Payload; 441 | XmppConnection->PubSub()->PublishMessage(NodeId, Message); 442 | } 443 | } 444 | 445 | 446 | 447 | --------------------------------------------------------------------------------