All files / client master-control-client.js

93.87% Statements 46/49
87.5% Branches 21/24
100% Functions 11/11
93.87% Lines 46/49

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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93    7x 7x 7x     8x 8x     157x     21x     3x 1x     2x 2x 3x 3x     3x 1x       26x 26x     8x 8x 6x   8x     10x 10x 10x     10x 39x 39x 37x   2x       188x   12x 1x   11x             38x 1x   37x   118x 1x   117x   12x 1x   11x   8x 1x   7x       7x  
"use strict";
/*! Copyright (c) 2021 Siemens AG. Licensed under the MIT License. */
Object.defineProperty(exports, "__esModule", { value: true });
exports.MasterControlClient = void 0;
const __1 = require("..");
class MasterControlClient extends __1.Client {
    constructor() {
        super(...arguments);
        this._connectionStates = new __1.AgvIdMap();
    }
    publish(topic, subject, object, options) {
        return this.publishTopic(topic, subject, object, options);
    }
    subscribe(topic, subject, handler) {
        return this.subscribeTopic(topic, subject, handler);
    }
    trackAgvs(handler) {
        if (!this._trackHandler) {
            this._trackHandler = handler;
        }
        else {
            const previousHandler = this._trackHandler;
            this._trackHandler = (subject, state, timestamp) => {
                previousHandler(subject, state, timestamp);
                handler(subject, state, timestamp);
            };
        }
        for (const [agvId, connection] of this._connectionStates) {
            handler(agvId, connection.connectionState, connection.timestamp);
        }
    }
    getTrackedState(subject) {
        const conn = this._connectionStates.get(subject);
        return conn ? { state: conn.connectionState, timestamp: conn.timestamp } : undefined;
    }
    getTrackedStates() {
        const states = [];
        for (const [agvId, conn] of this._connectionStates) {
            states.push({ subject: agvId, state: conn.connectionState, timestamp: conn.timestamp });
        }
        return states;
    }
    reset() {
        super.reset();
        this._connectionStates.clear();
        this._trackHandler = undefined;
    }
    async onStarted() {
        await this.subscribeTopic(__1.Topic.Connection, {}, (connection, agvId) => {
            this._connectionStates.set(agvId, connection);
            if (!this._trackHandler) {
                return;
            }
            this._trackHandler(agvId, connection.connectionState, connection.timestamp);
        });
    }
    validateTopicDirection(topic, asInbound) {
        switch (topic) {
            case __1.Topic.Connection:
                if (!asInbound) {
                    throw new TypeError("Outbound connection message not compatible with MasterControlClient");
                }
                break;
            case __1.Topic.Factsheet:
                if (!asInbound) {
                    throw new TypeError("Outbound factsheet message not compatible with MasterControlClient");
                }
                break;
            case __1.Topic.InstantActions:
                if (asInbound) {
                    throw new TypeError("Inbound instantActions message not compatible with MasterControlClient");
                }
                break;
            case __1.Topic.Order:
                if (asInbound) {
                    throw new TypeError("Inbound order message not compatible with MasterControlClient");
                }
                break;
            case __1.Topic.State:
                if (!asInbound) {
                    throw new TypeError("Outbound state message not compatible with MasterControlClient");
                }
                break;
            case __1.Topic.Visualization:
                if (!asInbound) {
                    throw new TypeError("Outbound visualization message not compatible with MasterControlClient");
                }
                break;
        }
    }
}
exports.MasterControlClient = MasterControlClient;