From a0b3ac319801f94f7a911943ca9565f938dcaac6 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Mon, 21 Jul 2014 17:11:47 -0700 Subject: [PATCH] Track metalevels and levels in .transform; exploit this in websocket driver --- route.js | 9 +++++---- websocket-driver.js | 11 ++++------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/route.js b/route.js index 2a677fd..b30e7d5 100644 --- a/route.js +++ b/route.js @@ -1391,8 +1391,8 @@ function Routing(exports) { var ls = inputMetaLevels[i]; var levels = []; for (var j = 0; j < ls.length; j++) { - var p = f(ls[j] || inputEmptyLevel); - if (!emptyCheck(p)) { + var p = f(ls[j] || inputEmptyLevel, i, j); + if (!emptyCheck(p, i, j)) { while (levels.length < j) levels.push(outputEmptyLevel); levels.push(p); } @@ -1406,8 +1406,9 @@ function Routing(exports) { }; Gestalt.prototype.transform = function (f) { - return new Gestalt(mapLevels(this.metaLevels, function (p) { - return new GestaltLevel(f(p.subscriptions), f(p.advertisements)); + return new Gestalt(mapLevels(this.metaLevels, function (p, ml, l) { + return new GestaltLevel(f(p.subscriptions, ml, l, false), + f(p.advertisements, ml, l, true)); }, function (p) { return p.isEmpty(); }, emptyLevel, emptyLevel)); diff --git a/websocket-driver.js b/websocket-driver.js index 5fcd9e6..b4a9ae7 100644 --- a/websocket-driver.js +++ b/websocket-driver.js @@ -52,8 +52,9 @@ WebSocketConnection.prototype.relayGestalt = function () { WebSocketConnection.prototype.aggregateGestalt = function () { var self = this; - return this.peerGestalt.transform(function (m) { - return route.compilePattern(true, [self.label, __, route.embeddedMatcher(m)]); + return this.peerGestalt.transform(function (m, metaLevel) { + return route.compilePattern(true, + [self.label, metaLevel, route.embeddedMatcher(m)]); }).union(this.relayGestalt()); }; @@ -84,8 +85,6 @@ WebSocketConnection.prototype.sendLocalRoutes = function () { WebSocketConnection.prototype.collectMatchers = function (getAdvertisements, level, g) { var extractMetaLevels = route.compileProjection([this.label, _$, __]); var mls = route.matcherKeys(g.project(extractMetaLevels, getAdvertisements, 0, level)); - if (mls === null) return; - // ^ TODO: fix this cheap and nasty hack. Better protocol for gestalt use, perhaps. for (var i = 0; i < mls.length; i++) { var metaLevel = mls[i][0]; // only one capture in the projection var extractMatchers = route.compileProjection([this.label, metaLevel, _$]); @@ -113,9 +112,7 @@ WebSocketConnection.prototype.handleEvent = function (e) { break; case "message": var m = e.message; - if (m.length && m.length === 3 - && m[0] === this.label - && typeof(m[1]) === "number") + if (m.length && m.length === 3 && m[0] === this.label) { var encoded = JSON.stringify(encodeEvent(sendMessage(m[2], m[1], e.isFeedback))); if (this.deduplicator.accept(encoded)) {