Websocket API questions

I read the Websocket API here https://iot.mozilla.org/wot/#web-thing-websocket-api
I have two questions:

  1. Is this Websocket API implemented on the gateway?
  2. If yes, can I connect to a single WS endpoint and read/write from/to all devices? As I see from the specs, it is expected to create a new WS connection for each device. If we have 100 devices in the gateway, that means 100 simultaneously opened WS connections in order to get real-time state updates in some 3rd party app (e.g. a UI). This is not good.

Yes. You can see implementation here.

No.
I think it would be nice if we could pick up all events with a single websocket as you say. However, even if this is implemented, it probably will not be written at https://iot.mozilla.org/wot/.
It seems that wot API is focusing on a single thing interface. On the other hand, the gateway implements interfaces for things in addition to the wot API to handle multiple devices. For example, GET /things gets descriptions of all devices on the gateway.

Thanks for that answer. As I see, we have a problem here interacting real-time with more than one device. If I want to create a 3rd party UI app now, I need to open a lot of WS connections to the gateway, each for each device in it. That may not be even technically possible, as browsers implement limitation for simultaneously opened connections. I see that this implementation is by WOT specification, but WOT was meant for a single device purposes, while gateway is meant to cover many devices underneath. So maybe its worth thinking about another interface that is gateway specific, not WOT specific?

Yes that is the API implemented by the Things Gateway and yes it is currently necessary to open one WebSocket per Thing, using the Thing’s URL. I do think we should add the ability to have multiple Things per WebSocket, we may just need to add a thing ID (URI) to each message. See https://github.com/mozilla-iot/wot/issues/46

The Web Thing API is intended for both individual devices and for gateways which expose the Web Thing API for multiple devices.