@openremote/core 1.8.0-snapshot.20250725120002 → 1.8.0-snapshot.20250728102340

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,161 +1 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { EventProviderStatus } from "./event";
11
- import { objectsEqual } from "./util";
12
- import { Util } from ".";
13
- export const subscribe = (eventProviderFactory) => (base) => class extends base {
14
- constructor() {
15
- super(...arguments);
16
- this._connectRequested = false;
17
- this._status = EventProviderStatus.DISCONNECTED;
18
- this._statusCallback = (status) => this._onEventProviderStatusChanged(status);
19
- }
20
- connectedCallback() {
21
- if (super.connectedCallback) {
22
- super.connectedCallback();
23
- }
24
- this.connectEvents();
25
- }
26
- disconnectedCallback() {
27
- this.disconnectEvents();
28
- if (super.disconnectedCallback) {
29
- super.disconnectedCallback();
30
- }
31
- }
32
- connectEvents() {
33
- if (!eventProviderFactory.getEventProvider()) {
34
- console.log("No event provider available so cannot subscribe");
35
- return;
36
- }
37
- if (this._connectRequested) {
38
- return;
39
- }
40
- this._connectRequested = true;
41
- eventProviderFactory.getEventProvider().subscribeStatusChange(this._statusCallback);
42
- this._doConnect();
43
- }
44
- disconnectEvents() {
45
- if (!this._connectRequested) {
46
- return;
47
- }
48
- this._connectRequested = false;
49
- eventProviderFactory.getEventProvider().unsubscribeStatusChange(this._statusCallback);
50
- this._onEventsDisconnect();
51
- }
52
- _doConnect() {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- if (!this.eventsConnected) {
55
- return;
56
- }
57
- this._onEventsConnect();
58
- });
59
- }
60
- get eventsConnected() {
61
- return this._connectRequested && eventProviderFactory.getEventProvider().status === EventProviderStatus.CONNECTED;
62
- }
63
- _onEventProviderStatusChanged(status) {
64
- switch (status) {
65
- case EventProviderStatus.DISCONNECTED:
66
- this._onEventsDisconnect();
67
- break;
68
- case EventProviderStatus.CONNECTED:
69
- this._doConnect();
70
- break;
71
- }
72
- }
73
- _onEventsConnect() {
74
- this._addEventSubscriptions();
75
- this.onEventsConnect();
76
- }
77
- _onEventsDisconnect() {
78
- this._removeEventSubscriptions();
79
- this.onEventsDisconnect();
80
- }
81
- /**
82
- * Defaults to subscribe to attribute events and optionally asset events, override in subclasses to do
83
- * custom subscriptions.
84
- * Returns the subscription IDs of any created subscriptions
85
- */
86
- _addEventSubscriptions() {
87
- return __awaiter(this, void 0, void 0, function* () {
88
- const isAttributes = !!this._attributeRefs;
89
- const isAsset = !!this._assetIds;
90
- const ids = this._attributeRefs ? this._attributeRefs : this._assetIds;
91
- if (ids && ids.length > 0) {
92
- this._subscriptionIds = [];
93
- if (isAsset) {
94
- const assetSubscriptionId = yield eventProviderFactory.getEventProvider().subscribeAssetEvents(ids, true, (event) => this._onEvent(event));
95
- // Check if the same IDs are in place
96
- const currentIds = this._attributeRefs ? this._attributeRefs : this._assetIds;
97
- if (!this._subscriptionIds || !Util.objectsEqual(ids, currentIds)) {
98
- eventProviderFactory.getEventProvider().unsubscribe(assetSubscriptionId);
99
- return;
100
- }
101
- this._subscriptionIds.push(assetSubscriptionId);
102
- }
103
- const subscriptionId = yield eventProviderFactory.getEventProvider().subscribeAttributeEvents(ids, isAttributes, (event) => this._onEvent(event));
104
- // Check if the same IDs are in place
105
- const currentIds = this._attributeRefs ? this._attributeRefs : this._assetIds;
106
- if (!this._subscriptionIds || !Util.objectsEqual(ids, currentIds)) {
107
- eventProviderFactory.getEventProvider().unsubscribe(subscriptionId);
108
- return;
109
- }
110
- this._subscriptionIds.push(subscriptionId);
111
- }
112
- });
113
- }
114
- _removeEventSubscriptions() {
115
- if (!this._subscriptionIds) {
116
- return;
117
- }
118
- this._subscriptionIds.forEach((subscriptionId) => {
119
- eventProviderFactory.getEventProvider().unsubscribe(subscriptionId);
120
- });
121
- this._subscriptionIds = undefined;
122
- }
123
- _refreshEventSubscriptions() {
124
- this._removeEventSubscriptions();
125
- this._addEventSubscriptions();
126
- }
127
- set assetIds(assetIds) {
128
- if (objectsEqual(this._assetIds, assetIds)) {
129
- return;
130
- }
131
- this._assetIds = assetIds;
132
- this._refreshEventSubscriptions();
133
- this.requestUpdate("assetIds");
134
- }
135
- get assetIds() {
136
- return this._assetIds;
137
- }
138
- set attributeRefs(attributes) {
139
- if (objectsEqual(this._attributeRefs, attributes)) {
140
- return;
141
- }
142
- this._attributeRefs = attributes;
143
- this._refreshEventSubscriptions();
144
- }
145
- get attributeRefs() {
146
- return this._attributeRefs;
147
- }
148
- _sendEvent(event) {
149
- eventProviderFactory.getEventProvider().sendEvent(event);
150
- }
151
- _sendEventWithReply(event) {
152
- return eventProviderFactory.getEventProvider().sendEventWithReply(event);
153
- }
154
- // noinspection JSUnusedLocalSymbols
155
- onEventsConnect() { }
156
- // noinspection JSUnusedLocalSymbols
157
- onEventsDisconnect() { }
158
- // noinspection JSUnusedLocalSymbols
159
- _onEvent(event) { }
160
- };
161
- //# sourceMappingURL=asset-mixin.js.map
1
+ var __awaiter=this&&this.__awaiter||function(t,e,s,n){return new(s||(s=Promise))(function(i,r){function o(t){try{u(n.next(t))}catch(t){r(t)}}function c(t){try{u(n.throw(t))}catch(t){r(t)}}function u(t){var e;t.done?i(t.value):((e=t.value)instanceof s?e:new s(function(t){t(e)})).then(o,c)}u((n=n.apply(t,e||[])).next())})};import{EventProviderStatus as t}from"./event";import{objectsEqual as e}from"./util";import{Util as s}from".";export const subscribe=n=>i=>class extends i{constructor(){super(...arguments),this._connectRequested=!1,this._status=t.DISCONNECTED,this._statusCallback=t=>this._onEventProviderStatusChanged(t)}connectedCallback(){super.connectedCallback&&super.connectedCallback(),this.connectEvents()}disconnectedCallback(){this.disconnectEvents(),super.disconnectedCallback&&super.disconnectedCallback()}connectEvents(){if(!n.getEventProvider())return void console.log("No event provider available so cannot subscribe");this._connectRequested||(this._connectRequested=!0,n.getEventProvider().subscribeStatusChange(this._statusCallback),this._doConnect())}disconnectEvents(){this._connectRequested&&(this._connectRequested=!1,n.getEventProvider().unsubscribeStatusChange(this._statusCallback),this._onEventsDisconnect())}_doConnect(){return __awaiter(this,void 0,void 0,function*(){this.eventsConnected&&this._onEventsConnect()})}get eventsConnected(){return this._connectRequested&&n.getEventProvider().status===t.CONNECTED}_onEventProviderStatusChanged(e){switch(e){case t.DISCONNECTED:this._onEventsDisconnect();break;case t.CONNECTED:this._doConnect()}}_onEventsConnect(){this._addEventSubscriptions(),this.onEventsConnect()}_onEventsDisconnect(){this._removeEventSubscriptions(),this.onEventsDisconnect()}_addEventSubscriptions(){return __awaiter(this,void 0,void 0,function*(){let t=!!this._attributeRefs,e=!!this._assetIds,i=this._attributeRefs?this._attributeRefs:this._assetIds;if(i&&i.length>0){if(this._subscriptionIds=[],e){let t=yield n.getEventProvider().subscribeAssetEvents(i,!0,t=>this._onEvent(t)),e=this._attributeRefs?this._attributeRefs:this._assetIds;if(!this._subscriptionIds||!s.objectsEqual(i,e))return void n.getEventProvider().unsubscribe(t);this._subscriptionIds.push(t)}let r=yield n.getEventProvider().subscribeAttributeEvents(i,t,t=>this._onEvent(t)),o=this._attributeRefs?this._attributeRefs:this._assetIds;if(!this._subscriptionIds||!s.objectsEqual(i,o))return void n.getEventProvider().unsubscribe(r);this._subscriptionIds.push(r)}})}_removeEventSubscriptions(){this._subscriptionIds&&(this._subscriptionIds.forEach(t=>{n.getEventProvider().unsubscribe(t)}),this._subscriptionIds=void 0)}_refreshEventSubscriptions(){this._removeEventSubscriptions(),this._addEventSubscriptions()}set assetIds(t){e(this._assetIds,t)||(this._assetIds=t,this._refreshEventSubscriptions(),this.requestUpdate("assetIds"))}get assetIds(){return this._assetIds}set attributeRefs(t){e(this._attributeRefs,t)||(this._attributeRefs=t,this._refreshEventSubscriptions())}get attributeRefs(){return this._attributeRefs}_sendEvent(t){n.getEventProvider().sendEvent(t)}_sendEventWithReply(t){return n.getEventProvider().sendEventWithReply(t)}onEventsConnect(){}onEventsDisconnect(){}_onEvent(t){}};