zettajs/zetta

Device subscriptions over multiplexed ws

Closed this issue · 2 comments

Should device queries work over multiplexed ws?

I found two issues currently.

  1. https://github.com/zettajs/zetta/blob/master/lib/event_socket.js#L171 } else if (data['query']) { should be } else if (tmpData['query']) {
  2. Queries to a cloud zetta where devices exist on the hub does not work..

Eg. cloud running on localhost:3000 and hub with two devices connected running on localhost:1337

Sending subscription query/where type is not missing to the hub:

λ: wsta ws://localhost:1337/events '{"type": "subscribe", "topic": "query/where type is not missing"}'
Connected to ws://localhost:1337/events
{"type":"subscribe-ack","timestamp":1466539977840,"topic":"query/where type is not missing","subscriptionId":1}
{"type":"event","topic":"query/where type is not missing","subscriptionId":1,"data":{"class":["device","led"],"properties":{"led":1,"id":"48917c1b-7e3a-4cf0-a22f-b77471caac72","name":1,"type":"led","state":"off"},"actions":[{"class":["transition"],"name":"turn-on","method":"POST","href":"http://localhost:1337/servers/milford/devices/48917c1b-7e3a-4cf0-a22f-b77471caac72","fields":[{"name":"action","type":"hidden","value":"turn-on"}]}],"links":[{"rel":["self","edit"],"href":"http://localhost:1337/servers/milford/devices/48917c1b-7e3a-4cf0-a22f-b77471caac72"},{"rel":["up","http://rels.zettajs.io/server"],"href":"http://localhost:1337/servers/milford"},{"rel":["http://rels.zettajs.io/type","describedby"],"href":"http://localhost:1337/servers/milford/meta/led"},{"title":"state","rel":["monitor","http://rels.zettajs.io/object-stream"],"href":"ws://localhost:1337/servers/milford/events?topic=led%2F48917c1b-7e3a-4cf0-a22f-b77471caac72%2Fstate"},{"title":"logs","rel":["monitor","http://rels.zettajs.io/object-stream"],"href":"ws://localhost:1337/servers/milford/events?topic=led%2F48917c1b-7e3a-4cf0-a22f-b77471caac72%2Flogs"}]}}
{"type":"event","topic":"query/where type is not missing","subscriptionId":1,"data":{"class":["device","photocell"],"properties":{"id":"e7ffb5e3-6961-4d03-8eca-e4267c49af5a","opts":{},"intensity":0.9999999999999988,"name":"photocell","type":"photocell"},"actions":null,"links":[{"rel":["self","edit"],"href":"http://localhost:1337/servers/milford/devices/e7ffb5e3-6961-4d03-8eca-e4267c49af5a"},{"rel":["up","http://rels.zettajs.io/server"],"href":"http://localhost:1337/servers/milford"},{"rel":["http://rels.zettajs.io/type","describedby"],"href":"http://localhost:1337/servers/milford/meta/photocell"},{"title":"intensity","rel":["monitor","http://rels.zettajs.io/object-stream"],"href":"ws://localhost:1337/servers/milford/events?topic=photocell%2Fe7ffb5e3-6961-4d03-8eca-e4267c49af5a%2Fintensity"},{"title":"logs","rel":["monitor","http://rels.zettajs.io/object-stream"],"href":"ws://localhost:1337/servers/milford/events?topic=photocell%2Fe7ffb5e3-6961-4d03-8eca-e4267c49af5a%2Flogs"}]}}

Sending subscription query/where type is not missing to the cloud:

λ: wsta ws://localhost:3000/events '{"type": "subscribe", "topic": "query/where type is not missing"}'
Connected to ws://localhost:3000/events
{"type":"subscribe-ack","timestamp":1466540026097,"topic":"query/where type is not missing","subscriptionId":1}

So if yes, how would be specify the server to run the query on.

For device queries today we use a separate url parameter for the server. Eg ...?topic=query/where type is not missing&server=some-server or ...?topic=query/where type is not missing&server=*

My proposal would be for multiplexed to specify the server query in front of the topic like: some-server/query/where type is not missing or */query/where type is not missing. This would keep the same format for how we do all other multiplexed subscriptions.

Fixed in #318.