All files / universal/gpii/node_modules/flowManager/src BrowserChannel.js

90% Statements 18/20
75% Branches 3/4
75% Functions 3/4
90% Lines 18/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53    1x 1x   1x   1x       1x                         1x 2x 2x       2x   2x     1x 12x 12x     12x 12x 2x     10x 10x            
"use strict";
 
var fluid = require("infusion");
var gpii = fluid.registerNamespace("gpii");
 
fluid.registerNamespace("gpii.flowManager");
 
fluid.defaults("gpii.flowManager.browserChannel", {
    gradeNames: ["fluid.modelComponent"]
});
 
fluid.defaults("gpii.flowManager.browserChannel.handler", {
    gradeNames: ["kettle.request.ws", "gpii.flowManager.sessionAware"],
    listeners: {
        onReceiveMessage: {
            funcName: "gpii.flowManager.browserChannel.receiveMessage",
            args: ["{that}",
                   "{arguments}.1",
                   "{flowManager}.solutionsRegistryDataSource",
                   "{deviceReporter}.platformReporter"]
        }
    }
});
 
gpii.flowManager.browserChannel.sendError = function (request, message) {
    fluid.log("Sending browserChannel error ", message);
    var error = {
        isError: true,
        message: message
    };
    request.sendMessage(error);
    // These codes bizarrely are not HTTP codes, but listed here: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent
    request.ws.close(1008, "Solution id not authorized");
};
 
gpii.flowManager.browserChannel.receiveMessage = function (that, message, solutionsRegistryDataSource, platformReporter) {
    var solutionId = message.payload.solutionId;
    Iif (that.established) {
        gpii.flowManager.browserChannel.sendError(that, "Connection already established - cannot send a second connect message");
    }
    solutionsRegistryDataSource.get({os: platformReporter.reportPlatform().id}, function onSuccess(entries) {
        if (!(solutionId in entries)) {
            gpii.flowManager.browserChannel.sendError(that, "Rejecting a connection request from '" + solutionId +
                      "'. The solution id was not found in the solutions registry");
        } else {
            gpii.settingsHandlers.webSockets.instance.addClient(solutionId, that);
            that.established = true;
        }
    }, function (error) {
        gpii.flowManager.browserChannel.sendError(that, error.message);
    });
};