UNPKG

dasf-messaging-typescript

Version:

Typescript RPC bindings for the data analytics software framework (DASF)

57 lines (56 loc) 2.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DigitalEarthUrlBuilder = exports.DefaultDASFUrlBuilder = void 0; var Type; (function (Type) { Type["producer"] = "producer"; Type["consumer"] = "consumer"; })(Type || (Type = {})); /** * Default url builder implementation based on host:port, namespace and topic */ class DefaultDASFUrlBuilder { static BASE_DASF_URL = "ws://%host%:%port%/ws/v2/%type%/non-persistent/public/%namespace%/%topic%/"; topic; consumeTopic; DASFConsumerURL; DASFProducerURL; constructor(host, port, namespace, topic) { this.topic = topic; this.consumeTopic = this.generateConsumeTopic(topic); this.DASFConsumerURL = this.buildUrl(host, port, namespace, Type.consumer, this.consumeTopic); this.DASFProducerURL = this.buildUrl(host, port, namespace, Type.producer, this.topic); } buildUrl(host, port, namespace, type, topic) { let url = DefaultDASFUrlBuilder.BASE_DASF_URL .replace("%host%", host) .replace("%port%", port) .replace("%namespace%", namespace) .replace("%type%", type) .replace("%topic%", topic); if (type == Type.consumer) { // append subscription url += this.generateSubscriptionPrefix() + "?subscriptionType=Exclusive"; } return url; } generateConsumeTopic(topic) { return topic + "_" + this.generateRequestToken(); } generateSubscriptionPrefix() { return "web-frontend-" + new Date().toISOString(); } generateRequestToken() { return Math.random().toString(16).slice(2); } } exports.DefaultDASFUrlBuilder = DefaultDASFUrlBuilder; class DigitalEarthUrlBuilder extends DefaultDASFUrlBuilder { static HOST = "rz-vm154.gfz-potsdam.de"; static PORT = "8082"; static NAMESPACE = "digital-earth"; constructor(topic) { super(DigitalEarthUrlBuilder.HOST, DigitalEarthUrlBuilder.PORT, DigitalEarthUrlBuilder.NAMESPACE, topic); } } exports.DigitalEarthUrlBuilder = DigitalEarthUrlBuilder;