swissmanu / harmonyhubjs-client

A Node.JS library which allows you to interact with your Logitech Harmony Hub.
https://github.com/swissmanu/harmonyhubjs-client
MIT License
155 stars 42 forks source link

identity response error #10

Closed Hans-S closed 8 years ago

Hans-S commented 8 years ago

I'm trying to get my homebridge (https://github.com/nfarina/homebridge) to work. It includes the harmony client. I can't get connected, because of this:

        if(response.identity && response.identity !== undefined) {
                   ^

TypeError: Cannot read property 'identity' of undefined at Client. (/Users/Hans/homebridge/node_modules/harmonyhubjs-client/lib/login/hub.js:64:15)

As far as I can tell, this is because there's CDATA in the response that contains the identity. The identity is part of the CDATA. The CDATA part however is not returned in the received stanza, hence the response.identity is undefined. I'm not a js coder, so can't change the code to fix this myself. I've seen that there was a CDATA issue in the past, but it looks like there was no CDATA in the identity response before (according to your docs).

Any ideas?

swissmanu commented 8 years ago

can you distinguish which XML parser is used on your installation?

node-xmpp, the XMPP library beneath harmonyhubjs-client uses ltx as parser for the XMPP communication. ltx has various backends which are implemented using differend techniques. the best one, node-expat is a native binding to a C library which is quite robust. though, if the binding was not able to build, there is a fallback to a "native javascript" implementation called sax_ltx. that implementation does not support the non-XMPP-standard compliant protocol which Logitech uses for its hubs.

i tried to contribute to ltx and fix that problem (https://github.com/node-xmpp/ltx/pull/51). the maintainers decided to not introduce my change to their code since their library is only thought to be used with XMPP in mind.

tl;dr: check during npm install if node-expat throws some errors during building its native extension and try to fix that. otherwise you might have some spare time to implement another parser? :)

lyonsad commented 8 years ago

I am getting this same error. I have ltx installed.

Hans-S commented 8 years ago

When I run pm install on ltx, only warnings I get are similar to these: ../deps/libexpat/lib/xmltok.c:471:1: warning: missing field 'isName2' initializer [-Wmissing-field-initializers] I can run a node test in node-expat, and it returns OK 32 honoured.

Besides the compiler warnings, it looks ok. I'm not sure how I can determine for sure what parser is actually used. Also, not that I'm not an expert (far from it actually, I'm really an end user), so my suggestion that it has to do with CDATA is not a given. This is more of the error situation I see:

received XMPP stanza: /Users/Hans/homebridge/node_modules/harmonyhubjs-client/lib/login/hub.js:64 if(response.identity && response.identity !== undefined) { ^

But as you can see, the identity is not present in what I receive. In the received data before the Stanza, I can see the stanza data, but also the missing identity field, which is in a CDATA part.

While typing this, I seem to have resolved the issue. I have this running on two different Macs. On my Macbook, I forced use of the node-expat parser by hardcoding the parser in Parser.js and StreamParser.js. After that, I also did this on my MacMini, which I want to run homebridge on dedicated. The hardcoding failed. It turned out that node-expat wasn't installed correctly there, which is probably because I ran the npm install using remote desktop, which results in some kind of security issue. That was resolved by using sudo and --unsafe-perms. After that, it works. So one bad installation, and a preference for the sax parser I guess. Case closed as far as I'm concerned, and thanks a lot for taking the time to answer, and for your code!

lyonsad commented 8 years ago

can you provide exactly what you did? I am on ubuntu but I am having this issue.

Hans-S commented 8 years ago

In the following files:

homebridge/node_modules/harmonyhubjs-client/node_modules/node-xmpp-client/node_modules/node-xmpp-core/lib/StreamParser.js homebridge/node_modules/harmonyhubjs-client/node_modules/node-xmpp-client/node_modules/node-xmpp-core/node_modules/ltx/lib/Parser.js

change ltx to node-expat as shown here (each source contains only one of the lines below) var LtxParser = require('./parsers/node-expat') , LtxParser = require('ltx/lib/parsers/node-expat')

If you get an error that the module is not found, run sudo npm install, node-expat module might fail installation because of security reasons.

swissmanu commented 8 years ago

thanks @Hans-S for sharing your experience.

so you did not have a "real" problem building node-expat rather than some file permission issues? i don't know how homebridge suggest to install itself. but doing "everything" as root i.e. could end up in problems like probably.

maybe one of you guys could share this knowledge in the homebridge community?

Hans-S commented 8 years ago

Looks like a permission thing mainly yeah. I see now that a similar problem is reported in the homebridge community, so good idea yea, I will try and give them a hand over there.

Cheers!

tdoescher commented 7 years ago

I have the newest version, but i have the same error. What can i do to fix this problem?

andylemin commented 7 years ago

I'm having the exact same problem (running on Debian Jessie) :( I can see the exception is coming from ltx, but I can't seem to get it to use node-expat instead as suggested by @swissmanu ?

[10/22/2016, 11:07:00 PM] Homebridge is running on port 51826.
/usr/lib/node_modules/homebridge-harmonyhub/node_modules/harmonyhubjs-client/lib/login/hub.js:59
      if (response.identity && response.identity !== undefined) {
                  ^

TypeError: Cannot read property 'identity' of undefined
    at Client.<anonymous> (/usr/lib/node_modules/homebridge-harmonyhub/node_modules/harmonyhubjs-client/lib/login/hub.js:59:19)

I have installed node-expat, how can I get homebridge to recognise it?

Thanks, Andy.

swissmanu commented 7 years ago

please have a look at #28. recently merged PR #29 should fix this problem.