Skip to content

Commit b12b68e

Browse files
committed
Another fix for pairing
1 parent d181244 commit b12b68e

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/pairing.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,19 @@ bool AppleTVpairing(struct mdnssd_handle_s* mDNShandle, char **pSecret, const ch
174174

175175
// request a PIN code to be displayed on ATV
176176
#ifndef TEST_VECTOR
177-
if (http_parse(sock, method, resource, NULL, headers, NULL, &len) && strcasestr(resource, "200")) {
177+
fprintf(stderr, "waiting for device to show PIN code...\n");
178+
fflush(stderr);
179+
180+
// Device needs time to show prompt and display PIN, retry up to 10 seconds
181+
bool parse_result = false;
182+
for (int retry = 0; retry < 20 && !parse_result; retry++) {
183+
parse_result = http_parse(sock, method, resource, NULL, headers, NULL, &len);
184+
if (!parse_result && retry < 19) {
185+
usleep(500000); // 500ms between retries = 10 seconds total
186+
}
187+
}
188+
189+
if (parse_result && strcasestr(resource, "200")) {
178190
kd_free(headers);
179191
#else
180192
if (1) {
@@ -362,7 +374,7 @@ bool AppleTVpairing(struct mdnssd_handle_s* mDNShandle, char **pSecret, const ch
362374

363375
NFREE(body);
364376
} else {
365-
fprintf(stderr, "device did not respond to pairing request\n");
377+
fprintf(stderr, "device did not respond to pairing request (response: %s)\n", resource);
366378
fflush(stderr);
367379
}
368380

0 commit comments

Comments
 (0)