Skip to content

Commit 21d9106

Browse files
authored
Merge pull request #23 from pubnub/develop
Presence Timeout changes / PNPresenceEventResult.state fix
2 parents 3ef8453 + 10e2480 commit 21d9106

33 files changed

+463
-386
lines changed

.pubnub.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
---
22
changelog:
3+
-
4+
changes:
5+
-
6+
text: "Presence Timeout cannot be lower than 20"
7+
type: improvement
8+
-
9+
text: "PNPresenceEventResult.State property not populated in callback"
10+
type: bug
11+
date: Jun 4, 19
12+
version: v4.2.1
313
-
414
changes:
515
-
@@ -362,6 +372,7 @@ supported-platforms:
362372
- "Unity 5.5.1"
363373
- "Unity 2017.3.*"
364374
- "Unity 2018.*"
375+
- "Unity 2019.*"
365376
platforms:
366377
- "iOS player, will require iOS 7.0 or higher."
367378
- "Android, OS 2.3.1 or later; ARMv7 (Cortex) CPU with NEON support or Atom CPU; OpenGL ES 2.0 or later."
@@ -372,4 +383,4 @@ supported-platforms:
372383
- "Ubuntu 12.04+, with Graphics card DX9 (shader model 3.0) or DX11 with feature level 9.3 capabilities; and CPU SSE2 instruction set support."
373384
- "Mac OS X 10.8+, with Graphics card DX9 (shader model 3.0) or DX11 with feature level 9.3 capabilities; and CPU SSE2 instruction set support."
374385
version: "PubNub Unity SDK"
375-
version: v4.2.0
386+
version: v4.2.1

AppVeyorScripts/install.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
$source = "https://netstorage.unity3d.com/unity/a9f86dcd79df/Windows64EditorInstaller/UnitySetup64-2017.3.0f3.exe"
1+
$source = "https://download.unity3d.com/download_unity/292b93d75a2c/Windows64EditorInstaller/UnitySetup64.exe"
22
$destination = ".\UnitySetup64.exe"
33
Invoke-WebRequest $source -OutFile $destination
44
Start-Process -FilePath ".\UnitySetup64.exe" -Wait -ArgumentList ('/S', '/Q')
5-
Write-Host "$(date) UnitySetup64-2017.3.0f3 Installed"-ForegroundColor green
5+
Write-Host "$(date) UnitySetup64-2019.1 Installed"-ForegroundColor green

AppVeyorScripts/test.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,11 @@ $res = Invoke-Pester -OutputFormat NUnitXml -OutputFile $testResultsFile -PassTh
55
if ($res.FailedCount -gt 0) {
66
throw "$($res.FailedCount) tests failed."
77
}
8+
9+
$testResultsFile2 = "C:\temp\results2.xml"
10+
Start-Process -Wait -FilePath Unity.exe -ArgumentList ('-batchmode', '-nographics', '-logFile', 'C:\temp\unity.log', '-runTests', '-projectPath', 'c:\projects\unity\PubNubUnity', '-testResults', $testResultsFile2, '-testPlatform', 'playmode', '-quit')
11+
$res2 = Invoke-Pester -OutputFormat NUnitXml -OutputFile $testResultsFile2 -PassThru
12+
(New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path $testResultsFile2))
13+
if ($res2.FailedCount -gt 0) {
14+
throw "$($res2.FailedCount) tests failed."
15+
}

PubNubUnity/Assets/PubNub/Editor/EncryptionTests.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,13 @@ public void TestNullEncryption ()
618618
//encrypt
619619

620620
var ex = Assert.Throws<ArgumentNullException>(() => pubnubCrypto.Encrypt (message)); // True (("").Equals (encrypted));
621+
/* #if UNITY_2019_1_OR_NEWER
622+
UnityEngine.Debug.Log ("UNITY_2019_1_OR_NEWER:" + ex.Message);*/
623+
Assert.That(ex.Message.Contains("Value cannot be null."),ex.Message, null);
624+
/* #else
625+
UnityEngine.Debug.Log ("!UNITY_2019_1_OR_NEWER:" + ex.Message);
621626
Assert.That(ex.Message.Contains("Argument cannot be null."),ex.Message, null);
627+
#endif*/
622628
}
623629

624630
/// <summary>
@@ -636,7 +642,11 @@ public void TestNullDecryption ()
636642
//decrypt
637643
var ex = Assert.Throws<ArgumentNullException>(() => pubnubCrypto.Decrypt (message));
638644

639-
Assert.That(ex.Message.Contains("Argument cannot be null."), ex.Message, null);
645+
/* #if UNITY_2019_1_OR_NEWER */
646+
Assert.That(ex.Message.Contains("Value cannot be null."),ex.Message, null);
647+
/* #else
648+
Assert.That(ex.Message.Contains("Argument cannot be null."),ex.Message, null);
649+
#endif*/
640650
}
641651

642652
/// <summary>

PubNubUnity/Assets/PubNub/Examples/Example.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ void Init(){
400400
pnConfiguration.SecretKey = "demo";
401401
pnConfiguration.CipherKey = "enigma";
402402
pnConfiguration.LogVerbosity = PNLogVerbosity.BODY;
403-
pnConfiguration.PresenceTimeout = 60;
404-
pnConfiguration.PresenceInterval= 30;
403+
pnConfiguration.PresenceTimeout = 19;
404+
pnConfiguration.PresenceInterval= 12;
405405
pnConfiguration.AuthKey = "authKey";
406406
pnConfiguration.HeartbeatNotificationOption = PNHeartbeatNotificationOption.All;
407407

@@ -569,7 +569,7 @@ void SubscribeCallbackHandler(object sender, EventArgs e){
569569
Display(string.Format("SubscribeCallback Result: {0}", pubnub.JsonLibrary.SerializeToJsonString(mea.MessageResult.Payload)));
570570
}
571571
if(mea.PresenceEventResult != null){
572-
Debug.Log ("In Example, SubscribeCallback in presence" + mea.PresenceEventResult.Channel + mea.PresenceEventResult.Occupancy + mea.PresenceEventResult.Event);
572+
Debug.Log ("In Example, SubscribeCallback in presence" + mea.PresenceEventResult.Channel + mea.PresenceEventResult.Occupancy + mea.PresenceEventResult.Event + mea.PresenceEventResult.State);
573573
}
574574
}
575575

PubNubUnity/Assets/PubNub/PlayModeTests/PlayModeCommon.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ public class PlayModeCommon {
5555
public static bool SslOn = true;
5656
public static bool CipherOn = false;
5757
public static string Origin = "ps.pndsn.com";
58-
public static string PublishKey = "pub-c-34a8af78-0bb3-40cb-b0c4-be413d9a6b19";
59-
public static string SubscribeKey = "sub-c-b3fd9fce-af5b-11e7-8d62-62090b44bf58";
60-
public static string SecretKey = "sec-c-ZTVlNDIxNTAtMDUxOC00YjA3LWFiYzktZTBlMjljZjc3NGQx";
58+
public static string PublishKey = "pub-c-c1648ded-d156-4a2d-9dbb-a23262945fe2";
59+
public static string SubscribeKey = "sub-c-c14b8948-7dfe-11e9-aee4-2e27e4d79cf8";
60+
public static string SecretKey = "sec-c-OGI5YmJiMmUtMjIwNS00NjkzLTkxZmYtMjE1N2I2MDhlNDM5";
6161
public static string cg1 = "channelGroup1";
6262
public static string cg2 = "channelGroup2";
6363
public static string ch1 = "channel1";

PubNubUnity/Assets/PubNub/PlayModeTests/PlayModeTests.cs

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ public IEnumerator TestTime() {
3737
public IEnumerator TestWhereNow() {
3838
PNConfiguration pnConfiguration = PlayModeCommon.SetPNConfig(false);
3939
PubNub pubnub = new PubNub(pnConfiguration);
40-
string whereNowChannel = "UnityTestWhereNowChannel";
40+
System.Random r = new System.Random ();
41+
42+
string whereNowChannel = "UnityTestWhereNowChannel"+ r.Next (100);
43+
4144
pubnub.Subscribe ().Channels(new List<string> (){whereNowChannel}).WithPresence().Execute();
4245
yield return new WaitForSeconds (PlayModeCommon.WaitTimeBetweenCalls);
4346
bool testReturn = false;
@@ -228,15 +231,17 @@ public IEnumerator TestHereNowChannelsAndChannelGroups() {
228231
pubnub.CleanUp();
229232
}
230233

231-
[UnityTest]
234+
//[UnityTest]
232235
public IEnumerator TestGlobalHereNow() {
233236
PNConfiguration pnConfiguration = PlayModeCommon.SetPNConfig(false);
234237
pnConfiguration.UUID = "UnityTestHereNowUUID";
235238
PubNub pubnub = new PubNub(pnConfiguration);
236-
string hereNowChannel = "UnityTestHereNowChannel6";
237-
string hereNowChannel2 = "UnityTestHereNowChannel7";
238-
string hereNowChannel3 = "UnityTestHereNowChannel8";
239-
string channelGroup = "channelGroup4";
239+
System.Random r = new System.Random ();
240+
241+
string hereNowChannel = "UnityTestHereNowChannel6"+ r.Next (100);
242+
string hereNowChannel2 = "UnityTestHereNowChannel7"+ r.Next (100);
243+
string hereNowChannel3 = "UnityTestHereNowChannel8"+ r.Next (100);
244+
string channelGroup = "channelGroup4"+ r.Next (100);
240245
List<string> channelList = new List<string>();
241246
channelList.Add(hereNowChannel);
242247
channelList.Add(hereNowChannel2);
@@ -272,10 +277,13 @@ public IEnumerator TestGlobalHereNowWithoutUUID() {
272277
PNConfiguration pnConfiguration = PlayModeCommon.SetPNConfig(false);
273278
pnConfiguration.UUID = "UnityTestHereNowUUID";
274279
PubNub pubnub = new PubNub(pnConfiguration);
275-
string hereNowChannel = "UnityTestHereNowChannel9";
276-
string hereNowChannel2 = "UnityTestHereNowChannel10";
277-
string hereNowChannel3 = "UnityTestHereNowChannel11";
278-
string channelGroup = "channelGroup5";
280+
System.Random r = new System.Random ();
281+
282+
string hereNowChannel = "UnityTestHereNowChannel6"+ r.Next (100);
283+
string hereNowChannel2 = "UnityTestHereNowChannel7"+ r.Next (100);
284+
string hereNowChannel3 = "UnityTestHereNowChannel8"+ r.Next (100);
285+
286+
string channelGroup = "channelGroup5"+ r.Next (100);
279287
List<string> channelList = new List<string>();
280288
channelList.Add(hereNowChannel);
281289
channelList.Add(hereNowChannel2);
@@ -305,15 +313,17 @@ public IEnumerator TestGlobalHereNowWithoutUUID() {
305313
pubnub.CleanUp();
306314
}
307315

308-
[UnityTest]
316+
//[UnityTest]
309317
public IEnumerator TestGlobalHereNowWithoutUUIDWithState() {
310318
PNConfiguration pnConfiguration = PlayModeCommon.SetPNConfig(false);
311-
pnConfiguration.UUID = "UnityTestHereNowUUID";
312-
PubNub pubnub = new PubNub(pnConfiguration);
313-
string hereNowChannel = "UnityTestHereNowChannel12";
314-
string hereNowChannel2 = "UnityTestHereNowChannel13";
315-
string hereNowChannel3 = "UnityTestHereNowChannel14";
316-
string channelGroup = "channelGroup6";
319+
System.Random r = new System.Random ();
320+
pnConfiguration.UUID = "UnityTestHereNowUUID"+ r.Next (100);
321+
PubNub pubnub = new PubNub(pnConfiguration);
322+
323+
string hereNowChannel = "UnityTestHereNowChannel6"+ r.Next (100);
324+
string hereNowChannel2 = "UnityTestHereNowChannel7"+ r.Next (100);
325+
string hereNowChannel3 = "UnityTestHereNowChannel8"+ r.Next (100);
326+
string channelGroup = "channelGroup6"+ r.Next (100);
317327
List<string> channelList = new List<string>();
318328
channelList.Add(hereNowChannel);
319329
channelList.Add(hereNowChannel2);
@@ -324,16 +334,16 @@ public IEnumerator TestGlobalHereNowWithoutUUIDWithState() {
324334
pubnub.AddChannelsToChannelGroup().ChannelGroup(channelGroup).Channels(channelList).Async((result, status) => {
325335
Debug.Log ("in AddChannelsToChannelGroup");
326336
});
327-
yield return new WaitForSeconds (PlayModeCommon.WaitTimeBetweenCalls);
337+
yield return new WaitForSeconds (PlayModeCommon.WaitTimeBetweenCalls2);
328338

329339
pubnub.Subscribe ().Channels(channelList2).ChannelGroups(channelGroupList).Execute();
330-
yield return new WaitForSeconds (PlayModeCommon.WaitTimeBetweenCalls);
340+
yield return new WaitForSeconds (PlayModeCommon.WaitTimeBetweenCalls2);
331341
Dictionary<string, object> state = new Dictionary<string, object>();
332342
state.Add("k", "v");
333343
pubnub.SetPresenceState().Channels(channelList).ChannelGroups(channelGroupList).State(state).Async ((result, status) => {
334344

335345
});
336-
yield return new WaitForSeconds (PlayModeCommon.WaitTimeBetweenCalls);
346+
yield return new WaitForSeconds (PlayModeCommon.WaitTimeBetweenCalls2);
337347
bool testReturn = false;
338348
pubnub.HereNow().IncludeState(true).IncludeUUIDs(false).Async((result, status) => {
339349
Debug.Log("status.Error:" + status.Error);
@@ -344,7 +354,7 @@ public IEnumerator TestGlobalHereNowWithoutUUIDWithState() {
344354
testReturn = !status.Error && matchResult;
345355
});
346356

347-
yield return new WaitForSeconds (PlayModeCommon.WaitTimeForAsyncResponse);
357+
yield return new WaitForSeconds (PlayModeCommon.WaitTimeBetweenCalls3);
348358
Assert.True(testReturn, "test didn't return");
349359
pubnub.CleanUp();
350360
}
@@ -354,10 +364,12 @@ public IEnumerator TestHereNowWithUUIDWithState() {
354364
PNConfiguration pnConfiguration = PlayModeCommon.SetPNConfig(false);
355365
pnConfiguration.UUID = "UnityTestHereNowUUID";
356366
PubNub pubnub = new PubNub(pnConfiguration);
357-
string hereNowChannel = "UnityTestHereNowChannel15";
358-
string hereNowChannel2 = "UnityTestHereNowChannel16";
359-
string hereNowChannel3 = "UnityTestHereNowChannel17";
360-
string channelGroup = "channelGroup7";
367+
System.Random r = new System.Random ();
368+
369+
string hereNowChannel = "UnityTestHereNowChannel6"+ r.Next (100);
370+
string hereNowChannel2 = "UnityTestHereNowChannel7"+ r.Next (100);
371+
string hereNowChannel3 = "UnityTestHereNowChannel8"+ r.Next (100);
372+
string channelGroup = "channelGroup6"+ r.Next (100);
361373
List<string> channelList = new List<string>();
362374
channelList.Add(hereNowChannel);
363375
channelList.Add(hereNowChannel2);

PubNubUnity/Assets/PubNub/PubNubUnity/PNConfiguration.cs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,40 @@ public PNReconnectionPolicy ReconnectionPolicy
117117
get {return reconnectionPolicy;}
118118
set {reconnectionPolicy = value;}
119119
}
120-
public int PresenceTimeout { get; set;}
120+
private int calPresenceInterval(int presenceTimeout){
121+
return (presenceTimeout/2)-1;
122+
}
123+
124+
private int presenceTimeout = 0;
125+
private readonly int minPresenceTimeout = 20;
126+
public int PresenceTimeout {
127+
get{
128+
return presenceTimeout;
129+
}
130+
set{
131+
presenceTimeout = value;
132+
if(presenceTimeout < minPresenceTimeout){
133+
#if (ENABLE_PUBNUB_LOGGING)
134+
string logText = string.Format("PresenceTimeout value less than the min recommended value of {0}, setting value to {0}", minPresenceTimeout);
135+
UnityEngine.Debug.Log (string.Format("\n{0} {1}, {2}: {3}\n", DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString(), TimeZone.CurrentTimeZone.StandardName, logText, minPresenceTimeout));
136+
#endif
137+
presenceTimeout = minPresenceTimeout;
138+
}
139+
PresenceInterval = calPresenceInterval(presenceTimeout);
140+
}
141+
}
142+
143+
private int presenceInterval = 0;
144+
121145
//In seconds, How often the client should announce it's existence via heartbeating.
122-
public int PresenceInterval { get; set;}
146+
public int PresenceInterval {
147+
get{
148+
return presenceInterval;
149+
}
150+
set{
151+
presenceInterval = value;
152+
}
153+
}
123154

124155
private int maximumReconnectionRetries = 50;
125156
public int MaximumReconnectionRetries

PubNubUnity/Assets/PubNub/PubNubUnity/PubNubUnityBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace PubNubAPI
77
public class PubNubUnityBase
88
{
99
protected Counter publishMessageCounter;
10-
private const string build = "4.2.0";
10+
private const string build = "4.2.1";
1111
private string pnsdkVersion = string.Format ("PubNub-CSharp-Unity/{0}", build);
1212

1313
public string Version {

PubNubUnity/Assets/PubNub/Workers/SubscriptionWorker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ internal PNPresenceEvent CreatePNPresenceEvent (object payload)
762762
(pnPresenceEventDict.ContainsKey("uuid"))?pnPresenceEventDict["uuid"].ToString():"",
763763
occupancy,
764764
timetoken,
765-
(pnPresenceEventDict.ContainsKey("state"))?pnPresenceEventDict["state"]:null,
765+
(pnPresenceEventDict.ContainsKey("data"))?pnPresenceEventDict["data"]:null,
766766
Utility.CheckKeyAndConvertObjToStringArr((pnPresenceEventDict.ContainsKey("join"))?pnPresenceEventDict["join"]:null),
767767
Utility.CheckKeyAndConvertObjToStringArr((pnPresenceEventDict.ContainsKey("leave"))?pnPresenceEventDict["leave"]:null),
768768
Utility.CheckKeyAndConvertObjToStringArr((pnPresenceEventDict.ContainsKey("timeout"))?pnPresenceEventDict["timeout"]:null),

0 commit comments

Comments
 (0)