diff --git a/ember.js b/ember.js index ed0a98e..e8c4ab3 100755 --- a/ember.js +++ b/ember.js @@ -149,6 +149,10 @@ TreeNode.prototype.addChild = function(child) { this.children.push(child); } +TreeNode.prototype.isNode = function() { + return ((this instanceof Node) || (this instanceof QualifiedNode)); +} + TreeNode.prototype.isMatrix = function() { return ((this instanceof MatrixNode) || (this instanceof QualifiedMatrix)); } diff --git a/package.json b/package.json index 67899de..9909f27 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "emberplus", - "version": "1.7.22", + "version": "1.7.23", "description": "Javascript implementation of the Ember+ automation protocol", "main": "index.js", "scripts": { diff --git a/server.js b/server.js index ad4dff3..2a9c6c3 100755 --- a/server.js +++ b/server.js @@ -382,6 +382,19 @@ TreeServer.prototype.handleGetDirectory = function(client, element) { // report their value changes automatically. this.subscribe(client, element); } + else if (element.isNode()) { + const children = element.getChildren(); + if (children != null) { + for (let i = 0; i < children.length; i++) { + const child = children[i]; + if ((child.isMatrix() || child.isParameter()) && + (!child.isStream())) { + this.subscribe(client, child); + } + } + } + } + let res = this.getQualifiedResponse(element); if (this._debug) { console.log("getDirectory response", res); diff --git a/test/Server.test.js b/test/Server.test.js index 86bc530..de9cc2d 100755 --- a/test/Server.test.js +++ b/test/Server.test.js @@ -4,7 +4,7 @@ const DeviceTree = require("../").DeviceTree; const LOCALHOST = "127.0.0.1"; -const PORT = 9008; +const PORT = 9009; const init = function(_src,_tgt) { @@ -90,7 +90,7 @@ describe("server", function() { describe("JSONtoTree", function() { let jsonTree; - before(function() { + beforeAll(function() { jsonTree = init(); }); it("should generate an ember tree from json", function() { @@ -106,7 +106,7 @@ describe("server", function() { describe("Server - Client communication", function() { let server,client; - before(function() { + beforeAll(function() { jsonTree = init(); const root = TreeServer.JSONtoTree(jsonTree); server = new TreeServer(LOCALHOST, PORT, root); @@ -115,7 +115,7 @@ describe("server", function() { console.log("server listening"); }); }); - after(function() { + afterAll(function() { client.disconnect(); server.close(); }) @@ -142,6 +142,7 @@ describe("server", function() { .then(() => { expect(client.root.elements[0].children[0].children.length).toBe(4); expect(client.root.elements[0].children[0].children[3].contents.identifier).toBe("author"); + expect(server.subscribers["0.0.0"]).toBeDefined(); }); }); });