homebridge-plugins / node-arlo

JS library for Arlo Cameras
17 stars 15 forks source link

Beta branch error replace is not a function #26

Closed mrbythatmuch closed 4 years ago

mrbythatmuch commented 4 years ago

In client.ts chunk is buffer it is not a string so the code below errors out. Also the regex results in a JSON string that is not properly formatted see suggested changes at bottom.

response.message.addListener('data', (chunk) => { let data: Responses.SubscribeChunkData; try { data = JSON.parse(chunk.replace(/^event:\s*/, '"event": "').replace(/\s*data:\s*/, '", "data": ')).data; } catch (error) { throw new Error(error); }

Changing FROM data = JSON.parse(chunk.replace(/^event:\s*/, '"event": "').replace(/\s*data:\s*/, '", "data": ')).data;

TO data = JSON.parse(chunk.toString().trimEnd().replace(/^event:\s*/, '{"event": "').replace(/\s*data:\s*/, '", "data": ').concat('}'));

github-actions[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.