@operato/scene-mqtt 10.0.0-beta.2 → 10.0.0-beta.31

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.
package/README.md CHANGED
@@ -1,120 +1,33 @@
1
- # MQTT data source component for Things Scene
1
+ # @operato/scene-mqtt
2
2
 
3
- ## Concept
3
+ > MQTT integration component for things-scene
4
4
 
5
- - Subscribe the topic via MQTT Web Socket protocol.
6
- - Data Spread is set in data binding.
5
+ <!-- AUTOGEN_BEGIN: do not edit between markers (run scripts/regenerate-readmes.mjs to update) -->
7
6
 
8
- ## Creating a Development Environment (Based on MacOS)
7
+ ## Components
9
8
 
10
- ### Installing mosquitto as MQTT broker
9
+ - `Mqtt`
11
10
 
12
- - Use homebrew to install mosquitto.
11
+ ## Install
13
12
 
13
+ ```bash
14
+ yarn add @operato/scene-mqtt
14
15
  ```
15
- $ brew install mosquitto
16
- ```
17
-
18
- - Since Things Scene is for the browser, it must be accessible to MQTT broker via a web socket. So, enable the web service function on mosquitto.
19
-
20
- ```
21
- $ echo -e "listener 1884\nprotocol websockets\nlistener 1883\nprotocol mqtt" >> /usr/local/opt/mosquitto/etc/mosquitto/mosquitto.conf
22
- $ brew services restart mosquitto
23
- ```
24
-
25
- ## Setting
26
-
27
- ### When use mosquitto as MQTT Broker
28
16
 
29
- - broker : hostname of the broker
30
- - port : websocket service port number (default 1884)
31
- - path : '/mqtt'
32
- - user : username or blank
33
- - password : password or blank
34
- - topic : topic
35
- - qos : QOS level [0, 1, 2]
36
- - client-id : (unique) client id
17
+ ## Usage
37
18
 
19
+ ```ts
20
+ import { Mqtt } from '@operato/scene-mqtt'
38
21
  ```
39
- The client ID is the name of the only connection node (from the broker's point of view) and is unique for monitoring by the broker.
40
- If leave the client ID property blank, it will be automatically created as 'THINGS-BOARD-{timestamp}'.
41
- If enter the client ID property, it will be automatically created as '{{client-id}}-{timestamp}'.
42
- The reason for adding timestamp to the client ID property is to create a unique ID.
43
- ```
44
-
45
- - data-format : [Plain Text, JSON]
46
- - retain : true or false
47
- - ssl : true or false (false)
48
22
 
49
- ### When use MQTT-Websocket Plug-in of RabbitMQ
23
+ ## Build
50
24
 
51
- - broker : hostname of the broker
52
- - port : websocket service port number (default 15675)
53
- - path : '/ws'
54
- - user : username or blank
55
- - password : password or blank
56
- - topic : topic
57
- - qos : QOS level [0, 1, 2]
58
- - client-id : (unique) client id
59
-
60
- ```
61
- The client ID is the name of the only connection node (from the broker's point of view) and is unique for monitoring by the broker.
62
- If leave the client ID property blank, it will be automatically created as 'THINGS-BOARD-{timestamp}'.
63
- If enter the client ID property, it will be automatically created as '{{client-id}}-{timestamp}'.
64
- The reason for adding timestamp to the client ID property is to create a unique ID.
25
+ ```bash
26
+ yarn build
65
27
  ```
66
28
 
67
- - data-format : [Plain Text, JSON]
68
- - retain : true or false
69
- - ssl : true or false (false)
70
-
71
- ## Message Exchange when use MQTT-Websocket Plug-in of Rabbit MQ
72
-
73
- ```
74
- If use MQTT-Websocket Plug-in of Rabbit MQ,
75
- it is routed by 'amq.topic' exchange of durable 'topic' type.
76
- Therefore, the topic property of the above MQTT Data Source acts as a routing key.
77
-
78
- To receive from MQTT Data Source using AMQP of Rabbit MQ,
79
- see the JavaScript sample code below.
80
- ```
81
-
82
- ```
83
- var amqp = require('amqplib/callback_api');
84
-
85
- amqp.connect('amqp://hatiolab:hatiolab@mq.hatiolab.com', function(err, conn) {
86
- if(err) {
87
- console.error(err);
88
- return;
89
- }
90
-
91
- conn.createChannel(function (err, ch) {
92
- // Set exchange to amq.topic and durable option to true.
93
- var ex = 'amq.topic';
94
-
95
- ch.assertExchange(ex, 'topic', { durable: true });
96
-
97
- var location = {
98
- x: 100,
99
- y: 200
100
- };
101
-
102
- // When set the topic property to location
103
- ch.publish(ex, 'location', new Buffer(JSON.stringify(location)));
104
- });
105
- });
106
- ```
107
-
108
- ## build
109
-
110
- `$ yarn build`
111
-
112
- | type | filename | for | tested |
113
- | ---- | ----------------------- | -------------- | ------ |
114
- | UMD | things-scene-mqtt.js | modern browser | X |
115
- | UMD | things-scene-mqtt-ie.js | ie 11 | O |
116
- | ESM | things-scene-mqtt.mjs | modern browser | X |
29
+ Output: ESM module at `dist/index.js` (single bundle, no UMD/IE legacy).
117
30
 
118
- ## publish
31
+ _Version: 10.0.0-beta.2_
119
32
 
120
- `$ yarn publish`
33
+ <!-- AUTOGEN_END -->
package/dist/mqtt.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Component, ComponentNature, Properties, Shape } from '@hatiolab/things-scene';
1
+ import { ComponentNature, Properties, Shape } from '@hatiolab/things-scene';
2
2
  declare const Mqtt_base: (new (...args: any[]) => {
3
3
  _convertDataFormat(data: any, format: any): any;
4
4
  isDataSource(): boolean;
@@ -32,7 +32,7 @@ declare const Mqtt_base: (new (...args: any[]) => {
32
32
  get disposed(): boolean;
33
33
  isLayer(): boolean;
34
34
  isGroup(): boolean;
35
- isContainer(): this is import("@hatiolab/things-scene/dist-types/types/component").Container;
35
+ isContainer(): this is import("@hatiolab/things-scene").Container;
36
36
  isLine(): boolean;
37
37
  isRoot(): boolean;
38
38
  isRootModel(): boolean;
@@ -48,9 +48,9 @@ declare const Mqtt_base: (new (...args: any[]) => {
48
48
  get(property: any): any;
49
49
  set(props: any, propval?: any): any;
50
50
  getState(property: any): any;
51
- setState(props: any, propval?: any): any;
51
+ setState(props: Partial<import("@hatiolab/things-scene").State> | string, propval?: any): any;
52
52
  get model(): any;
53
- get state(): any;
53
+ get state(): import("@hatiolab/things-scene").State;
54
54
  get hierarchy(): any;
55
55
  get volatile(): never[];
56
56
  _applyProps(target: any, props: any, options: any): any;
@@ -92,7 +92,7 @@ declare const Mqtt_base: (new (...args: any[]) => {
92
92
  prerender(context: import("@hatiolab/things-scene").SceneRenderContext): void;
93
93
  render(context: import("@hatiolab/things-scene").SceneRenderContext): void;
94
94
  postrender(context: import("@hatiolab/things-scene").SceneRenderContext): void;
95
- prepare(resolve: (component: Component) => void, reject: (reason: any) => void): void;
95
+ prepare(resolve: (component: import("@hatiolab/things-scene").Component) => void, reject: (reason: any) => void): void;
96
96
  prepareIf(condition: boolean): void;
97
97
  drawText(context: import("@hatiolab/things-scene").SceneRenderContext): void;
98
98
  drawStroke(context: import("@hatiolab/things-scene").SceneRenderContext, override?: Record<string, unknown>): void;
@@ -143,16 +143,16 @@ declare const Mqtt_base: (new (...args: any[]) => {
143
143
  get started(): boolean;
144
144
  set started(v: boolean): any;
145
145
  get controls(): import("@hatiolab/things-scene").Control[] | undefined;
146
- findFirst(finder: string | ((c: Component) => boolean), ...others: any[]): Component | undefined;
147
- findAll(s: string | ((c: Component) => boolean), ...others: any[]): any[] | undefined;
148
- capture(x: number, y: number, except?: (c: Component) => boolean): any;
146
+ findFirst(finder: string | ((c: import("@hatiolab/things-scene").Component) => boolean), ...others: any[]): import("@hatiolab/things-scene").Component | undefined;
147
+ findAll(s: string | ((c: import("@hatiolab/things-scene").Component) => boolean), ...others: any[]): any[] | undefined;
148
+ capture(x: number, y: number, except?: (c: import("@hatiolab/things-scene").Component) => boolean): any;
149
149
  findAnchor(name: string): any;
150
- isDescendible(container: Component): boolean;
150
+ isDescendible(container: import("@hatiolab/things-scene").Component | any): boolean;
151
151
  getContext(component?: unknown): any;
152
- get root(): Component;
153
- get rootModel(): Component;
154
- get parent(): Component;
155
- set parent(v: Component): any;
152
+ get root(): import("@hatiolab/things-scene").Component;
153
+ get rootModel(): import("@hatiolab/things-scene").Component;
154
+ get parent(): import("@hatiolab/things-scene").Component;
155
+ set parent(v: import("@hatiolab/things-scene").Component): any;
156
156
  get anchors(): import("@hatiolab/things-scene").Anchor[];
157
157
  get scalable(): boolean;
158
158
  get stuck(): boolean;
@@ -178,47 +178,51 @@ declare const Mqtt_base: (new (...args: any[]) => {
178
178
  ondropfile(transfered: FileList, files: string[]): void;
179
179
  transcoordS2P(x: number, y: number, rp?: import("@hatiolab/things-scene").POINT): import("@hatiolab/things-scene").POINT;
180
180
  transcoordP2S(x: number, y: number, rp?: import("@hatiolab/things-scene").POINT): import("@hatiolab/things-scene").POINT;
181
- transcoordS2T(x: number, y: number, top?: Component): import("@hatiolab/things-scene").POINT;
182
- transcoordT2P(x: number, y: number, top?: Component): import("@hatiolab/things-scene").POINT;
183
- transcoordT2S(x: number, y: number, top?: Component): import("@hatiolab/things-scene").POINT;
184
- transcoordS2TR(x: number, y: number, top?: Component): import("@hatiolab/things-scene").POINT;
185
- transcoordS2O(x: number, y: number, target: Component): import("@hatiolab/things-scene").POINT;
186
- transcoordC2S(x: number, y: number, top?: Component): import("@hatiolab/things-scene").POINT;
187
- transcoordS2C(x: number, y: number, top?: Component): import("@hatiolab/things-scene").POINT;
181
+ transcoordS2T(x: number, y: number, top?: import("@hatiolab/things-scene").Component): import("@hatiolab/things-scene").POINT;
182
+ transcoordT2P(x: number, y: number, top?: import("@hatiolab/things-scene").Component): import("@hatiolab/things-scene").POINT;
183
+ transcoordT2S(x: number, y: number, top?: import("@hatiolab/things-scene").Component): import("@hatiolab/things-scene").POINT;
184
+ transcoordS2TR(x: number, y: number, top?: import("@hatiolab/things-scene").Component): import("@hatiolab/things-scene").POINT;
185
+ transcoordS2O(x: number, y: number, target: import("@hatiolab/things-scene").Component): import("@hatiolab/things-scene").POINT;
186
+ transcoordC2S(x: number, y: number, top?: import("@hatiolab/things-scene").Component): import("@hatiolab/things-scene").POINT;
187
+ transcoordS2C(x: number, y: number, top?: import("@hatiolab/things-scene").Component): import("@hatiolab/things-scene").POINT;
188
188
  toParent(x: number, y: number, rp?: import("@hatiolab/things-scene").POINT): import("@hatiolab/things-scene").POINT;
189
189
  fromParent(x: number, y: number, rp?: import("@hatiolab/things-scene").POINT): import("@hatiolab/things-scene").POINT;
190
- toScene(x: number, y: number, top?: Component): import("@hatiolab/things-scene").POINT;
191
- fromScene(x: number, y: number, top?: Component): import("@hatiolab/things-scene").POINT;
192
- toLocal(x: number, y: number, top?: Component): import("@hatiolab/things-scene").POINT;
193
- toGlobal(x: number, y: number, top?: Component): import("@hatiolab/things-scene").POINT;
194
- toOther(x: number, y: number, target: Component): import("@hatiolab/things-scene").POINT;
190
+ toScene(x: number, y: number, top?: import("@hatiolab/things-scene").Component): import("@hatiolab/things-scene").POINT;
191
+ fromScene(x: number, y: number, top?: import("@hatiolab/things-scene").Component): import("@hatiolab/things-scene").POINT;
192
+ toLocal(x: number, y: number, top?: import("@hatiolab/things-scene").Component): import("@hatiolab/things-scene").POINT;
193
+ toGlobal(x: number, y: number, top?: import("@hatiolab/things-scene").Component): import("@hatiolab/things-scene").POINT;
194
+ toOther(x: number, y: number, target: import("@hatiolab/things-scene").Component): import("@hatiolab/things-scene").POINT;
195
+ on<K extends keyof import("@hatiolab/things-scene").ComponentEventMap>(name: K, callback: (...args: import("@hatiolab/things-scene").ComponentEventMap[K]) => void, context?: any): any;
195
196
  on(name: string | object, callback: Function, context?: any): any;
197
+ off<K extends keyof import("@hatiolab/things-scene").ComponentEventMap>(name: K, callback?: ((...args: import("@hatiolab/things-scene").ComponentEventMap[K]) => void) | undefined, context?: any): any;
196
198
  off(name?: string | object, callback?: Function, context?: any): any;
199
+ once<K extends keyof import("@hatiolab/things-scene").ComponentEventMap>(name: K, callback: (...args: import("@hatiolab/things-scene").ComponentEventMap[K]) => void, context?: any): any;
197
200
  once(name: string | object, callback: Function, context?: any): any;
201
+ trigger<K extends keyof import("@hatiolab/things-scene").ComponentEventMap>(name: K, ...args: import("@hatiolab/things-scene").ComponentEventMap[K]): any;
198
202
  trigger(name: string, ...args: any[]): any;
199
203
  delegate_on(delegator: any): any;
200
204
  delegate_off(delegator: any): any;
201
205
  onchange(after: Record<string, any>, before: Record<string, any>): void;
202
206
  calculateBounds?(): void;
203
207
  oncreate_element?(element: HTMLElement): void;
204
- removeComponent(component: Component, ghost?: boolean): void;
205
- addComponent(component: Component, ghost?: boolean): void;
206
- insertComponentAt(component: Component, index: number, ghost?: boolean): void;
207
- getOverlay(component: Component): HTMLElement | undefined;
208
- findById(id: string): Component | undefined;
209
- findByRefid(ref: string | number): Component | undefined;
210
- findAllById(id: string): Component[];
208
+ removeComponent(component: import("@hatiolab/things-scene").Component, ghost?: boolean): void;
209
+ addComponent(component: import("@hatiolab/things-scene").Component, ghost?: boolean): void;
210
+ insertComponentAt(component: import("@hatiolab/things-scene").Component, index: number, ghost?: boolean): void;
211
+ getOverlay(component: import("@hatiolab/things-scene").Component): HTMLElement | undefined;
212
+ findById(id: string): import("@hatiolab/things-scene").Component | undefined;
213
+ findByRefid(ref: string | number): import("@hatiolab/things-scene").Component | undefined;
214
+ findAllById(id: string): import("@hatiolab/things-scene").Component[];
211
215
  resize(): void;
212
216
  fit(type?: string): void;
213
- get components(): Component[] | undefined;
217
+ get components(): import("@hatiolab/things-scene").Component[] | undefined;
214
218
  get layout(): any;
215
219
  get auxOverlay(): HTMLElement | undefined;
216
220
  get isReady(): boolean;
217
221
  get unitScale(): number;
218
- get selected(): Component[];
219
- set selected(_v: Component[]): any;
220
- get focused(): Component | null;
221
- set focused(_v: Component | null): any;
222
+ get selected(): import("@hatiolab/things-scene").Component[];
223
+ set selected(_v: import("@hatiolab/things-scene").Component[]): any;
224
+ get focused(): import("@hatiolab/things-scene").Component | null;
225
+ set focused(_v: import("@hatiolab/things-scene").Component | null): any;
222
226
  get hasSameParentForAllSelected(): boolean;
223
227
  set hasSameParentForAllSelected(_v: boolean): any;
224
228
  get fitMode(): string | undefined;
@@ -275,7 +279,7 @@ declare const Mqtt_base: (new (...args: any[]) => {
275
279
  get disposed(): boolean;
276
280
  isLayer(): boolean;
277
281
  isGroup(): boolean;
278
- isContainer(): this is import("@hatiolab/things-scene/dist-types/types/component").Container;
282
+ isContainer(): this is import("@hatiolab/things-scene").Container;
279
283
  isLine(): boolean;
280
284
  isRoot(): boolean;
281
285
  isRootModel(): boolean;
@@ -291,9 +295,9 @@ declare const Mqtt_base: (new (...args: any[]) => {
291
295
  get(property: any): any;
292
296
  set(props: any, propval?: any): any;
293
297
  getState(property: any): any;
294
- setState(props: any, propval?: any): any;
298
+ setState(props: Partial<import("@hatiolab/things-scene").State> | string, propval?: any): any;
295
299
  get model(): any;
296
- get state(): any;
300
+ get state(): import("@hatiolab/things-scene").State;
297
301
  get hierarchy(): any;
298
302
  get volatile(): never[];
299
303
  _applyProps(target: any, props: any, options: any): any;
@@ -329,7 +333,7 @@ declare const Mqtt_base: (new (...args: any[]) => {
329
333
  draw(context?: import("@hatiolab/things-scene").SceneRenderContext): void;
330
334
  prerender(context: import("@hatiolab/things-scene").SceneRenderContext): void;
331
335
  postrender(context: import("@hatiolab/things-scene").SceneRenderContext): void;
332
- prepare(resolve: (component: Component) => void, reject: (reason: any) => void): void;
336
+ prepare(resolve: (component: import("@hatiolab/things-scene").Component) => void, reject: (reason: any) => void): void;
333
337
  prepareIf(condition: boolean): void;
334
338
  drawText(context: import("@hatiolab/things-scene").SceneRenderContext): void;
335
339
  drawStroke(context: import("@hatiolab/things-scene").SceneRenderContext, override?: Record<string, unknown>): void;
@@ -380,16 +384,16 @@ declare const Mqtt_base: (new (...args: any[]) => {
380
384
  get started(): boolean;
381
385
  set started(v: boolean): any;
382
386
  get controls(): import("@hatiolab/things-scene").Control[] | undefined;
383
- findFirst(finder: string | ((c: Component) => boolean), ...others: any[]): Component | undefined;
384
- findAll(s: string | ((c: Component) => boolean), ...others: any[]): any[] | undefined;
385
- capture(x: number, y: number, except?: (c: Component) => boolean): any;
387
+ findFirst(finder: string | ((c: import("@hatiolab/things-scene").Component) => boolean), ...others: any[]): import("@hatiolab/things-scene").Component | undefined;
388
+ findAll(s: string | ((c: import("@hatiolab/things-scene").Component) => boolean), ...others: any[]): any[] | undefined;
389
+ capture(x: number, y: number, except?: (c: import("@hatiolab/things-scene").Component) => boolean): any;
386
390
  findAnchor(name: string): any;
387
- isDescendible(container: Component): boolean;
391
+ isDescendible(container: import("@hatiolab/things-scene").Component | any): boolean;
388
392
  getContext(component?: unknown): any;
389
- get root(): Component;
390
- get rootModel(): Component;
391
- get parent(): Component;
392
- set parent(v: Component): any;
393
+ get root(): import("@hatiolab/things-scene").Component;
394
+ get rootModel(): import("@hatiolab/things-scene").Component;
395
+ get parent(): import("@hatiolab/things-scene").Component;
396
+ set parent(v: import("@hatiolab/things-scene").Component): any;
393
397
  get scalable(): boolean;
394
398
  get stuck(): boolean;
395
399
  get capturable(): boolean;
@@ -414,47 +418,51 @@ declare const Mqtt_base: (new (...args: any[]) => {
414
418
  ondropfile(transfered: FileList, files: string[]): void;
415
419
  transcoordS2P(x: number, y: number, rp?: import("@hatiolab/things-scene").POINT): import("@hatiolab/things-scene").POINT;
416
420
  transcoordP2S(x: number, y: number, rp?: import("@hatiolab/things-scene").POINT): import("@hatiolab/things-scene").POINT;
417
- transcoordS2T(x: number, y: number, top?: Component): import("@hatiolab/things-scene").POINT;
418
- transcoordT2P(x: number, y: number, top?: Component): import("@hatiolab/things-scene").POINT;
419
- transcoordT2S(x: number, y: number, top?: Component): import("@hatiolab/things-scene").POINT;
420
- transcoordS2TR(x: number, y: number, top?: Component): import("@hatiolab/things-scene").POINT;
421
- transcoordS2O(x: number, y: number, target: Component): import("@hatiolab/things-scene").POINT;
422
- transcoordC2S(x: number, y: number, top?: Component): import("@hatiolab/things-scene").POINT;
423
- transcoordS2C(x: number, y: number, top?: Component): import("@hatiolab/things-scene").POINT;
421
+ transcoordS2T(x: number, y: number, top?: import("@hatiolab/things-scene").Component): import("@hatiolab/things-scene").POINT;
422
+ transcoordT2P(x: number, y: number, top?: import("@hatiolab/things-scene").Component): import("@hatiolab/things-scene").POINT;
423
+ transcoordT2S(x: number, y: number, top?: import("@hatiolab/things-scene").Component): import("@hatiolab/things-scene").POINT;
424
+ transcoordS2TR(x: number, y: number, top?: import("@hatiolab/things-scene").Component): import("@hatiolab/things-scene").POINT;
425
+ transcoordS2O(x: number, y: number, target: import("@hatiolab/things-scene").Component): import("@hatiolab/things-scene").POINT;
426
+ transcoordC2S(x: number, y: number, top?: import("@hatiolab/things-scene").Component): import("@hatiolab/things-scene").POINT;
427
+ transcoordS2C(x: number, y: number, top?: import("@hatiolab/things-scene").Component): import("@hatiolab/things-scene").POINT;
424
428
  toParent(x: number, y: number, rp?: import("@hatiolab/things-scene").POINT): import("@hatiolab/things-scene").POINT;
425
429
  fromParent(x: number, y: number, rp?: import("@hatiolab/things-scene").POINT): import("@hatiolab/things-scene").POINT;
426
- toScene(x: number, y: number, top?: Component): import("@hatiolab/things-scene").POINT;
427
- fromScene(x: number, y: number, top?: Component): import("@hatiolab/things-scene").POINT;
428
- toLocal(x: number, y: number, top?: Component): import("@hatiolab/things-scene").POINT;
429
- toGlobal(x: number, y: number, top?: Component): import("@hatiolab/things-scene").POINT;
430
- toOther(x: number, y: number, target: Component): import("@hatiolab/things-scene").POINT;
430
+ toScene(x: number, y: number, top?: import("@hatiolab/things-scene").Component): import("@hatiolab/things-scene").POINT;
431
+ fromScene(x: number, y: number, top?: import("@hatiolab/things-scene").Component): import("@hatiolab/things-scene").POINT;
432
+ toLocal(x: number, y: number, top?: import("@hatiolab/things-scene").Component): import("@hatiolab/things-scene").POINT;
433
+ toGlobal(x: number, y: number, top?: import("@hatiolab/things-scene").Component): import("@hatiolab/things-scene").POINT;
434
+ toOther(x: number, y: number, target: import("@hatiolab/things-scene").Component): import("@hatiolab/things-scene").POINT;
435
+ on<K extends keyof import("@hatiolab/things-scene").ComponentEventMap>(name: K, callback: (...args: import("@hatiolab/things-scene").ComponentEventMap[K]) => void, context?: any): any;
431
436
  on(name: string | object, callback: Function, context?: any): any;
437
+ off<K extends keyof import("@hatiolab/things-scene").ComponentEventMap>(name: K, callback?: ((...args: import("@hatiolab/things-scene").ComponentEventMap[K]) => void) | undefined, context?: any): any;
432
438
  off(name?: string | object, callback?: Function, context?: any): any;
439
+ once<K extends keyof import("@hatiolab/things-scene").ComponentEventMap>(name: K, callback: (...args: import("@hatiolab/things-scene").ComponentEventMap[K]) => void, context?: any): any;
433
440
  once(name: string | object, callback: Function, context?: any): any;
441
+ trigger<K extends keyof import("@hatiolab/things-scene").ComponentEventMap>(name: K, ...args: import("@hatiolab/things-scene").ComponentEventMap[K]): any;
434
442
  trigger(name: string, ...args: any[]): any;
435
443
  delegate_on(delegator: any): any;
436
444
  delegate_off(delegator: any): any;
437
445
  onchange(after: Record<string, any>, before: Record<string, any>): void;
438
446
  calculateBounds?(): void;
439
447
  oncreate_element?(element: HTMLElement): void;
440
- removeComponent(component: Component, ghost?: boolean): void;
441
- addComponent(component: Component, ghost?: boolean): void;
442
- insertComponentAt(component: Component, index: number, ghost?: boolean): void;
443
- getOverlay(component: Component): HTMLElement | undefined;
444
- findById(id: string): Component | undefined;
445
- findByRefid(ref: string | number): Component | undefined;
446
- findAllById(id: string): Component[];
448
+ removeComponent(component: import("@hatiolab/things-scene").Component, ghost?: boolean): void;
449
+ addComponent(component: import("@hatiolab/things-scene").Component, ghost?: boolean): void;
450
+ insertComponentAt(component: import("@hatiolab/things-scene").Component, index: number, ghost?: boolean): void;
451
+ getOverlay(component: import("@hatiolab/things-scene").Component): HTMLElement | undefined;
452
+ findById(id: string): import("@hatiolab/things-scene").Component | undefined;
453
+ findByRefid(ref: string | number): import("@hatiolab/things-scene").Component | undefined;
454
+ findAllById(id: string): import("@hatiolab/things-scene").Component[];
447
455
  resize(): void;
448
456
  fit(type?: string): void;
449
- get components(): Component[] | undefined;
457
+ get components(): import("@hatiolab/things-scene").Component[] | undefined;
450
458
  get layout(): any;
451
459
  get auxOverlay(): HTMLElement | undefined;
452
460
  get isReady(): boolean;
453
461
  get unitScale(): number;
454
- get selected(): Component[];
455
- set selected(_v: Component[]): any;
456
- get focused(): Component | null;
457
- set focused(_v: Component | null): any;
462
+ get selected(): import("@hatiolab/things-scene").Component[];
463
+ set selected(_v: import("@hatiolab/things-scene").Component[]): any;
464
+ get focused(): import("@hatiolab/things-scene").Component | null;
465
+ set focused(_v: import("@hatiolab/things-scene").Component | null): any;
458
466
  get hasSameParentForAllSelected(): boolean;
459
467
  set hasSameParentForAllSelected(_v: boolean): any;
460
468
  get fitMode(): string | undefined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,EAAE,GAAG,IAAI,CAAC,MAAM,CAAA;QAE9C,OAAO,CAAC,SAAS,EAAE,CAAA;QACnB,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,MAAI,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;IAC/D,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;IACjC,CAAC;IAED,IAAI,OAAO,CAAC,OAAO;QACjB,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;IACnC,CAAC;IAED,QAAQ,CAAC,KAAiB,EAAE,MAAkB;QAC5C,IAAI,SAAS,IAAI,KAAK,EAAE,CAAC;YACvB,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAA;YAEzB,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;gBAC7C,OAAM;YACR,CAAC;YAED,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAA;YAE1B,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE;gBACnD,GAAG,EAAE,CAAC;gBACN,MAAM,EAAE,KAAK;aACd,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,IAAI,MAAM;QACR,OAAO,MAAM,CAAA;IACf,CAAC;CACF,CAAA;AAtJoB,IAAI;IADxB,cAAc,CAAC,MAAM,CAAC;GACF,IAAI,CAsJxB;eAtJoB,IAAI","sourcesContent":["import mqtt from 'mqtt'\n\n/*\n * Copyright © HatioLab Inc. All rights reserved.\n */\nimport {\n Component,\n ComponentNature,\n DataSource,\n Properties,\n RectPath,\n Shape,\n sceneComponent\n} from '@hatiolab/things-scene'\n\nconst NATURE: ComponentNature = {\n mutable: false,\n resizable: true,\n rotatable: true,\n properties: [\n {\n type: 'string',\n label: 'broker',\n name: 'broker',\n placeholder: 'WebSocket hostname'\n },\n {\n type: 'number',\n label: 'port',\n name: 'port',\n placeholder: '15675'\n },\n {\n type: 'string',\n label: 'path',\n name: 'path',\n placeholder: '/mqtt or /ws'\n },\n {\n type: 'string',\n label: 'user',\n name: 'user'\n },\n {\n type: 'string',\n label: 'password',\n name: 'password',\n property: 'password'\n },\n {\n type: 'string',\n label: 'topic',\n name: 'topic'\n },\n {\n type: 'number',\n label: 'qos',\n name: 'qos',\n placeholder: '0..2'\n },\n {\n type: 'string',\n label: 'client-id',\n name: 'clientId'\n },\n {\n type: 'select',\n label: 'data-format',\n name: 'dataFormat',\n property: {\n options: [\n {\n display: 'Plain Text',\n value: 'text'\n },\n {\n display: 'JSON',\n value: 'json'\n }\n ]\n }\n },\n {\n type: 'checkbox',\n label: 'retain',\n name: 'retain'\n },\n {\n type: 'checkbox',\n label: 'ssl',\n name: 'ssl'\n }\n ],\n 'value-property': 'message',\n help: 'scene/component/mqtt'\n}\n\nconst MQTT_IMAGE =\n 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAK0AAACpCAMAAABu4E1nAAAAulBMVEVHcEzh1uvj1+3f2ezk2Ozk1u3h2Ozh4Ovl5O7g0O/j1e3i1uvl1+zDwdy2tNe+vNvGxN6yr9TIxt+8udnMyuHV1OavrNOopdDPzeO6t9iBfq7KyOCsqdK0sdXEwt3BvtvS0OSDMIekoM24tteKPo9wCHJ6Hn1/KYPZ2OiHN4t3F3mTUJh9I4CXV52QSpXd3Ol0EHaNRJKbX6GrfbKmdK2eZaWia6mLiLaVkr2xibmdmsS7nsbGsdLj1+x6ayFYAAAADXRSTlMA72knP6XI/v4Qg+JLWzYOpwAAD0xJREFUeF5iwAE4BxIwEA9YuFjZGG0HGDCysTIxE3YqK6PtoAHcXHgdzMNmO8gAKwsDDsDMZjsIASv2VMwEVwBgzVyX3bShKNxbgpPUF8AcsIxtKs/0uNNM+ReppH3/1yq6wELet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KC7puyoDcfeW3zL2tCtjp8hwtc5o3SHyRtwTd6O53F3Q3gbcgU5LYNQ0ZROS6m4QhRzyuwfnl6r7prsAnuYuYMF7oNMS2M00Pc/U2m6LDO8Qib0RcV3CLd1VGai7eXU7OvWF3cwKriDXDucSih0T/Z3HBbErq1v+uHN3tbrXdFrC72bP2ZhNpe2KtgtkYkcVgJp3Bt2DARt4u1nuDmxIDbuZtVrd8cN5C0o8QAAVjAu42hlQ3Lfc7Wa469hwxxZHXE0tHW8MqxQ9vwjFTbiZDCOb2nR3H+n0qm8KvxOtrTSGVkQAbXMp5kZcV25qWO90954OqeFAnmaYKtUVaz81oA3mrp3KUOkMs9y9FoJaH8NgQ8omrFTXgvBCaGOu/1DiFm33Pe4u2fQqRnI0cHes7ZpYWtCmlz76iDu6q813t7cEV55z2BfVLSPIWsH7nGibrwXuR91NuAc2bPsj0mp1T9tum79Rs9AXalQG7bvgVdiZ7j6x0ADfcJ/3iqvqKq4RtMtGaaEu1s8+4EZ1VYaZfTfh3oEAK7lYNoZfvuGWgbupujo4AGmVNntZaah0hjnuBtodCw3A9rAvcs5tq9U1Cqu0KoPn7cFb6QzM3bwxgKAWGnDlaU0euJufdo2NSF+aE9rm4vVVuNXQ973TpTJHoQtBimOwfkhnQDEWXg7o4/EI2tIGY+3LbOGAiwGLaxmYWW0HIeBmZoADBgbmQX2THSPLkLkl0JaNiGsNmQbvDYwAiZJSuDJ1+dQAAAAASUVORK5CYII='\n\n@sceneComponent('mqtt')\nexport default class Mqtt extends DataSource(RectPath(Shape)) {\n private static _image: HTMLImageElement\n\n private _client?: mqtt.MqttClient\n\n static get image() {\n if (!Mqtt._image) {\n Mqtt._image = new Image()\n Mqtt._image.src = MQTT_IMAGE\n }\n\n return Mqtt._image\n }\n\n async ready() {\n await super.ready()\n\n if (!this.app.isViewMode) return\n\n this._initMqttConnection()\n }\n\n _initMqttConnection() {\n try {\n this._client && this._client.end(true, () => {})\n } catch (e) {\n console.error(e)\n }\n delete this._client\n\n var {\n broker,\n port = 8441,\n clientId = 'THINGS-FACTORY',\n topic,\n qos = 1,\n retain = false,\n path = '/mqtt',\n dataFormat = 'text',\n user,\n password,\n ssl = false\n } = this.state\n\n if (!broker) {\n console.warn('broker not defined')\n return\n }\n\n clientId = [clientId, Date.now()].join('-')\n\n var client = mqtt.connect(`ws://${broker}:${port}${path}`, {\n keepalive: 10,\n clientId,\n protocolId: 'MQTT',\n protocolVersion: 4,\n clean: true,\n reconnectPeriod: 1000,\n connectTimeout: 30 * 1000,\n will: {\n topic: 'WillMsg',\n payload: 'Connection Closed abnormally..!',\n qos: 0,\n retain: false\n },\n username: user,\n password: password,\n rejectUnauthorized: false\n })\n\n client.on('error', err => {\n console.error(err)\n client.end()\n })\n\n client.on('connect', packet => {\n console.log('client connected:', clientId, packet)\n\n client.subscribe(\n topic,\n {\n qos\n },\n (err, granted) => {\n if (!err) {\n console.error('subscription failed', err)\n } else {\n console.log('mqtt subscription success for topic - ', topic)\n }\n }\n )\n })\n\n client.on('message', (topic, message, packet) => {\n this.data = this._convertDataFormat(message.toString(), dataFormat)\n })\n\n client.on('close', () => {\n console.log(clientId + ' disconnected')\n })\n\n this._client = client\n }\n\n dispose() {\n try {\n this._client && this._client.end(true, () => {})\n } catch (e) {\n console.error(e)\n }\n delete this._client\n\n super.dispose()\n }\n\n render(context: CanvasRenderingContext2D): void {\n var { left, top, width, height } = this.bounds\n\n context.beginPath()\n this.drawImage(context, Mqtt.image, left, top, width, height)\n }\n\n get message() {\n return this.getState('message')\n }\n\n set message(message) {\n this.setState('message', message)\n }\n\n onchange(after: Properties, before: Properties): void {\n if ('message' in after) {\n const { message } = after\n\n if (!this._client || !this._client.connected) {\n return\n }\n\n var { topic } = this.state\n\n this._client.publish(topic, JSON.stringify(message), {\n qos: 0,\n retain: false\n })\n }\n }\n\n get nature() {\n return NATURE\n }\n}\n"]}
1
+ {"version":3,"file":"mqtt.js","sourceRoot":"","sources":["../src/mqtt.ts"],"names":[],"mappings":";;AAA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AAE,MAAI,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;IAC/D,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;IACjC,CAAC;IAED,IAAI,OAAO,CAAC,OAAO;QACjB,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;IACnC,CAAC;IAED,QAAQ,CAAC,KAAiB,EAAE,MAAkB;QAC5C,IAAI,SAAS,IAAI,KAAK,EAAE,CAAC;YACvB,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAA;YAEzB,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;gBAC7C,OAAM;YACR,CAAC;YAED,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAA;YAE1B,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE;gBACnD,GAAG,EAAE,CAAC;gBACN,MAAM,EAAE,KAAK;aACd,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,IAAI,MAAM;QACR,OAAO,MAAM,CAAA;IACf,CAAC;CACF,CAAA;AAtJoB,IAAI;IADxB,cAAc,CAAC,MAAM,CAAC;GACF,IAAI,CAsJxB;eAtJoB,IAAI","sourcesContent":["import mqtt from 'mqtt'\n\n/*\n * Copyright © HatioLab Inc. All rights reserved.\n */\nimport {\n ComponentNature,\n DataSource,\n Properties,\n RectPath,\n Shape,\n sceneComponent\n} from '@hatiolab/things-scene'\n\nconst NATURE: ComponentNature = {\n mutable: false,\n resizable: true,\n rotatable: true,\n properties: [\n {\n type: 'string',\n label: 'broker',\n name: 'broker',\n placeholder: 'WebSocket hostname'\n },\n {\n type: 'number',\n label: 'port',\n name: 'port',\n placeholder: '15675'\n },\n {\n type: 'string',\n label: 'path',\n name: 'path',\n placeholder: '/mqtt or /ws'\n },\n {\n type: 'string',\n label: 'user',\n name: 'user'\n },\n {\n type: 'string',\n label: 'password',\n name: 'password',\n property: 'password'\n },\n {\n type: 'string',\n label: 'topic',\n name: 'topic'\n },\n {\n type: 'number',\n label: 'qos',\n name: 'qos',\n placeholder: '0..2'\n },\n {\n type: 'string',\n label: 'client-id',\n name: 'clientId'\n },\n {\n type: 'select',\n label: 'data-format',\n name: 'dataFormat',\n property: {\n options: [\n {\n display: 'Plain Text',\n value: 'text'\n },\n {\n display: 'JSON',\n value: 'json'\n }\n ]\n }\n },\n {\n type: 'checkbox',\n label: 'retain',\n name: 'retain'\n },\n {\n type: 'checkbox',\n label: 'ssl',\n name: 'ssl'\n }\n ],\n 'value-property': 'message',\n help: 'scene/component/mqtt'\n}\n\nconst MQTT_IMAGE =\n 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAK0AAACpCAMAAABu4E1nAAAAulBMVEVHcEzh1uvj1+3f2ezk2Ozk1u3h2Ozh4Ovl5O7g0O/j1e3i1uvl1+zDwdy2tNe+vNvGxN6yr9TIxt+8udnMyuHV1OavrNOopdDPzeO6t9iBfq7KyOCsqdK0sdXEwt3BvtvS0OSDMIekoM24tteKPo9wCHJ6Hn1/KYPZ2OiHN4t3F3mTUJh9I4CXV52QSpXd3Ol0EHaNRJKbX6GrfbKmdK2eZaWia6mLiLaVkr2xibmdmsS7nsbGsdLj1+x6ayFYAAAADXRSTlMA72knP6XI/v4Qg+JLWzYOpwAAD0xJREFUeF5iwAE4BxIwEA9YuFjZGG0HGDCysTIxE3YqK6PtoAHcXHgdzMNmO8gAKwsDDsDMZjsIASv2VMwEVwBgzVyX3bShKNxbgpPUF8AcsIxtKs/0uNNM+ReppH3/1yq6wELetoVEdzvTHynRl2+WFvuQW9FU1b6fo5os26k5r9VcLteyk2rqrG3bm5pinEZNpYY+fjaPX7Z68n4Oaq7XzSaVUh7bNmkTO6vVKkGEf30A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U2m6LDO8Qib0RcV3CLd1VGai7eXU7OvWF3cwKriDXDucSih0T/Z3HBbErq1v+uHN3tbrXdFrC72bP2ZhNpe2KtgtkYkcVgJp3Bt2DARt4u1nuDmxIDbuZtVrd8cN5C0o8QAAVjAu42hlQ3Lfc7Wa469hwxxZHXE0tHW8MqxQ9vwjFTbiZDCOb2nR3H+n0qm8KvxOtrTSGVkQAbXMp5kZcV25qWO90954OqeFAnmaYKtUVaz81oA3mrp3KUOkMs9y9FoJaH8NgQ8omrFTXgvBCaGOu/1DiFm33Pe4u2fQqRnI0cHes7ZpYWtCmlz76iDu6q813t7cEV55z2BfVLSPIWsH7nGibrwXuR91NuAc2bPsj0mp1T9tum79Rs9AXalQG7bvgVdiZ7j6x0ADfcJ/3iqvqKq4RtMtGaaEu1s8+4EZ1VYaZfTfh3oEAK7lYNoZfvuGWgbupujo4AGmVNntZaah0hjnuBtodCw3A9rAvcs5tq9U1Cqu0KoPn7cFb6QzM3bwxgKAWGnDlaU0euJufdo2NSF+aE9rm4vVVuNXQ973TpTJHoQtBimOwfkhnQDEWXg7o4/EI2tIGY+3LbOGAiwGLaxmYWW0HIeBmZoADBgbmQX2THSPLkLkl0JaNiGsNmQbvDYwAiZJSuDJ1+dQAAAAASUVORK5CYII='\n\n@sceneComponent('mqtt')\nexport default class Mqtt extends DataSource(RectPath(Shape)) {\n private static _image: HTMLImageElement\n\n private _client?: mqtt.MqttClient\n\n static get image() {\n if (!Mqtt._image) {\n Mqtt._image = new Image()\n Mqtt._image.src = MQTT_IMAGE\n }\n\n return Mqtt._image\n }\n\n async ready() {\n await super.ready()\n\n if (!this.app.isViewMode) return\n\n this._initMqttConnection()\n }\n\n _initMqttConnection() {\n try {\n this._client && this._client.end(true, () => {})\n } catch (e) {\n console.error(e)\n }\n delete this._client\n\n var {\n broker,\n port = 8441,\n clientId = 'THINGS-FACTORY',\n topic,\n qos = 1,\n retain = false,\n path = '/mqtt',\n dataFormat = 'text',\n user,\n password,\n ssl = false\n } = this.state\n\n if (!broker) {\n console.warn('broker not defined')\n return\n }\n\n clientId = [clientId, Date.now()].join('-')\n\n var client = mqtt.connect(`ws://${broker}:${port}${path}`, {\n keepalive: 10,\n clientId,\n protocolId: 'MQTT',\n protocolVersion: 4,\n clean: true,\n reconnectPeriod: 1000,\n connectTimeout: 30 * 1000,\n will: {\n topic: 'WillMsg',\n payload: 'Connection Closed abnormally..!',\n qos: 0,\n retain: false\n },\n username: user,\n password: password,\n rejectUnauthorized: false\n })\n\n client.on('error', err => {\n console.error(err)\n client.end()\n })\n\n client.on('connect', packet => {\n console.log('client connected:', clientId, packet)\n\n client.subscribe(\n topic,\n {\n qos\n },\n (err, granted) => {\n if (!err) {\n console.error('subscription failed', err)\n } else {\n console.log('mqtt subscription success for topic - ', topic)\n }\n }\n )\n })\n\n client.on('message', (topic, message, packet) => {\n this.data = this._convertDataFormat(message.toString(), dataFormat)\n })\n\n client.on('close', () => {\n console.log(clientId + ' disconnected')\n })\n\n this._client = client\n }\n\n dispose() {\n try {\n this._client && this._client.end(true, () => {})\n } catch (e) {\n console.error(e)\n }\n delete this._client\n\n super.dispose()\n }\n\n render(context: CanvasRenderingContext2D): void {\n var { left, top, width, height } = this.bounds\n\n context.beginPath()\n this.drawImage(context, Mqtt.image, left, top, width, height)\n }\n\n get message() {\n return this.getState('message')\n }\n\n set message(message) {\n this.setState('message', message)\n }\n\n onchange(after: Properties, before: Properties): void {\n if ('message' in after) {\n const { message } = after\n\n if (!this._client || !this._client.connected) {\n return\n }\n\n var { topic } = this.state\n\n this._client.publish(topic, JSON.stringify(message), {\n qos: 0,\n retain: false\n })\n }\n }\n\n get nature() {\n return NATURE\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@operato/scene-mqtt",
3
- "version": "10.0.0-beta.2",
3
+ "version": "10.0.0-beta.31",
4
4
  "type": "module",
5
5
  "description": "MQTT integration component for things-scene",
6
6
  "license": "MIT",
@@ -59,5 +59,5 @@
59
59
  "prettier --write"
60
60
  ]
61
61
  },
62
- "gitHead": "350ece104754d007967cf8e3f54d0d157465e94a"
62
+ "gitHead": "fdafbd04fd083a43690be937230c7d96a3ee5da3"
63
63
  }