Track metalevels and levels in .transform; exploit this in websocket driver

This commit is contained in:
Tony Garnock-Jones 2014-07-21 17:11:47 -07:00
parent 19374f6926
commit a0b3ac3198
2 changed files with 9 additions and 11 deletions

View File

@ -1391,8 +1391,8 @@ function Routing(exports) {
var ls = inputMetaLevels[i]; var ls = inputMetaLevels[i];
var levels = []; var levels = [];
for (var j = 0; j < ls.length; j++) { for (var j = 0; j < ls.length; j++) {
var p = f(ls[j] || inputEmptyLevel); var p = f(ls[j] || inputEmptyLevel, i, j);
if (!emptyCheck(p)) { if (!emptyCheck(p, i, j)) {
while (levels.length < j) levels.push(outputEmptyLevel); while (levels.length < j) levels.push(outputEmptyLevel);
levels.push(p); levels.push(p);
} }
@ -1406,8 +1406,9 @@ function Routing(exports) {
}; };
Gestalt.prototype.transform = function (f) { Gestalt.prototype.transform = function (f) {
return new Gestalt(mapLevels(this.metaLevels, function (p) { return new Gestalt(mapLevels(this.metaLevels, function (p, ml, l) {
return new GestaltLevel(f(p.subscriptions), f(p.advertisements)); return new GestaltLevel(f(p.subscriptions, ml, l, false),
f(p.advertisements, ml, l, true));
}, function (p) { }, function (p) {
return p.isEmpty(); return p.isEmpty();
}, emptyLevel, emptyLevel)); }, emptyLevel, emptyLevel));

View File

@ -52,8 +52,9 @@ WebSocketConnection.prototype.relayGestalt = function () {
WebSocketConnection.prototype.aggregateGestalt = function () { WebSocketConnection.prototype.aggregateGestalt = function () {
var self = this; var self = this;
return this.peerGestalt.transform(function (m) { return this.peerGestalt.transform(function (m, metaLevel) {
return route.compilePattern(true, [self.label, __, route.embeddedMatcher(m)]); return route.compilePattern(true,
[self.label, metaLevel, route.embeddedMatcher(m)]);
}).union(this.relayGestalt()); }).union(this.relayGestalt());
}; };
@ -84,8 +85,6 @@ WebSocketConnection.prototype.sendLocalRoutes = function () {
WebSocketConnection.prototype.collectMatchers = function (getAdvertisements, level, g) { WebSocketConnection.prototype.collectMatchers = function (getAdvertisements, level, g) {
var extractMetaLevels = route.compileProjection([this.label, _$, __]); var extractMetaLevels = route.compileProjection([this.label, _$, __]);
var mls = route.matcherKeys(g.project(extractMetaLevels, getAdvertisements, 0, level)); 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++) { for (var i = 0; i < mls.length; i++) {
var metaLevel = mls[i][0]; // only one capture in the projection var metaLevel = mls[i][0]; // only one capture in the projection
var extractMatchers = route.compileProjection([this.label, metaLevel, _$]); var extractMatchers = route.compileProjection([this.label, metaLevel, _$]);
@ -113,9 +112,7 @@ WebSocketConnection.prototype.handleEvent = function (e) {
break; break;
case "message": case "message":
var m = e.message; var m = e.message;
if (m.length && m.length === 3 if (m.length && m.length === 3 && m[0] === this.label)
&& m[0] === this.label
&& typeof(m[1]) === "number")
{ {
var encoded = JSON.stringify(encodeEvent(sendMessage(m[2], m[1], e.isFeedback))); var encoded = JSON.stringify(encodeEvent(sendMessage(m[2], m[1], e.isFeedback)));
if (this.deduplicator.accept(encoded)) { if (this.deduplicator.accept(encoded)) {