Skip to content

Commit

Permalink
Merge pull request #32 from evs-broadcast/feature/handle_devices_with…
Browse files Browse the repository at this point in the history
…_two_roots

Handle ember node with two roots
  • Loading branch information
dufourgilles authored Mar 13, 2019
2 parents 6149636 + 1f8269d commit 0e34ada
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions device.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ DeviceTree.prototype.getDirectory = function (qnode) {
}

self.callback = (error, node) => {
if (node == null) { return; }
if (node == null) { return; }
if (error) {
if (self._debug) {
console.log("Received getDirectory error", error);
Expand All @@ -160,25 +160,37 @@ DeviceTree.prototype.getDirectory = function (qnode) {
reject(error);
return;
}
let requestedPath = qnode.getPath();
if (requestedPath === "") {
if (qnode instanceof ember.Root) {
if (qnode.elements == null || qnode.elements.length === 0) {
if (self._debug) {
console.log("getDirectory response", node);
console.log("getDirectory response", node);
}
return self.callback(new Error("Invalid qnode for getDirectory"));
}
requestedPath = qnode.elements["0"].getPath();
}
const nodeElements = node == null ? null : node.elements;
if (nodeElements != null
&& nodeElements.every(el => el.getPath() === requestedPath || isDirectSubPathOf(el.getPath(), requestedPath))) {
if (self._debug) {
console.log("Received getDirectory response", node);

const nodeElements = node == null ? null : node.elements;

if (nodeElements != null
&& nodeElements.every(el => el._parent instanceof ember.Root)) {
if (self._debug) {
console.log("Received getDirectory response", node);
}
self.clearTimeout(); // clear the timeout now. The resolve below may take a while.
self.finishRequest();
resolve(node); // make sure the info is treated before going to next request.
}
} else {
let requestedPath = qnode.getPath();
const nodeElements = node == null ? null : node.elements;
if (nodeElements != null
&& nodeElements.every(el => isDirectSubPathOf(el.getPath(), requestedPath))) {
if (self._debug) {
console.log("Received getDirectory response", node);
}
self.clearTimeout(); // clear the timeout now. The resolve below may take a while.
self.finishRequest();
resolve(node); // make sure the info is treated before going to next request.
}
self.clearTimeout(); // clear the timeout now. The resolve below may take a while.
self.finishRequest();
resolve(node); // make sure the info is treated before going to next request.
}
};

Expand Down

0 comments on commit 0e34ada

Please sign in to comment.