developers.home-assistant icon indicating copy to clipboard operation
developers.home-assistant copied to clipboard

Websocket Documentation via Add-on is Unclear

Open qJake opened this issue 4 years ago • 7 comments

Refer to: https://github.com/home-assistant/developers.home-assistant/blob/master/docs/hassio_addon_communication.md under section Home Assistant Core.

The line regarding the Websocket API proxy is extremely unclear and does not align with standard websocket usage.

Typically, a websocket URL begins with ws:// or wss://. Since the proxy mentioned here begins with http://, the actual connection and authentication are (supposedly?) completely different.

Please add additional verbiage to this section explaining how someone would actually use this proxy, and how a pure websocket call may differ from the same call passed in via the proxy endpoint.

qJake avatar Mar 15 '20 13:03 qJake

Did you try it with a wss URL?

balloob avatar Mar 15 '20 16:03 balloob

@balloob Yes - please refer to this issue wherein I try to wrap my head around this 🙂 https://github.com/home-assistant/core/issues/31668

That issue doesn't quite have the right screenshots, but here is what I'm trying:

image

Likely because, from where this request is made (Chrome on my workstation, outside the Supervisor environment), the supervisor hostname is not known.

qJake avatar Mar 15 '20 16:03 qJake

Here is some additional experimentation I'm doing - these requests are originating server-side from within an add-on (so supervisor is a known hostname). I achieved this by writing in a small HTTP client into my add-on and deploying it into my HA instance.

image

Okay... so then we add some WebSocket upgrade headers:

image

Hmm... but there is a Connection upgrade header. Strange.

Even if we remove everything and just attempt a base websocket connection, it's still the same, so it doesn't seem to care about auth:

image

According to the WebSocket article on Wikipedia, these headers should be correct.

qJake avatar Mar 15 '20 17:03 qJake

You can't hit supervisor from a browser. You only do it in processes running on your addon container.

balloob avatar Mar 15 '20 18:03 balloob

For your frontend, you need ingress.

balloob avatar Mar 15 '20 18:03 balloob

My frontend is intended to be used from web browsers outside of the context of Home Assistant (i.e. a tablet) but from within the same network. (Also, my app is not compatible with Ingress due to the way that Ingress rewrites HTML to "fit" inside HA, but that's a separate issue and I'm OK with not using Ingress since this isn't the type of app you would sit down and use from HA anyway.)

So that's where I'm struggling to understand the architecture here. I need to be able to obtain a token from within the Supervisor that I can pass to my Javascript frontend, that will "just work" from a browser (be it inside or outside a Supervisor context). Forcing my users to manually generate a LLAT will work, but is cumbersome.

Right now, it seems like my best option would be to call the Token API endpoint and automatically generate a LLAT (if that's even possible) and save it within my app's config. Aside from those two solutions, I'm not sure how else to hook up to the WebSocket endpoint.

qJake avatar Mar 15 '20 20:03 qJake