Skip to content

Commit

Permalink
virtual_device log update properly formats actions before updating state
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamMagaluk committed Jan 19, 2016
1 parent 572a3d3 commit a7088a1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ var ZettaHttpServer = module.exports = function(zettaInstance, options) {
name = decodeURI(name);
self.zetta.log.emit('log', 'http_server', 'Websocket connection for peer "' + name + '" established.');

// Include ._env and ._loader on websocket, allows argo formatters to work used in virtual_device build actions.
var host = ws.upgradeReq.headers['host']
self.wireUpWebSocketForEvent(ws, host, '/servers/' + name);

if (self.peers[name] && self.peers[name].state !== PeerSocket.DISCONNECTED) {
// peer already connected or connecting
ws.close(4000, 'peer already connected');
Expand Down
5 changes: 5 additions & 0 deletions lib/virtual_device.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var util = require('util');
var ReadableStream = require('stream').Readable;
var EventEmitter = require('events').EventEmitter;
var rels = require('zetta-rels');
var buildDeviceActions = require('./api_formats/siren/device.siren').buildActions;

var VirtualStream = module.exports = function(topic, socket, options) {
ReadableStream.call(this, options);
Expand Down Expand Up @@ -41,6 +42,10 @@ var VirtualDevice = module.exports = function(entity, peerSocket) {
});

this._socket.on(logTopic, function(data) {
// Format data.actions to siren action format
data.actions = buildDeviceActions(data.properties.id, self._socket.ws._env, self._socket.ws._loader, data.transitions);
delete data.transitions;

self._update(data);
self._eventEmitter.emit(data.transition);
});
Expand Down

0 comments on commit a7088a1

Please sign in to comment.