Skip to content

Instantly share code, notes, and snippets.

@djensen47
Last active March 4, 2016 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djensen47/293f3b9e4500e778b443 to your computer and use it in GitHub Desktop.
Save djensen47/293f3b9e4500e778b443 to your computer and use it in GitHub Desktop.
vehicle-socket-ish.js
{
"uri": "vehicle://door/front/left",
"data": {
"status": "closed",
"lock": true,
"zone": {}
}
}
//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" ;-)
@djensen47
Copy link
Author

The json is just an example and probably needs some work but I based it on the Vehicle Interface spec for Door.

@peterMelco
Copy link

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.

@djensen47
Copy link
Author

@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