@@ -39,17 +39,24 @@ bool PubNub::begin(const char *publish_key_, const char *subscribe_key_, const c
39
39
subscribe_key = subscribe_key_;
40
40
origin = origin_;
41
41
uuid = NULL ;
42
+ auth = NULL ;
42
43
}
43
44
44
45
void PubNub::set_uuid (const char *uuid_)
45
46
{
46
47
uuid = uuid_;
47
48
}
48
49
50
+ void PubNub::set_auth (const char *auth_)
51
+ {
52
+ auth = auth_;
53
+ }
54
+
49
55
PubNub_BASE_CLIENT *PubNub::publish (const char *channel, const char *message, int timeout)
50
56
{
51
57
PubNub_BASE_CLIENT &client = publish_client;
52
58
unsigned long t_start;
59
+ int have_param = 0 ;
53
60
54
61
retry:
55
62
t_start = millis ();
@@ -92,7 +99,14 @@ PubNub_BASE_CLIENT *PubNub::publish(const char *channel, const char *message, in
92
99
}
93
100
}
94
101
95
- enum PubNub_BH ret = this ->_request_bh (client, t_start, timeout, ' ?' );
102
+ if (auth) {
103
+ client.print (have_param ? ' &' : ' ?' );
104
+ client.print (" auth=" );
105
+ client.print (auth);
106
+ have_param = 1 ;
107
+ }
108
+
109
+ enum PubNub_BH ret = this ->_request_bh (client, t_start, timeout, have_param ? ' &' : ' ?' );
96
110
switch (ret) {
97
111
case PubNub_BH_OK:
98
112
/* Success and reached body, return handle to the client
@@ -115,6 +129,7 @@ PubSubClient *PubNub::subscribe(const char *channel, int timeout)
115
129
{
116
130
PubSubClient &client = subscribe_client;
117
131
unsigned long t_start;
132
+ int have_param = 0 ;
118
133
119
134
retry:
120
135
t_start = millis ();
@@ -136,9 +151,16 @@ PubSubClient *PubNub::subscribe(const char *channel, int timeout)
136
151
if (uuid) {
137
152
client.print (" ?uuid=" );
138
153
client.print (uuid);
154
+ have_param = 1 ;
155
+ }
156
+ if (auth) {
157
+ client.print (have_param ? ' &' : ' ?' );
158
+ client.print (" auth=" );
159
+ client.print (auth);
160
+ have_param = 1 ;
139
161
}
140
162
141
- enum PubNub_BH ret = this ->_request_bh (client, t_start, timeout, uuid ? ' &' : ' ?' );
163
+ enum PubNub_BH ret = this ->_request_bh (client, t_start, timeout, have_param ? ' &' : ' ?' );
142
164
switch (ret) {
143
165
case PubNub_BH_OK:
144
166
/* Success and reached body. We need to eat '[' first,
0 commit comments