Last active
March 4, 2016 00:12
-
-
Save djensen47/293f3b9e4500e778b443 to your computer and use it in GitHub Desktop.
vehicle-socket-ish.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"uri": "vehicle://door/front/left", | |
"data": { | |
"status": "closed", | |
"lock": true, | |
"zone": {} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//based on https://developer.mozilla.org/en-US/docs/Web/API/WebSocket | |
//var door = new Vehicle.Socket('vehicle://door/front/left'); | |
var door = new Vehicle.MessageBus('vehicle://door/front/left'); | |
door.onConnect(function() {}); | |
door.onMessage(function(uri, data) { | |
//data is an object based JSON or JSON-LD | |
}); | |
door.onError(function(error) {}); | |
door.send('lock'); //or other command | |
door.close(); // close bus/subscription, i.e. not "close the door" ;-) |
Looks like a good approach, one question:
door.onMessage(function(uri, data) {
//data is an object based JSON or JSON-LD
});
What does the parameter uri contain in the onMessage function ? Is it not enough to provide the uri in the MessageBus ? or is there some other purpose.
@peterMelco I was thinking of the URI as a 'channel' but the WebSocket spec returns an object that contains the 'source' and 'origin' so URI is not necessary.
Take a look at Issue #81. It's a little more fleshed out.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
json
is just an example and probably needs some work but I based it on the Vehicle Interface spec for Door.