FourPortRouterInfotron

This is a generic blueprint which let you route messages on specific output terminals, depending on message content. This is defined in the properties of the infotrons.

Sample Declaration

<div id="router1"
     impl="~0147b23e00865011dbb93d45b457cd1d4f"
     properties = "'out1': 'foo', 'out2': 'bar', 'out3': 'baz'  "
     script="http://localhost/Router.js">
</div>
## Dependencies + N/A ## Input Terminals + message_in: (expected message type: any matching defined proeprties) ## Output Terminals + out1, out2, out3, out4. Selects output terminal depending on which predefined data the input matches. ## Properties + out1 ... out4 with defined matching properties ## Demos that use it + N/A ## How does it work? When initalized, it associates strings with each output terminal. When a message appears on the input terminal, it routes it to the output port defined by the properties. ------

BLUEPRINT(
"~0147b23e00865011dbb93d45b457cd1d4f",
[
 ["message_in", "onMessage", 10]
],
[
 "out1",
 "out2",
 "out3",
 "out4"
],
function(Class)
{
    Class.prototype._onInit = function(props)
    {
        var i;
        var n = 4;
        this.match_values = [];

        for (i = 0; i < n; i ++) {
            this.match_values[i] = props["out" + (i + 1) + "_match_value"];
        }
    };

    Class.prototype.onMessage = function(msg)
    {
        var i;
        var n  = 4;

        for (i = 0; i < n; i ++) {
            if (this.match_values[i] == msg) {
                this.postMessage("out" + (i + 1), msg);
            }
        }
    };
},"Router");