jeffreydwalter / arlo-go

WIP - (BETA) - Go package for interacting with Netgear's Arlo camera system.
MIT License
42 stars 8 forks source link

Disconnect on logout. #1

Closed dougnd closed 5 years ago

dougnd commented 5 years ago

I was getting a panic after Login:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x18 pc=0x633dd4]
 goroutine 35 [running]:
github.com/jeffreydwalter/arlo-golang.(*eventStream).listen.func1(0xc000172230, 0xc000186048)
        /Users/dndawso/go/src/github.com/jeffreydwalter/arlo-golang/events_stream.go:96 +0x114
created by github.com/jeffreydwalter/arlo-golang.(*eventStream).listen
        /Users/dndawso/go/src/github.com/jeffreydwalter/arlo-golang/events_stream.go:81 +0x98

It is caused by the event received on the channel being nil. I suspect this is due to the channel being closed. I also noticed the following message sent right before the nils:

EVENT: &{ { "action": "logout", "transId": "xxxx!XXXXXXX-XXX-XXXXXXXX","reason":"You have been logged out because you logged in from another device."} message }

This PR causes a disconnect if an action of "logout" is received. I don't know if this is the most desirable fix, but it works for me and my use case (a simple library downloader). If you have other suggestions, I am all ears.

Doug.

jeffreydwalter commented 5 years ago

Hey Doug,

Good catch! Thanks for the PR!

You're the first person to file a PR, so I'm just curious what you think about the library so far? Have you had a chance to look through the code at all? How's the library's API for you as a consumer of the library? I'd definitely appreciate any feedback!

It's still a work in progress, obviously... :) But the major parts are pretty solid. The main thing that's missing at this point is to implement a lot of actual Arlo API calls. I've implemented quite a few of the useful ones that I had in my Python version of this library, but I found a bunch more while digging through the Arlo source code.

Thanks, Jeff

dougnd commented 5 years ago

The library looks good so far.

I don't actually have any Arlo devices, this was some work for my dad. He was a mechanical engineer and has a great technical mind, but most of his exposure to programming stopped with early fortran. He saw an article that used your python library to download videos from the gallery, but struggled to get python installed on windows. From the python library I saw a link to the go variant and figured with go I can cross compile on my mac to and exe that will run without dependencies on his windows machine (plus I'm been using and loving go at work).

So, I have not explored the library much. I basically just took your sample code and customized it as https://github.com/dougnd/arloDownloader .

The other problems I encountered: 1) The DownloadFile function did not seem to work for me (I got 404s). I think it was because the underlying request library was setting all sorts of headers (including JSON content type). I haven't opened an issue because I haven't done enough due diligence to even make sure it was not something I was doing wrong -- go makes it super easy to just code up a download file function myself.

2) Using a future date for fromDate when calling GetLibrary results in an error like:

We are sorry, the database service is currently down. Please try again. reason: DynamoDB Service Unreachable

It took me a little while to figure out that the database server is not down, I just had done the math wrong. If you are interested, I could submit a PR to add a check on the dates to the library, but this was admittedly my own fault. The error message was just a red herring.

Overall, the library was quite easy to use!