Skip to content

Commit 06d6336

Browse files
PubNub SDK v5.0.0 release.
1 parent 3d156be commit 06d6336

File tree

64 files changed

+25491
-1404
lines changed

Some content is hidden

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

64 files changed

+25491
-1404
lines changed

.pubnub.yml

Lines changed: 336 additions & 43 deletions
Large diffs are not rendered by default.

PubNubUnity/Assets/PubNub/Builders/History/FetchMessagesRequestBuilder.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,24 @@ protected bool CreateFetchMessagesResult(object objChannelsDict, out Dictionary<
227227
#endif
228228
continue;
229229
}
230+
#if (ENABLE_PUBNUB_LOGGING)
231+
this.PubNubInstance.PNLog.WriteToLog(string.Format ("kvpair.Value {0}", kvpair.Value), PNLoggingMethod.LevelInfo);
232+
#endif
230233
object[] channelDetails = kvpair.Value as object[];
234+
if(channelDetails == null){
235+
List<object> channelDetailsList = kvpair.Value as List<object>;
236+
if(channelDetailsList != null){
237+
channelDetails = channelDetailsList.Cast<object>().ToArray();
238+
}
239+
}
231240
#if (ENABLE_PUBNUB_LOGGING)
232241
this.PubNubInstance.PNLog.WriteToLog(string.Format ("CreateFetchMessagesResult: channelDetails {0}", channelDetails.Length), PNLoggingMethod.LevelInfo);
233242
#endif
234243

235244
List<PNMessageResult> lstMessageResult = new List<PNMessageResult>();
245+
int count = 0;
236246
foreach(object messageData in channelDetails){
247+
count++;
237248
Dictionary<string, object> messageDataDict = messageData as Dictionary<string, object>;
238249
if(messageDataDict!=null){
239250

PubNubUnity/Assets/PubNub/Builders/Presence/HereNowRequestBuilder.cs

Lines changed: 123 additions & 35 deletions
Large diffs are not rendered by default.

PubNubUnity/Assets/PubNub/Editor/EditorCommon.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#define USE_JSONFX_UNITY_IOS
1+
// #define USE_JSONFX_UNITY_IOS
22
//#define USE_MiniJSON
3+
#define USE_NEWTONSOFT_JSON
34
using System;
45
using System.Collections.Generic;
56
using System.ComponentModel;

PubNubUnity/Assets/PubNub/Editor/EncryptionTests.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public void TestArrayDecryptionUsingMiniJson ()
228228
#else
229229
[Test]
230230
#endif
231-
public void TestObjectEncryption ()
231+
public void TestObjectEncryption ()
232232
{
233233
pn = EditorCommon.InitPN(pnConfig);
234234
PubnubCrypto pubnubCrypto = new PubnubCrypto ("enigma", PNLog);
@@ -271,7 +271,7 @@ public void TestObjectEncryptionMiniJson ()
271271
#else
272272
[Test]
273273
#endif
274-
public void TestObjectDecryption ()
274+
public void TestObjectDecryption ()
275275
{
276276
pn = EditorCommon.InitPN(pnConfig);
277277
PubnubCrypto pubnubCrypto = new PubnubCrypto ("enigma", PNLog);
@@ -777,6 +777,32 @@ public void TestGermanCharsEncryption ()
777777
Assert.True (("stpgsG1DZZxb44J7mFNSzg==").Equals (encrypted));
778778
}
779779

780+
[Test]
781+
public void TestEmojiEncryption ()
782+
{
783+
pn = EditorCommon.InitPN(pnConfig);
784+
PubnubCrypto pubnubCrypto = new PubnubCrypto ("enigma", PNLog);
785+
string message = "Text with emoji 🙀 👸 🐥 😜 🎉";
786+
message = EditorCommon.Serialize (message);
787+
string encrypted = pubnubCrypto.Encrypt (message);
788+
UnityEngine.Debug.Log(encrypted);
789+
790+
Assert.True (("QnmYXhfz/qbYEbkHktlm6RqNZOxJWR32V1u1F4eVILWozb0esjAjZvwnQ8L6ozo8KTCgOu1OUonsLFS8+VABJ6DcqFXYOkEGH4aVJkCknejBYsrgYythpypltwEdMnG8").Equals (encrypted));
791+
}
792+
[Test]
793+
public void TestEmojiDecryption ()
794+
{
795+
pn = EditorCommon.InitPN(pnConfig);
796+
PubnubCrypto pubnubCrypto = new PubnubCrypto ("enigma", PNLog);
797+
string message = "QnmYXhfz/qbYEbkHktlm6RqNZOxJWR32V1u1F4eVILWozb0esjAjZvwnQ8L6ozo8KTCgOu1OUonsLFS8+VABJ6DcqFXYOkEGH4aVJkCknejBYsrgYythpypltwEdMnG8";
798+
//decrypt
799+
string decrypted = pubnubCrypto.Decrypt (message);
800+
//deserialize
801+
message = EditorCommon.Deserialize<string> (decrypted);
802+
UnityEngine.Debug.Log(message);
803+
Assert.True (("Text with emoji 🙀 👸 🐥 😜 🎉").Equals (message));
804+
}
805+
780806
#if (USE_MiniJSON)
781807
[Test]
782808
public void TestGermanCharsEncryptionMiniJson ()

PubNubUnity/Assets/PubNub/Editor/FetchMessagesResponseTests.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using NUnit.Framework;
2+
using UnityEngine;
3+
using System.Linq;
4+
using System;
5+
using System.Text;
6+
7+
namespace PubNubAPI.Tests
8+
{
9+
public class SerializationTests
10+
{
11+
[Test]
12+
public void TestEmojiSerialization (){
13+
string message = "Text with emoji 🙀 👸 🐥 😜 🎉";
14+
SerializationCommon(message);
15+
}
16+
17+
public void SerializationCommon(object message){
18+
string serialized = EditorCommon.Serialize(message);
19+
string expected = string.Format("\"{0}\"", message);
20+
Assert.True (expected.Equals (serialized));
21+
}
22+
23+
[Test]
24+
public void TestEmojiDeserialization (){
25+
string message = "\"Text with emoji 🙀 👸 🐥 😜 🎉\"";
26+
DeserializationCommon(message, message);
27+
}
28+
29+
public void DeserializationCommon(string message, string expected){
30+
string deserialized = EditorCommon.Deserialize<string>(message);
31+
32+
string deserializedWithQuotes = string.Format("\"{0}\"", deserialized);
33+
Assert.True (message.Equals (deserializedWithQuotes));
34+
}
35+
36+
}
37+
}

PubNubUnity/Assets/PubNub/Editor/SerializationTests.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PubNubUnity/Assets/PubNub/Examples/Example.cs

Lines changed: 42 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ public class Example : MonoBehaviour {
1414

1515
string cg1 = "channelGroup1";
1616
string cg2 = "channelGroup2";
17+
// string ch1 = "team_readonly.a8e9eff5-eed9-4d42-8686-1ecb6fe9916f";
1718
string ch1 = "channel1";
18-
string ch2 = "channel2";
19+
string ch2 = "channel11";
1920
UnityEngine.UI.Text TextContent;
2021
UnityEngine.UI.Button ButtonClear;
2122
UnityEngine.UI.Button ButtonReset;
@@ -238,16 +239,13 @@ void ButtonFireHandler(){
238239
});
239240
}
240241
void ButtonPublishHandler(){
241-
//for(int i =0; i<1000; i++){
242-
//pubnub.Publish().Channel("channel1").Message("test message" +i+ " " + DateTime.Now.Ticks.ToString()).Async((result, status) => {
243242
Dictionary<string, string> dict = new Dictionary<string, string>();
244243
dict.Add ("k1", "v1");
245244

246245
Dictionary<string, string> meta = new Dictionary<string, string>();
247246
meta.Add ("k1", "v1");
248247

249-
pubnub.Publish().Channel("channel1").Meta(meta).Message("Text with 😜 emoji 🐥" + DateTime.Now.Ticks.ToString()).QueryParam(dict).Async((result, status) => {
250-
Debug.Log ("in Publish");
248+
pubnub.Publish().Channel("channel1").Meta(meta).Message("Text with emoji 🙀" + DateTime.Now.Ticks.ToString()).QueryParam(dict).Async((result, status) => {
251249
if(!status.Error){
252250
Debug.Log (string.Format("DateTime {0}, In Publish Example, Timetoken: {1}", DateTime.UtcNow , result.Timetoken));
253251
Display(string.Format("Published: {0}", result.Timetoken));
@@ -257,7 +255,6 @@ void ButtonPublishHandler(){
257255
}
258256

259257
});
260-
//}
261258
}
262259
void ButtonPublishPostHandler(){
263260

@@ -427,15 +424,11 @@ void AddComponents(){
427424
ButtonEncrypt = GameObject.Find("ButtonEncrypt").GetComponent<UnityEngine.UI.Button>();
428425
ButtonEncrypt.onClick.AddListener(ButtonEncryptHandler);
429426
InputFieldName = GameObject.Find("InputFieldName").GetComponent<UnityEngine.UI.InputField>();
430-
// InputFieldName.onValueChanged.AddListener(InputFieldNameHandler);
431427
InputFieldID = GameObject.Find("InputFieldID").GetComponent<UnityEngine.UI.InputField>();
432-
// InputFieldID.onValueChanged.AddListener(InputFieldIDHandler);
433-
434428
}
435429

436430
void ButtonSendFileHandler(){
437431
string publishMessage = string.Format("publishMessage_{0}{1}", "id_", "constString");
438-
// string filePath = "Assets/PubNub/PlayModeTests/file_upload_test.txt";
439432
string filePath = Application.persistentDataPath + "/test.txt";
440433
FileName = InputFieldName.text.ToString();
441434
if(!string.IsNullOrEmpty(FileName)){
@@ -473,14 +466,6 @@ void ButtonEncryptHandler(){
473466
Debug.Log("cipher key set");
474467
}
475468

476-
// void InputFieldNameHandler(){
477-
// FileName = InputFieldName.text;
478-
// }
479-
480-
// void InputFieldIDHandler(){
481-
// FileID = InputFieldID.text;
482-
// }
483-
484469
// Use this for initialization
485470
void Start () {
486471
AddComponents();
@@ -499,7 +484,6 @@ void Init(){
499484
pnConfiguration.LogVerbosity = PNLogVerbosity.BODY;
500485
pnConfiguration.PresenceTimeout = 120;
501486
pnConfiguration.PresenceInterval= 60;
502-
pnConfiguration.AuthKey = "authKey";
503487
pnConfiguration.HeartbeatNotificationOption = PNHeartbeatNotificationOption.All;
504488

505489
//TODO: remove
@@ -537,7 +521,6 @@ void MessageCounts(List<string> listChannels, PubNub pubnub){
537521

538522
Dictionary<string, Dictionary<string, object>> messageList = new Dictionary<string, Dictionary<string, object>>();
539523

540-
541524
void SubscribeCallbackHandler2(object sender, EventArgs e) {
542525
SubscribeEventEventArgs mea = e as SubscribeEventEventArgs;
543526

@@ -631,41 +614,31 @@ void SubscribeCallbackHandler(object sender, EventArgs e){
631614
Debug.Log("SubscribeCallbackHandler Event handler");
632615
SubscribeEventEventArgs mea = e as SubscribeEventEventArgs;
633616

634-
if(mea.Status != null){
635-
switch (mea.Status.Category){
636-
case PNStatusCategory.PNConnectedCategory:
637-
PrintStatus(mea.Status);
638-
// pubnub.Publish().Channel("my_channel").Message("Hello from the PubNub Unity SDK").Ttl(10).UsePost(true).Async((result, status) => {
639-
// if(!status.Error){
640-
// Debug.Log (string.Format("DateTime {0}, In Publish Example, Timetoken: {1}", DateTime.UtcNow , result.Timetoken));
641-
// } else {
642-
// Debug.Log (status.Error);
643-
// Debug.Log (status.ErrorData.Info);
644-
// }
645-
646-
// });
647-
648-
break;
649-
case PNStatusCategory.PNUnexpectedDisconnectCategory:
650-
case PNStatusCategory.PNTimeoutCategory:
651-
pubnub.Reconnect();
652-
pubnub.CleanUp();
653-
break;
654-
}
655-
} else {
656-
Debug.Log("mea.Status null" + e.GetType().ToString() + mea.GetType().ToString());
657-
}
658-
if(mea.MessageResult != null){
659-
Debug.Log ("In Example, SubscribeCallback in message" + mea.MessageResult.Channel + mea.MessageResult.Payload);
660-
Display(string.Format("SubscribeCallback Result: {0}", pubnub.JsonLibrary.SerializeToJsonString(mea.MessageResult.Payload)));
661-
}
662-
if(mea.PresenceEventResult != null){
663-
Debug.Log ("In Example, SubscribeCallback in presence" + mea.PresenceEventResult.Channel + mea.PresenceEventResult.Occupancy + mea.PresenceEventResult.Event + mea.PresenceEventResult.State);
664-
}
665-
if(mea.SignalEventResult != null){
666-
Debug.Log ("In Example, SubscribeCallback in SignalEventResult" + mea.SignalEventResult.Channel + mea.SignalEventResult.Payload);
667-
Display(string.Format("SubscribeCallback SignalEventResult: {0}", pubnub.JsonLibrary.SerializeToJsonString(mea.SignalEventResult.Payload)));
617+
if(mea.Status != null){
618+
switch (mea.Status.Category){
619+
case PNStatusCategory.PNConnectedCategory:
620+
PrintStatus(mea.Status);
621+
break;
622+
case PNStatusCategory.PNUnexpectedDisconnectCategory:
623+
case PNStatusCategory.PNTimeoutCategory:
624+
pubnub.Reconnect();
625+
pubnub.CleanUp();
626+
break;
668627
}
628+
} else {
629+
Debug.Log("mea.Status null" + e.GetType().ToString() + mea.GetType().ToString());
630+
}
631+
if(mea.MessageResult != null){
632+
Debug.Log ("In Example, SubscribeCallback in message" + mea.MessageResult.Channel + mea.MessageResult.Payload);
633+
Display(string.Format("SubscribeCallback Result: {0}", pubnub.JsonLibrary.SerializeToJsonString(mea.MessageResult.Payload)));
634+
}
635+
if(mea.PresenceEventResult != null){
636+
Debug.Log ("In Example, SubscribeCallback in presence" + mea.PresenceEventResult.Channel + mea.PresenceEventResult.Occupancy + mea.PresenceEventResult.Event + mea.PresenceEventResult.State);
637+
}
638+
if(mea.SignalEventResult != null){
639+
Debug.Log ("In Example, SubscribeCallback in SignalEventResult" + mea.SignalEventResult.Channel + mea.SignalEventResult.Payload);
640+
Display(string.Format("SubscribeCallback SignalEventResult: {0}", pubnub.JsonLibrary.SerializeToJsonString(mea.SignalEventResult.Payload)));
641+
}
669642
}
670643

671644
void RemoveChannelsFromPush(List<string> listChannels, PubNub pubnub, string deviceId, PNPushType pnPushType){
@@ -764,18 +737,27 @@ void ListAllChannelsOfGroup(PubNub pubnub, string cg){
764737
}
765738

766739
void FetchMessages(PubNub pubnub, List<string> listChannels){
767-
pubnub.FetchMessages().Channels(listChannels).IncludeMeta(true).Async ((result, status) => {
740+
pubnub.FetchMessages().Channels(new List<string>(){ch1}).IncludeMeta(true).Async ((result, status) => {
768741
if(status.Error){
769742
Debug.Log (string.Format("In Example, FetchMessages Error: {0} {1} {2}", status.StatusCode, status.ErrorData, status.Category));
770743
} else {
771744
Debug.Log (string.Format("In FetchMessages, result: "));//,result.EndTimetoken, result.Messages[0].ToString()));
772745
foreach(KeyValuePair<string, List<PNMessageResult>> kvp in result.Channels){
773746
Debug.Log("kvp channelname" + kvp.Key);
747+
int count = 0;
774748
foreach(PNMessageResult pnMessageResut in kvp.Value){
775-
Debug.Log("Channel: " + pnMessageResut.Channel);
776-
Debug.Log("payload: " + pnMessageResut.Payload.ToString());
777-
Debug.Log("timetoken: " + pnMessageResut.Timetoken.ToString());
778-
Display(string.Format("Channel {0}, payload {1}, timetoken {2}", pnMessageResut.Channel, pnMessageResut.Payload.ToString(), pnMessageResut.Timetoken.ToString()));
749+
count++;
750+
try{
751+
752+
Debug.Log("Channel: " + pnMessageResut.Channel);
753+
Debug.Log("Timetoken: " + pnMessageResut.Timetoken.ToString());
754+
Debug.Log("Payload: " + pnMessageResut.Payload.ToString());
755+
756+
Display("Payload: " + pnMessageResut.Payload.ToString());
757+
}catch (Exception ex){
758+
Debug.Log("payload: " + pnMessageResut.Payload.ToString());
759+
Debug.Log("ex: " + ex.ToString());
760+
}
779761
}
780762
}
781763
}
@@ -795,6 +777,7 @@ void DisplayHereNowResult(PNHereNowResult result){
795777
sb.Append("in HereNow channel occupancy: " + hereNowChannelData.Occupancy.ToString());
796778
Display(string.Format("channelName: {0}", hereNowChannelData.Occupancy));
797779
List<PNHereNowOccupantData> hereNowOccupantData = hereNowChannelData.Occupants as List<PNHereNowOccupantData>;
780+
Display(string.Format("hereNowOccupantData: {0}", hereNowOccupantData.Count));
798781
if(hereNowOccupantData != null){
799782
foreach(PNHereNowOccupantData pnHereNowOccupantData in hereNowOccupantData){
800783
if(pnHereNowOccupantData.State != null){

PubNubUnity/Assets/PubNub/Helpers/MessageActionsHelpers.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using System.Collections.Generic;
34

45
namespace PubNubAPI
@@ -51,6 +52,13 @@ public static Dictionary<string, PNHistoryMessageActionsTypeValues> ExtractMessa
5152
foreach (KeyValuePair<string, object> kvpActionValues in objActionValues)
5253
{
5354
object[] actionAttributes = kvpActionValues.Value as object[];
55+
if(actionAttributes == null){
56+
List<object> actionAttributesList = kvpActionValues.Value as List<object>;
57+
if(actionAttributesList != null){
58+
actionAttributes = actionAttributesList.Cast<object>().ToArray();
59+
}
60+
}
61+
5462
List<PNHistoryMessageActionsTypeValueAttributes> actionValueAttributes = new List<PNHistoryMessageActionsTypeValueAttributes>();
5563
foreach(object actionValueAttribute in actionAttributes){
5664
Dictionary<string, object> attributeValues= actionValueAttribute as Dictionary<string, object>;

0 commit comments

Comments
 (0)