import { c } from "./chunk-BA3WIOU6.js"; import { o } from "./chunk-SOSOZIX6.js"; import { x } from "./chunk-K6QDYFZU.js"; import { v } from "./chunk-ZHRAUKVQ.js"; import { n as n2 } from "./chunk-Z4JTBD7M.js"; import { U as U2 } from "./chunk-5DMBXPN2.js"; import { Bt } from "./chunk-VEGAOVMY.js"; import { k2 as k } from "./chunk-QCKFNSN2.js"; import { e, n5 as n, y3 as y } from "./chunk-6SOHRC7T.js"; import { D, U } from "./chunk-V6P2MAQQ.js"; import { s2 as s, s3 as s2 } from "./chunk-E5O6P5I2.js"; import { i, q, r, t } from "./chunk-YXWMMD76.js"; // node_modules/@arcgis/core/layers/support/StreamConnection.js var c2 = class extends n2.EventedAccessor { get connectionError() { return this.errorString ? new s2("stream-connection", this.errorString) : null; } onFeature(r2) { this.emit("data-received", r2); } }; e([y({ readOnly: true })], c2.prototype, "connectionError", null), c2 = e([n("esri.layers.support.StreamConnection")], c2); var n3 = c2; // node_modules/@arcgis/core/layers/graphics/sources/connections/WebSocketConnection.js var p; !function(e2) { e2[e2.CONNECTING = 0] = "CONNECTING", e2[e2.OPEN = 1] = "OPEN", e2[e2.CLOSING = 2] = "CLOSING", e2[e2.CLOSED = 3] = "CLOSED"; }(p || (p = {})); var u = class extends n3 { constructor(e2) { super(), this.errorString = null; const { geometryType: t3, spatialReference: o2, sourceSpatialReference: s3 } = e2; this._config = e2, this._featureZScaler = o(t3, s3, o2), this._open(); } async _open() { await this._tryCreateWebSocket(), this.destroyed || await this._handshake(); } destroy() { r(this._websocket) && (this._websocket.onopen = null, this._websocket.onclose = null, this._websocket.onerror = null, this._websocket.onmessage = null, this._websocket.close()), this._websocket = null; } get connectionStatus() { if (t(this._websocket)) return "disconnected"; switch (this._websocket.readyState) { case p.CONNECTING: case p.OPEN: return "connected"; case p.CLOSING: case p.CLOSED: return "disconnected"; } } async _tryCreateWebSocket(e2 = this._config.source.path, s3 = 1e3, r2 = 0) { try { if (this.destroyed) return; const t3 = Bt(e2, this._config.customParameters); this._websocket = await this._createWebSocket(t3), this.notifyChange("connectionStatus"); } catch (c3) { const i2 = s3 / 1e3; return this._config.maxReconnectionAttempts && r2 >= this._config.maxReconnectionAttempts ? (s.getLogger(this.declaredClass).error(new s2("websocket-connection", "Exceeded maxReconnectionAttempts attempts. No further attempts will be made")), void this.destroy()) : (s.getLogger(this.declaredClass).error(new s2("websocket-connection", `Failed to connect. Attempting to reconnect in ${i2}s`, c3)), await U(s3), this._tryCreateWebSocket(e2, Math.min(1.5 * s3, 1e3 * this._config.maxReconnectionInterval), r2 + 1)); } } _createWebSocket(e2) { return new Promise((t3, o2) => { const s3 = new WebSocket(e2); s3.onopen = () => { if (s3.onopen = null, this.destroyed) return s3.onclose = null, void s3.close(); s3.onclose = (e3) => this._onClose(e3), s3.onerror = (e3) => this._onError(e3), s3.onmessage = (e3) => this._onMessage(e3), t3(s3); }, s3.onclose = (e3) => { s3.onopen = s3.onclose = null, o2(e3); }; }); } async _handshake(e2 = 1e4) { const s3 = this._websocket; if (t(s3)) return; const n4 = D(), i2 = s3.onmessage, { filter: a, outFields: l, spatialReference: d } = this._config; return n4.timeout(e2), s3.onmessage = (e3) => { var _a; let r2 = null; try { r2 = JSON.parse(e3.data); } catch (c3) { } r2 && "object" == typeof r2 || (s.getLogger(this.declaredClass).error(new s2("websocket-connection", "Protocol violation. Handshake failed - malformed message", e3.data)), n4.reject(), this.destroy()), ((_a = r2.spatialReference) == null ? void 0 : _a.wkid) !== (d == null ? void 0 : d.wkid) && (s.getLogger(this.declaredClass).error(new s2("websocket-connection", `Protocol violation. Handshake failed - expected wkid of ${d.wkid}`, e3.data)), n4.reject(), this.destroy()), "json" !== r2.format && (s.getLogger(this.declaredClass).error(new s2("websocket-connection", "Protocol violation. Handshake failed - format is not set", e3.data)), n4.reject(), this.destroy()), a && r2.filter !== a && s.getLogger(this.declaredClass).error(new s2("websocket-connection", "Tried to set filter, but server doesn't support it")), l && r2.outFields !== l && s.getLogger(this.declaredClass).error(new s2("websocket-connection", "Tried to set outFields, but server doesn't support it")), s3.onmessage = i2, n4.resolve(); }, s3.send(JSON.stringify({ filter: a, outFields: l, format: "json", spatialReference: { wkid: d.wkid } })), n4.promise; } _onMessage(e2) { try { const o2 = JSON.parse(e2.data); if ("featureResult" !== o2.type) throw new s2("websocket-connection", "Protocol violation - Expected to find message of type 'featureResult'", o2); for (const e3 of o2.features) r(this._featureZScaler) && this._featureZScaler(e3.geometry), this.onFeature(e3); } catch (r2) { return s.getLogger(this.declaredClass).error(new s2("websocket-connection", "Failed to parse message", r2)), void this.destroy(); } } _onError(e2) { const t3 = "Encountered an error over WebSocket connection"; this._set("errorString", t3), s.getLogger(this.declaredClass).error("websocket-connection", t3); } _onClose(e2) { this._websocket = null, this.notifyChange("connectionStatus"), 1e3 !== e2.code && s.getLogger(this.declaredClass).error("websocket-connection", `WebSocket closed unexpectedly with error code ${e2.code}`), this.destroyed || this._open(); } }; e([y()], u.prototype, "connectionStatus", null), e([y()], u.prototype, "errorString", void 0), u = e([n("esri.layers.graphics.sources.connections.WebSocketConnection")], u); // node_modules/@arcgis/core/layers/graphics/sources/connections/GeoEventConnection.js var m = 1e4; var p2 = { maxQueryDepth: 5, maxRecordCountFactor: 3 }; var _ = class extends u { constructor(e2) { super({ ...p2, ...e2 }); } async _open() { const e2 = await this._fetchServiceDefinition(this._config.source); e2.timeInfo.trackIdField || s.getLogger(this.declaredClass).warn("GeoEvent service was configured without a TrackIdField. This may result in certain functionality being disabled. The purgeOptions.maxObservations property will have no effect."); const t3 = this._fetchWebSocketUrl(e2.streamUrls, this._config.spatialReference); this._buddyServicesQuery || (this._buddyServicesQuery = this._queryBuddyServices()), await this._buddyServicesQuery, await this._tryCreateWebSocket(t3); const { filter: r2, outFields: o2 } = this._config; this.destroyed || this._setFilter(r2, o2); } _onMessage(e2) { let t3; try { t3 = this._enrich(JSON.parse(e2.data)), r(this._featureZScaler) && this._featureZScaler(t3.geometry); } catch (i2) { return void s.getLogger(this.declaredClass).error(new s2("geoevent-connection", "Failed to parse message", i2)); } this.onFeature(t3); } async _fetchServiceDefinition(e2) { const r2 = { f: "json", ...this._config.customParameters }, s3 = U2(e2.path, { query: r2, responseType: "json" }), o2 = (await s3).data; return this._serviceDefinition = o2, o2; } _fetchWebSocketUrl(e2, t3) { const r2 = e2[0], { urls: s3, token: o2 } = r2, i2 = this._inferWebSocketBaseUrl(s3); return Bt(`${i2}/subscribe`, { outSR: "" + t3.wkid, token: o2 }); } _inferWebSocketBaseUrl(e2) { if (1 === e2.length) return e2[0]; for (const t3 of e2) if (t3.includes("wss")) return t3; return s.getLogger(this.declaredClass).error(new s2("geoevent-connection", "Unable to infer WebSocket url", e2)), null; } async _setFilter(e2, t3) { const o2 = this._websocket; if (t(o2) || t(e2) && t(t3)) return; const n4 = JSON.stringify({ filter: this._serializeFilter(e2, t3) }); let a = false; const u2 = D(), d = () => { a || (this.destroyed || this._websocket !== o2 || s.getLogger(this.declaredClass).error(new s2("geoevent-connection", "Server timed out when setting filter")), u2.reject()); }, l = (e3) => { const t4 = JSON.parse(e3.data); t4.filter && (t4.error && (s.getLogger(this.declaredClass).error(new s2("geoevent-connection", "Failed to set service filter", t4.error)), this._set("errorString", `Could not set service filter - ${t4.error}`), u2.reject(t4.error)), o2.onmessage = this._onMessage.bind(this), a = true, u2.resolve()); }; return o2.onmessage = l, o2.send(n4), setTimeout(d, m), u2.promise; } _serializeFilter(e2, t3) { const n4 = {}; if (t(e2) && t(t3)) return n4; if (r(e2) && e2.geometry) try { const t4 = v(e2.geometry); if ("extent" !== t4.type) throw new s2(`Expected extent but found type ${t4.type}`); n4.geometry = JSON.stringify(t4.shiftCentralMeridian()); } catch (a) { s.getLogger(this.declaredClass).error(new s2("geoevent-connection", "Encountered an error when setting connection geometryDefinition", a)); } return r(e2) && e2.where && "1 = 1" !== e2.where && (n4.where = e2.where), r(t3) && (n4.outFields = t3.join(",")), n4; } _enrich(e2) { if (!this._relatedFeatures) return e2; const t3 = this._serviceDefinition.relatedFeatures.joinField, o2 = e2.attributes[t3]; if (!this._relatedFeatures.has(o2)) return s.getLogger(this.declaredClass).warn("geoevent-connection", "Feature join failed. Is the join field configured correctly?", e2), e2; const { attributes: i2, geometry: n4 } = this._relatedFeatures.get(o2); for (const r2 in i2) e2.attributes[r2] = i2[r2]; return n4 && (e2.geometry = n4), e2.geometry || e2.centroid || s.getLogger(this.declaredClass).error(new s2("geoevent-connection", "Found malformed feature - no geometry found", e2)), e2; } async _queryBuddyServices() { try { const { relatedFeatures: e2, keepLatestArchive: t3 } = this._serviceDefinition, r2 = this._queryRelatedFeatures(e2), s3 = this._queryArchive(t3); await r2; const o2 = await s3; if (!o2) return; for (const i2 of o2.features) this.onFeature(this._enrich(i2)); } catch (e2) { s.getLogger(this.declaredClass).error(new s2("geoevent-connection", "Encountered an error when querying buddy services", { error: e2 })); } } async _queryRelatedFeatures(e2) { if (!e2) return; const t3 = await this._queryBuddy(e2.featuresUrl); this._addRelatedFeatures(t3); } async _queryArchive(e2) { if (e2) return this._queryBuddy(e2.featuresUrl); } async _queryBuddy(e2) { const t3 = new (await import("./FeatureLayer-PKSF7I4I.js")).default({ url: e2 }), { capabilities: r2 } = await t3.load(), s3 = r2.query.supportsMaxRecordCountFactor, o2 = r2.query.supportsPagination, i2 = r2.query.supportsCentroid, c3 = this._config.maxRecordCountFactor, u2 = t3.capabilities.query.maxRecordCount, d = s3 ? u2 * c3 : u2, l = new x(); if (l.outFields = i(this._config.outFields, ["*"]), l.where = i(q(this._config.filter, "where"), "1=1"), l.returnGeometry = true, l.returnExceededLimitFeatures = true, l.outSpatialReference = k.fromJSON(this._config.spatialReference), i2 && (l.returnCentroid = true), s3 && (l.maxRecordCountFactor = c3), o2) return l.num = d, t3.destroy(), this._queryPages(e2, l); const g = await c(e2, l, this._config.sourceSpatialReference); return t3.destroy(), g.data; } async _queryPages(e2, t3, r2 = [], s3 = 0) { t3.start = r(t3.num) ? s3 * t3.num : null; const { data: i2 } = await c(e2, t3, this._config.sourceSpatialReference); return i2.exceededTransferLimit && s3 < this._config.maxQueryDepth ? (i2.features.forEach((e3) => r2.push(e3)), this._queryPages(e2, t3, r2, s3 + 1)) : (r2.forEach((e3) => i2.features.push(e3)), i2); } _addRelatedFeatures(e2) { const t3 = /* @__PURE__ */ new Map(), r2 = e2.features, s3 = this._serviceDefinition.relatedFeatures.joinField; for (const o2 of r2) { const e3 = o2.attributes[s3]; t3.set(e3, o2); } this._relatedFeatures = t3; } }; _ = e([n("esri.layers.graphics.sources.connections.GeoEventConnection")], _); var w = _; // node_modules/@arcgis/core/layers/graphics/sources/connections/createConnection.js function t2(t3, o2, r2, c3, i2, s3, a, m2) { const p3 = 0 === t3.path.indexOf("wss://") || 0 === t3.path.indexOf("ws://"), f = { source: t3, sourceSpatialReference: o2, spatialReference: r2, geometryType: c3, filter: i2, maxReconnectionAttempts: s3, maxReconnectionInterval: a, customParameters: m2 }; return p3 ? new u(f) : new w(f); } export { t2 as t }; //# sourceMappingURL=chunk-3KO6RYS2.js.map