Skip to content

Commit 241fcae

Browse files
Rework subscription loop to use event engine. Add Include and Sort structures. (#46)
modify(subscription): Rework subscription loop to use event engine remove(c-core): Remove not needed c-core files from Include folder change(params): create dedicated structures for `Sort` and `Include` params Rework `GetMemberships`, `GetChannelMembers`, `GetAllUsersMetadataand` and `GetAllChannelsMetadata` to have dedicated structures for Include and Sort fields. Note: this is BREAKING CHANGE. change(deprecate): Mark _JSON functions as deprecated fix(fetchHistory): Fix bugs in parsing `FetchHistory` response. fix(responses): Fix bug that not all requested data was included in functions response when TotalCount was set.
1 parent b50de76 commit 241fcae

File tree

421 files changed

+1232
-106630
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

421 files changed

+1232
-106630
lines changed

.pubnub.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
name: unreal-engine
2-
version: 0.2.6
2+
version: 0.3.0
33
schema: 1
44
scm: github.com/pubnub/unreal-engine
55
changelog:
6-
- date: 2024-02-12
6+
- date: 2025-04-29
7+
version: 0.3.0
8+
changes:
9+
- type: feature
10+
text: "Rework GetMemberships, GetChannelMembers, GetAllUsersMetadataand GetAllChannelsMetadata to have dedicated structures for Include and Sort fields. Note: this is BREAKING CHANGE."
11+
- type: improvement
12+
text: "Change subscription loop to use Event Engine."
13+
- type: improvement
14+
text: "Mark _JSON functions as deprecated"
15+
- type: improvement
16+
text: "Remove not needed C-Core files. Leave only required headers."
17+
- type: bug
18+
text: "Fix bugs in parsing FetchHistory response."
19+
- type: bug
20+
text: "Fix bug that not all requested data was included in functions response when TotalCount was set."
21+
- date: 2025-02-12
722
version: 0.2.6
823
changes:
924
- type: bug
@@ -12,12 +27,12 @@ changelog:
1227
text: "Fix SetSecretKeyAutomatically setting to set the key properly."
1328
- type: bug
1429
text: "Fix 'PubnubLog: Error: Pubnub user ID is not set. Aborting operation.' false error."
15-
- date: 2024-02-06
30+
- date: 2025-02-06
1631
version: 0.2.5
1732
changes:
1833
- type: feature
1934
text: "Add plugin support for Linux and IOS projects."
20-
- date: 2024-01-21
35+
- date: 2025-01-21
2136
version: 0.2.4
2237
changes:
2338
- type: feature

PubnubLibrary.uplugin

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"FileVersion": 3,
3-
"Version": 6,
4-
"VersionName": "0.2.6",
3+
"Version": 7,
4+
"VersionName": "0.3.0",
55
"FriendlyName": "Pubnub Unreal SDK",
66
"Description": "Quickly add interactive features to your game that scale without building your backend infrastructure.",
77
"Category": "Code",

Source/PubnubLibrary/Private/FunctionLibraries/PubnubJsonUtilities.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ FString UPubnubJsonUtilities::JsonObjectToString(TSharedPtr<FJsonObject> JsonObj
1212
}
1313

1414
FString JsonString;
15-
TSharedRef< TJsonWriter<> > JsonWriter = TJsonWriterFactory<>::Create(&JsonString);
15+
TSharedRef< TJsonWriter<TCHAR, TCondensedJsonPrintPolicy<TCHAR>> > JsonWriter = TJsonWriterFactory<TCHAR, TCondensedJsonPrintPolicy<TCHAR>>::Create(&JsonString);
16+
1617
FJsonSerializer::Serialize(JsonObject.ToSharedRef(), JsonWriter);
1718
return JsonString;
1819
}
@@ -195,14 +196,20 @@ void UPubnubJsonUtilities::FetchHistoryJsonToData(FString ResponseJson, bool& Er
195196
for(auto MessageValue : ChannelJsonValue->AsArray())
196197
{
197198
FPubnubHistoryMessageData CurrentMessage;
198-
MessageValue->AsObject()->TryGetStringField(ANSI_TO_TCHAR("message"), CurrentMessage.Message);
199+
if(!MessageValue->AsObject()->TryGetStringField(ANSI_TO_TCHAR("message"), CurrentMessage.Message))
200+
{
201+
const TSharedPtr<FJsonObject>* MetaJsonObject;
202+
if(MessageValue->AsObject()->TryGetObjectField(ANSI_TO_TCHAR("message"), MetaJsonObject))
203+
{
204+
CurrentMessage.Message = JsonObjectToString(*MetaJsonObject);
205+
}
206+
}
199207
MessageValue->AsObject()->TryGetStringField(ANSI_TO_TCHAR("uuid"), CurrentMessage.UserID);
200208
MessageValue->AsObject()->TryGetStringField(ANSI_TO_TCHAR("timetoken"), CurrentMessage.Timetoken);
201209
MessageValue->AsObject()->TryGetStringField(ANSI_TO_TCHAR("message_type"), CurrentMessage.MessageType);
202-
MessageValue->AsObject()->TryGetStringField(ANSI_TO_TCHAR("custom_message_type"), CurrentMessage.MessageType);
210+
MessageValue->AsObject()->TryGetStringField(ANSI_TO_TCHAR("custom_message_type"), CurrentMessage.CustomMessageType);
203211
if(!MessageValue->AsObject()->TryGetStringField(ANSI_TO_TCHAR("meta"), CurrentMessage.Meta))
204212
{
205-
UE_LOG(LogTemp, Warning, TEXT("Reading Meta as Json Object"));
206213
const TSharedPtr<FJsonObject>* MetaJsonObject;
207214
if(MessageValue->AsObject()->TryGetObjectField(ANSI_TO_TCHAR("meta"), MetaJsonObject))
208215
{

Source/PubnubLibrary/Private/FunctionLibraries/PubnubUtilities.cpp

Lines changed: 268 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "Runtime/Launch/Resources/Version.h"
66
#include "Json.h"
77

8-
98
FString UPubnubUtilities::AddQuotesToString(const FString InString, bool SkipIfHasQuotes)
109
{
1110
if(InString.Left(1) != "\"" || InString.Right(1) != "\"" || !SkipIfHasQuotes)
@@ -29,4 +28,272 @@ FString UPubnubUtilities::PubnubCharMemBlockToString(const pubnub_char_mem_block
2928
#else
3029
return FString::ConstructFromPtrSize(PnChar.ptr, PnChar.size);
3130
#endif
31+
}
32+
33+
FString UPubnubUtilities::MembershipIncludeToString(const FPubnubMembershipInclude& MembershipInclude)
34+
{
35+
FString FinalString = "";
36+
if(MembershipInclude.IncludeCustom) {FinalString.Append("custom,");}
37+
if(MembershipInclude.IncludeStatus) {FinalString.Append("status,");}
38+
if(MembershipInclude.IncludeType) {FinalString.Append("type,");}
39+
if(MembershipInclude.IncludeChannel) {FinalString.Append("channel,");}
40+
if(MembershipInclude.IncludeChannelCustom) {FinalString.Append("channel.custom,");}
41+
if(MembershipInclude.IncludeChannelStatus) {FinalString.Append("channel.status,");}
42+
if(MembershipInclude.IncludeChannelType) {FinalString.Append("channel.type,");}
43+
//Total count is passed as a separate parameter, so it's not included directly in the final string
44+
45+
//If there was any include remove the last comma
46+
if(!FinalString.IsEmpty())
47+
{
48+
FinalString.RemoveAt(FinalString.Len() - 1);
49+
}
50+
51+
return FinalString;
52+
}
53+
54+
FString UPubnubUtilities::MemberIncludeToString(const FPubnubMemberInclude& MemberInclude)
55+
{
56+
FString FinalString = "";
57+
if(MemberInclude.IncludeCustom) {FinalString.Append("custom,");}
58+
if(MemberInclude.IncludeStatus) {FinalString.Append("status,");}
59+
if(MemberInclude.IncludeType) {FinalString.Append("type,");}
60+
if(MemberInclude.IncludeUser) {FinalString.Append("user,");}
61+
if(MemberInclude.IncludeUserCustom) {FinalString.Append("user.custom,");}
62+
if(MemberInclude.IncludeUserStatus) {FinalString.Append("user.status,");}
63+
if(MemberInclude.IncludeUserType) {FinalString.Append("user.type,");}
64+
//Total count is passed as a separate parameter, so it's not included directly in the final string
65+
66+
//If there was any include remove the last comma
67+
if(!FinalString.IsEmpty())
68+
{
69+
FinalString.RemoveAt(FinalString.Len() - 1);
70+
}
71+
72+
return FinalString;
73+
}
74+
75+
FString UPubnubUtilities::GetAllIncludeToString(const FPubnubGetAllInclude& GetAllInclude)
76+
{
77+
FString FinalString = "";
78+
if(GetAllInclude.IncludeCustom) {FinalString.Append("custom,");}
79+
if(GetAllInclude.IncludeStatus) {FinalString.Append("status,");}
80+
if(GetAllInclude.IncludeType) {FinalString.Append("type,");}
81+
//Total count is passed as a separate parameter, so it's not included directly in the final string
82+
83+
//If there was any include remove the last comma
84+
if(!FinalString.IsEmpty())
85+
{
86+
FinalString.RemoveAt(FinalString.Len() - 1);
87+
}
88+
89+
return FinalString;
90+
}
91+
92+
FString UPubnubUtilities::MembershipSortTypeToString(const EPubnubMembershipSortType SortType)
93+
{
94+
switch (SortType)
95+
{
96+
case EPubnubMembershipSortType::PMST_ChannelID:
97+
return "channel.id";
98+
case EPubnubMembershipSortType::PMST_ChannelName:
99+
return "channel.name";
100+
case EPubnubMembershipSortType::PMST_ChannelUpdated:
101+
return "channel.updated";
102+
case EPubnubMembershipSortType::PMST_ChannelStatus:
103+
return "channel.status";
104+
case EPubnubMembershipSortType::PMST_ChannelType:
105+
return "channel.type";
106+
case EPubnubMembershipSortType::PMST_Updated:
107+
return "updated";
108+
case EPubnubMembershipSortType::PMST_Status:
109+
return "status";
110+
case EPubnubMembershipSortType::PMST_Type:
111+
return "type";
112+
}
113+
return "";
114+
}
115+
116+
FString UPubnubUtilities::MemberSortTypeToString(const EPubnubMemberSortType SortType)
117+
{
118+
switch (SortType)
119+
{
120+
case EPubnubMemberSortType::PMeST_UserID:
121+
return "user.id";
122+
case EPubnubMemberSortType::PMeST_UserName:
123+
return "user.name";
124+
case EPubnubMemberSortType::PMeST_UserUpdated:
125+
return "user.updated";
126+
case EPubnubMemberSortType::PMeST_UserStatus:
127+
return "user.status";
128+
case EPubnubMemberSortType::PMeST_UserType:
129+
return "user.type";
130+
case EPubnubMemberSortType::PMeST_Updated:
131+
return "updated";
132+
case EPubnubMemberSortType::PMeST_Status:
133+
return "status";
134+
case EPubnubMemberSortType::PMeST_Type:
135+
return "type";
136+
}
137+
return "";
138+
}
139+
140+
FString UPubnubUtilities::GetAllSortTypeToString(const EPubnubGetAllSortType SortType)
141+
{
142+
switch (SortType)
143+
{
144+
case EPubnubGetAllSortType::PGAST_ID:
145+
return "id";
146+
case EPubnubGetAllSortType::PGAST_Name:
147+
return "name";
148+
case EPubnubGetAllSortType::PGAST_Updated:
149+
return "updated";
150+
case EPubnubGetAllSortType::PGAST_Status:
151+
return "status";
152+
case EPubnubGetAllSortType::PGAST_Type:
153+
return "type";
154+
}
155+
return "";
156+
}
157+
158+
FString UPubnubUtilities::MembershipSortToString(const FPubnubMembershipSort& MemberInclude)
159+
{
160+
FString FinalString = "";
161+
//Form comma separated string of sorts
162+
for(auto SingleSort : MemberInclude.MembershipSort)
163+
{
164+
if(!FinalString.IsEmpty()) {FinalString.Append(",");}
165+
FinalString.Append(MembershipSortTypeToString(SingleSort.SortType));
166+
//Default sort is ascending, so we only specify order when it's descending
167+
if(SingleSort.SortOrder)
168+
{
169+
FinalString.Append(":desc");
170+
}
171+
}
172+
173+
return FinalString;
174+
}
175+
176+
FString UPubnubUtilities::MemberSortToString(const FPubnubMemberSort& MemberInclude)
177+
{
178+
FString FinalString = "";
179+
//Form comma separated string of sorts
180+
for(auto SingleSort : MemberInclude.MemberSort)
181+
{
182+
if(!FinalString.IsEmpty()) {FinalString.Append(",");}
183+
FinalString.Append(MemberSortTypeToString(SingleSort.SortType));
184+
//Default sort is ascending, so we only specify order when it's descending
185+
if(SingleSort.SortOrder)
186+
{
187+
FinalString.Append(":desc");
188+
}
189+
}
190+
191+
return FinalString;
192+
}
193+
194+
FString UPubnubUtilities::GetAllSortToString(const FPubnubGetAllSort& GetAllInclude)
195+
{
196+
FString FinalString = "";
197+
//Form comma separated string of sorts
198+
for(auto SingleSort : GetAllInclude.GetAllSort)
199+
{
200+
if(!FinalString.IsEmpty()) {FinalString.Append(",");}
201+
FinalString.Append(GetAllSortTypeToString(SingleSort.SortType));
202+
//Default sort is ascending, so we only specify order when it's descending
203+
if(SingleSort.SortOrder)
204+
{
205+
FinalString.Append(":desc");
206+
}
207+
}
208+
209+
return FinalString;
210+
}
211+
212+
213+
pubnub_subscription_t* UPubnubUtilities::EEGetSubscriptionForChannel(pubnub_t* Context, FString Channel, FPubnubSubscribeSettings Options)
214+
{
215+
pubnub_subscription_options_t PnOptions = pubnub_subscription_options_defopts();
216+
PnOptions.receive_presence_events = Options.ReceivePresenceEvents;
217+
218+
pubnub_channel_t* PubnubChannel = pubnub_channel_alloc(Context, TCHAR_TO_ANSI(*Channel));
219+
220+
pubnub_subscription_t* Subscription = pubnub_subscription_alloc((pubnub_entity_t*)PubnubChannel, &PnOptions);
221+
222+
pubnub_entity_free((void**)&PubnubChannel);
223+
224+
return Subscription;
225+
}
226+
227+
pubnub_subscription_t* UPubnubUtilities::EEGetSubscriptionForChannelGroup(pubnub_t* Context, FString ChannelGroup, FPubnubSubscribeSettings Options)
228+
{
229+
pubnub_subscription_options_t PnOptions = pubnub_subscription_options_defopts();
230+
PnOptions.receive_presence_events = Options.ReceivePresenceEvents;
231+
232+
pubnub_channel_group_t* PubnubChannelGroup = pubnub_channel_group_alloc(Context, TCHAR_TO_ANSI(*ChannelGroup));
233+
234+
pubnub_subscription_t* Subscription = pubnub_subscription_alloc((pubnub_entity_t*)PubnubChannelGroup, &PnOptions);
235+
236+
pubnub_entity_free((void**)&PubnubChannelGroup);
237+
238+
return Subscription;
239+
}
240+
241+
bool UPubnubUtilities::EEAddListenerAndSubscribe(pubnub_subscription_t* Subscription, pubnub_subscribe_message_callback_t Callback, UPubnubSubsystem* PubnubSubsystem)
242+
{
243+
if(!PubnubSubsystem)
244+
{
245+
UE_LOG(PubnubLog, Error, TEXT("EEAddListenerAndSubscribe Failed, PubnubSubsystem is invalid"));
246+
return false;
247+
}
248+
249+
enum pubnub_res AddListenerResult = pubnub_subscribe_add_subscription_listener(Subscription, PBSL_LISTENER_ON_MESSAGE, Callback, PubnubSubsystem);
250+
if(PNR_OK != AddListenerResult)
251+
{
252+
FString ResultString(pubnub_res_2_string(AddListenerResult));
253+
PubnubSubsystem->PubnubError("Failed to subscribe. Add_subscription_listener failed with error: " + ResultString);
254+
return false;
255+
}
256+
257+
enum pubnub_res SubscribeResult = pubnub_subscribe_with_subscription(Subscription, nullptr);
258+
if(PNR_OK != SubscribeResult)
259+
{
260+
FString ResultString(pubnub_res_2_string(AddListenerResult));
261+
PubnubSubsystem->PubnubError("Failed to subscribe. Subscribe_with_subscription failed with error: " + ResultString);
262+
return false;
263+
}
264+
265+
return true;
266+
}
267+
268+
bool UPubnubUtilities::EERemoveListenerAndUnsubscribe(pubnub_subscription_t** SubscriptionPtr, pubnub_subscribe_message_callback_t Callback, UPubnubSubsystem* PubnubSubsystem)
269+
{
270+
if(!PubnubSubsystem)
271+
{
272+
UE_LOG(PubnubLog, Error, TEXT("EERemoveListenerAndUnsubscribe Failed, PubnubSubsystem is invalid"));
273+
return false;
274+
}
275+
276+
if(!SubscriptionPtr)
277+
{
278+
PubnubSubsystem->PubnubError("Failed to unsubscribe. Passed subscription pointer is invalid");
279+
return false;
280+
}
281+
282+
enum pubnub_res RemoveListenerResult = pubnub_subscribe_remove_subscription_listener(*SubscriptionPtr, PBSL_LISTENER_ON_MESSAGE, Callback, PubnubSubsystem);
283+
if(PNR_OK != RemoveListenerResult)
284+
{
285+
FString ResultString(pubnub_res_2_string(RemoveListenerResult));
286+
PubnubSubsystem->PubnubError("Failed to subscribe. Remove_subscription_listener failed with error: " + ResultString);
287+
return false;
288+
}
289+
290+
enum pubnub_res UnsubscribeResult = pubnub_unsubscribe_with_subscription(SubscriptionPtr);
291+
if(PNR_OK != UnsubscribeResult)
292+
{
293+
FString ResultString(pubnub_res_2_string(UnsubscribeResult));
294+
PubnubSubsystem->PubnubError("Failed to unsubscribe. Unsubscribe_with_subscription failed with error: " + ResultString);
295+
return false;
296+
}
297+
298+
return true;
32299
}

0 commit comments

Comments
 (0)