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" ;-) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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.