@@ -14,8 +14,9 @@ public class Example : MonoBehaviour {
14
14
15
15
string cg1 = "channelGroup1" ;
16
16
string cg2 = "channelGroup2" ;
17
+ // string ch1 = "team_readonly.a8e9eff5-eed9-4d42-8686-1ecb6fe9916f";
17
18
string ch1 = "channel1" ;
18
- string ch2 = "channel2 " ;
19
+ string ch2 = "channel11 " ;
19
20
UnityEngine . UI . Text TextContent ;
20
21
UnityEngine . UI . Button ButtonClear ;
21
22
UnityEngine . UI . Button ButtonReset ;
@@ -238,16 +239,13 @@ void ButtonFireHandler(){
238
239
} ) ;
239
240
}
240
241
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) => {
243
242
Dictionary < string , string > dict = new Dictionary < string , string > ( ) ;
244
243
dict . Add ( "k1" , "v1" ) ;
245
244
246
245
Dictionary < string , string > meta = new Dictionary < string , string > ( ) ;
247
246
meta . Add ( "k1" , "v1" ) ;
248
247
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 ) => {
251
249
if ( ! status . Error ) {
252
250
Debug . Log ( string . Format ( "DateTime {0}, In Publish Example, Timetoken: {1}" , DateTime . UtcNow , result . Timetoken ) ) ;
253
251
Display ( string . Format ( "Published: {0}" , result . Timetoken ) ) ;
@@ -257,7 +255,6 @@ void ButtonPublishHandler(){
257
255
}
258
256
259
257
} ) ;
260
- //}
261
258
}
262
259
void ButtonPublishPostHandler ( ) {
263
260
@@ -427,15 +424,11 @@ void AddComponents(){
427
424
ButtonEncrypt = GameObject . Find ( "ButtonEncrypt" ) . GetComponent < UnityEngine . UI . Button > ( ) ;
428
425
ButtonEncrypt . onClick . AddListener ( ButtonEncryptHandler ) ;
429
426
InputFieldName = GameObject . Find ( "InputFieldName" ) . GetComponent < UnityEngine . UI . InputField > ( ) ;
430
- // InputFieldName.onValueChanged.AddListener(InputFieldNameHandler);
431
427
InputFieldID = GameObject . Find ( "InputFieldID" ) . GetComponent < UnityEngine . UI . InputField > ( ) ;
432
- // InputFieldID.onValueChanged.AddListener(InputFieldIDHandler);
433
-
434
428
}
435
429
436
430
void ButtonSendFileHandler ( ) {
437
431
string publishMessage = string . Format ( "publishMessage_{0}{1}" , "id_" , "constString" ) ;
438
- // string filePath = "Assets/PubNub/PlayModeTests/file_upload_test.txt";
439
432
string filePath = Application . persistentDataPath + "/test.txt" ;
440
433
FileName = InputFieldName . text . ToString ( ) ;
441
434
if ( ! string . IsNullOrEmpty ( FileName ) ) {
@@ -473,14 +466,6 @@ void ButtonEncryptHandler(){
473
466
Debug . Log ( "cipher key set" ) ;
474
467
}
475
468
476
- // void InputFieldNameHandler(){
477
- // FileName = InputFieldName.text;
478
- // }
479
-
480
- // void InputFieldIDHandler(){
481
- // FileID = InputFieldID.text;
482
- // }
483
-
484
469
// Use this for initialization
485
470
void Start ( ) {
486
471
AddComponents ( ) ;
@@ -499,7 +484,6 @@ void Init(){
499
484
pnConfiguration . LogVerbosity = PNLogVerbosity . BODY ;
500
485
pnConfiguration . PresenceTimeout = 120 ;
501
486
pnConfiguration . PresenceInterval = 60 ;
502
- pnConfiguration . AuthKey = "authKey" ;
503
487
pnConfiguration . HeartbeatNotificationOption = PNHeartbeatNotificationOption . All ;
504
488
505
489
//TODO: remove
@@ -537,7 +521,6 @@ void MessageCounts(List<string> listChannels, PubNub pubnub){
537
521
538
522
Dictionary < string , Dictionary < string , object > > messageList = new Dictionary < string , Dictionary < string , object > > ( ) ;
539
523
540
-
541
524
void SubscribeCallbackHandler2 ( object sender , EventArgs e ) {
542
525
SubscribeEventEventArgs mea = e as SubscribeEventEventArgs ;
543
526
@@ -631,41 +614,31 @@ void SubscribeCallbackHandler(object sender, EventArgs e){
631
614
Debug . Log ( "SubscribeCallbackHandler Event handler" ) ;
632
615
SubscribeEventEventArgs mea = e as SubscribeEventEventArgs ;
633
616
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 ;
668
627
}
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
+ }
669
642
}
670
643
671
644
void RemoveChannelsFromPush ( List < string > listChannels , PubNub pubnub , string deviceId , PNPushType pnPushType ) {
@@ -764,18 +737,27 @@ void ListAllChannelsOfGroup(PubNub pubnub, string cg){
764
737
}
765
738
766
739
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 ) => {
768
741
if ( status . Error ) {
769
742
Debug . Log ( string . Format ( "In Example, FetchMessages Error: {0} {1} {2}" , status . StatusCode , status . ErrorData , status . Category ) ) ;
770
743
} else {
771
744
Debug . Log ( string . Format ( "In FetchMessages, result: " ) ) ; //,result.EndTimetoken, result.Messages[0].ToString()));
772
745
foreach ( KeyValuePair < string , List < PNMessageResult > > kvp in result . Channels ) {
773
746
Debug . Log ( "kvp channelname" + kvp . Key ) ;
747
+ int count = 0 ;
774
748
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
+ }
779
761
}
780
762
}
781
763
}
@@ -795,6 +777,7 @@ void DisplayHereNowResult(PNHereNowResult result){
795
777
sb . Append ( "in HereNow channel occupancy: " + hereNowChannelData . Occupancy . ToString ( ) ) ;
796
778
Display ( string . Format ( "channelName: {0}" , hereNowChannelData . Occupancy ) ) ;
797
779
List < PNHereNowOccupantData > hereNowOccupantData = hereNowChannelData . Occupants as List < PNHereNowOccupantData > ;
780
+ Display ( string . Format ( "hereNowOccupantData: {0}" , hereNowOccupantData . Count ) ) ;
798
781
if ( hereNowOccupantData != null ) {
799
782
foreach ( PNHereNowOccupantData pnHereNowOccupantData in hereNowOccupantData ) {
800
783
if ( pnHereNowOccupantData . State != null ) {
0 commit comments