@operato/scene-integration 0.0.5 → 0.0.6
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/CHANGELOG.md +9 -0
- package/dist/connection-control.d.ts +41 -0
- package/dist/connection-control.js +137 -0
- package/dist/connection-control.js.map +1 -0
- package/dist/connection-state-subscription.d.ts +29 -0
- package/dist/connection-state-subscription.js +89 -0
- package/dist/connection-state-subscription.js.map +1 -0
- package/dist/data-subscription.d.ts +29 -0
- package/dist/data-subscription.js +76 -0
- package/dist/data-subscription.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/origin-client.d.ts +5 -0
- package/dist/origin-client.js +110 -0
- package/dist/origin-client.js.map +1 -0
- package/dist/scenario-control.d.ts +44 -0
- package/dist/scenario-control.js +142 -0
- package/dist/scenario-control.js.map +1 -0
- package/dist/scenario-instance-subscription.d.ts +34 -0
- package/dist/scenario-instance-subscription.js +107 -0
- package/dist/scenario-instance-subscription.js.map +1 -0
- package/dist/scenario-queue-subscription.d.ts +22 -0
- package/dist/scenario-queue-subscription.js +68 -0
- package/dist/scenario-queue-subscription.js.map +1 -0
- package/dist/scenario-run.d.ts +39 -0
- package/dist/scenario-run.js +136 -0
- package/dist/scenario-run.js.map +1 -0
- package/dist/scenario-start.d.ts +39 -0
- package/dist/scenario-start.js +134 -0
- package/dist/scenario-start.js.map +1 -0
- package/dist/scenario-stop.d.ts +39 -0
- package/dist/scenario-stop.js +122 -0
- package/dist/scenario-stop.js.map +1 -0
- package/package.json +2 -2
- package/src/connection-control.ts +1 -5
- package/src/connection-state-subscription.ts +2 -7
- package/src/data-subscription.ts +1 -6
- package/src/origin-client.ts +0 -3
- package/src/scenario-control.ts +0 -3
- package/src/scenario-instance-subscription.ts +2 -7
- package/src/scenario-queue-subscription.ts +1 -6
- package/src/scenario-run.ts +0 -3
- package/src/scenario-start.ts +0 -3
- package/src/scenario-stop.ts +0 -3
- package/tsconfig.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,15 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
### [0.0.6](https://github.com/things-scene/operato-scene/compare/v0.0.5...v0.0.6) (2021-12-03)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### :bug: Bug Fix
|
|
10
|
+
|
|
11
|
+
* tsconfig ([a5ce449](https://github.com/things-scene/operato-scene/commit/a5ce449078e0b5371323984b78f1fb32526489bd))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
6
15
|
### [0.0.5](https://github.com/things-scene/operato-scene/compare/v0.0.4...v0.0.5) (2021-12-03)
|
|
7
16
|
|
|
8
17
|
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Shape } from '@hatiolab/things-scene';
|
|
2
|
+
declare const ConnectionControl_base: typeof Shape;
|
|
3
|
+
export default class ConnectionControl extends ConnectionControl_base {
|
|
4
|
+
static _image: HTMLImageElement;
|
|
5
|
+
static get image(): HTMLImageElement;
|
|
6
|
+
private _client;
|
|
7
|
+
render(context: CanvasRenderingContext2D): void;
|
|
8
|
+
ready(): void;
|
|
9
|
+
_init(): void;
|
|
10
|
+
dispose(): void;
|
|
11
|
+
get nature(): {
|
|
12
|
+
mutable: boolean;
|
|
13
|
+
resizable: boolean;
|
|
14
|
+
rotatable: boolean;
|
|
15
|
+
properties: ({
|
|
16
|
+
type: string;
|
|
17
|
+
label: string;
|
|
18
|
+
name: string;
|
|
19
|
+
property: {
|
|
20
|
+
options: () => Promise<string[]>;
|
|
21
|
+
};
|
|
22
|
+
} | {
|
|
23
|
+
type: string;
|
|
24
|
+
label: string;
|
|
25
|
+
name: string;
|
|
26
|
+
property: {
|
|
27
|
+
options: {
|
|
28
|
+
display: string;
|
|
29
|
+
value: string;
|
|
30
|
+
}[];
|
|
31
|
+
};
|
|
32
|
+
})[];
|
|
33
|
+
'value-property': string;
|
|
34
|
+
help: string;
|
|
35
|
+
};
|
|
36
|
+
get client(): any;
|
|
37
|
+
get controlType(): string;
|
|
38
|
+
set controlType(controlType: string);
|
|
39
|
+
controlConnect(): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { Component, RectPath, Shape } from '@hatiolab/things-scene';
|
|
2
|
+
import COMPONENT_IMAGE from '../assets/symbol-connection-control.png';
|
|
3
|
+
import { getClient } from './origin-client';
|
|
4
|
+
import gql from 'graphql-tag';
|
|
5
|
+
const NATURE = {
|
|
6
|
+
mutable: false,
|
|
7
|
+
resizable: true,
|
|
8
|
+
rotatable: true,
|
|
9
|
+
properties: [
|
|
10
|
+
{
|
|
11
|
+
type: 'select',
|
|
12
|
+
label: 'connection-name',
|
|
13
|
+
name: 'connectionName',
|
|
14
|
+
property: {
|
|
15
|
+
options: async () => {
|
|
16
|
+
var response = await getClient().query({
|
|
17
|
+
query: gql `
|
|
18
|
+
query {
|
|
19
|
+
connections {
|
|
20
|
+
items {
|
|
21
|
+
name
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
`
|
|
26
|
+
});
|
|
27
|
+
if (response.errors) {
|
|
28
|
+
return [''];
|
|
29
|
+
}
|
|
30
|
+
return [''].concat(response.data.connections.items.map((item) => item.name));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
type: 'select',
|
|
36
|
+
label: 'control-type',
|
|
37
|
+
name: 'controlType',
|
|
38
|
+
property: {
|
|
39
|
+
options: [
|
|
40
|
+
{
|
|
41
|
+
display: '',
|
|
42
|
+
value: ''
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
display: 'connect',
|
|
46
|
+
value: 'connect'
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
display: 'disconnect',
|
|
50
|
+
value: 'disconnect'
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
'value-property': 'controlType',
|
|
57
|
+
help: 'scene/component/connection-control'
|
|
58
|
+
};
|
|
59
|
+
export default class ConnectionControl extends RectPath(Shape) {
|
|
60
|
+
static get image() {
|
|
61
|
+
if (!ConnectionControl._image) {
|
|
62
|
+
ConnectionControl._image = new Image();
|
|
63
|
+
ConnectionControl._image.src = COMPONENT_IMAGE;
|
|
64
|
+
}
|
|
65
|
+
return ConnectionControl._image;
|
|
66
|
+
}
|
|
67
|
+
render(context) {
|
|
68
|
+
var { left, top, width, height } = this.bounds;
|
|
69
|
+
context.beginPath();
|
|
70
|
+
this.drawImage(context, ConnectionControl.image, left, top, width, height);
|
|
71
|
+
}
|
|
72
|
+
ready() {
|
|
73
|
+
super.ready();
|
|
74
|
+
this._init();
|
|
75
|
+
}
|
|
76
|
+
_init() {
|
|
77
|
+
if (!this.app.isViewMode)
|
|
78
|
+
return;
|
|
79
|
+
this._client = getClient();
|
|
80
|
+
}
|
|
81
|
+
dispose() {
|
|
82
|
+
super.dispose();
|
|
83
|
+
try {
|
|
84
|
+
if (this._client) {
|
|
85
|
+
this._client.stop();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
console.error(e);
|
|
90
|
+
}
|
|
91
|
+
delete this._client;
|
|
92
|
+
}
|
|
93
|
+
get nature() {
|
|
94
|
+
return NATURE;
|
|
95
|
+
}
|
|
96
|
+
get client() {
|
|
97
|
+
return this._client;
|
|
98
|
+
}
|
|
99
|
+
get controlType() {
|
|
100
|
+
return this.getState('controlType');
|
|
101
|
+
}
|
|
102
|
+
set controlType(controlType) {
|
|
103
|
+
this.setState('controlType', controlType);
|
|
104
|
+
this.controlConnect();
|
|
105
|
+
}
|
|
106
|
+
async controlConnect() {
|
|
107
|
+
let { controlType, connectionName } = this.state;
|
|
108
|
+
if (!connectionName || !this.app.isViewMode)
|
|
109
|
+
return;
|
|
110
|
+
switch (controlType) {
|
|
111
|
+
case 'connect':
|
|
112
|
+
case true:
|
|
113
|
+
case 1:
|
|
114
|
+
controlType = 'connect';
|
|
115
|
+
break;
|
|
116
|
+
default:
|
|
117
|
+
controlType = 'disconnect';
|
|
118
|
+
}
|
|
119
|
+
var client = this._client;
|
|
120
|
+
var query = '';
|
|
121
|
+
query = `mutation{
|
|
122
|
+
${controlType}Connection(name: "${connectionName}") {
|
|
123
|
+
status
|
|
124
|
+
}
|
|
125
|
+
}`;
|
|
126
|
+
if (client) {
|
|
127
|
+
var response = await client.query({
|
|
128
|
+
query: gql `
|
|
129
|
+
${query}
|
|
130
|
+
`
|
|
131
|
+
});
|
|
132
|
+
this.data = response;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
Component.register('connection-control', ConnectionControl);
|
|
137
|
+
//# sourceMappingURL=connection-control.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-control.js","sourceRoot":"","sources":["../src/connection-control.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAEnE,OAAO,eAAe,MAAM,yCAAyC,CAAA;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,GAAG,MAAM,aAAa,CAAA;AAE7B,MAAM,MAAM,GAAG;IACb,OAAO,EAAE,KAAK;IACd,SAAS,EAAE,IAAI;IACf,SAAS,EAAE,IAAI;IACf,UAAU,EAAE;QACV;YACE,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,iBAAiB;YACxB,IAAI,EAAE,gBAAgB;YACtB,QAAQ,EAAE;gBACR,OAAO,EAAE,KAAK,IAAI,EAAE;oBAClB,IAAI,QAAQ,GAAG,MAAM,SAAS,EAAE,CAAC,KAAK,CAAC;wBACr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vB,MAAK;YACP;gBACE,WAAW,GAAG,YAAY,CAAA;SAC7B;QAED,IAAI,MAAM,GAAG,IAAI,CAAC,OAAO,CAAA;QACzB,IAAI,KAAK,GAAG,EAAE,CAAA;QAEd,KAAK,GAAG;QACJ,WAAW,qBAAqB,cAAc;;;MAGhD,CAAA;QAEF,IAAI,MAAM,EAAE;YACV,IAAI,QAAQ,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC;gBAChC,KAAK,EAAE,GAAG,CAAA;YACN,KAAK;SACR;aACF,CAAC,CAAA;YAEF,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAA;SACrB;IACH,CAAC;CACF;AAED,SAAS,CAAC,QAAQ,CAAC,oBAAoB,EAAE,iBAAiB,CAAC,CAAA","sourcesContent":["import { Component, RectPath, Shape } from '@hatiolab/things-scene'\n\nimport COMPONENT_IMAGE from '../assets/symbol-connection-control.png'\nimport { getClient } from './origin-client'\nimport gql from 'graphql-tag'\n\nconst NATURE = {\n mutable: false,\n resizable: true,\n rotatable: true,\n properties: [\n {\n type: 'select',\n label: 'connection-name',\n name: 'connectionName',\n property: {\n options: async () => {\n var response = await getClient().query({\n query: gql`\n query {\n connections {\n items {\n name\n }\n }\n }\n `\n })\n if (response.errors) {\n return ['']\n }\n\n return [''].concat(response.data.connections.items.map((item: any) => item.name))\n }\n }\n },\n {\n type: 'select',\n label: 'control-type',\n name: 'controlType',\n property: {\n options: [\n {\n display: '',\n value: ''\n },\n {\n display: 'connect',\n value: 'connect'\n },\n {\n display: 'disconnect',\n value: 'disconnect'\n }\n ]\n }\n }\n ],\n 'value-property': 'controlType',\n help: 'scene/component/connection-control'\n}\n\nexport default class ConnectionControl extends RectPath(Shape) {\n static _image: HTMLImageElement\n\n static get image() {\n if (!ConnectionControl._image) {\n ConnectionControl._image = new Image()\n ConnectionControl._image.src = COMPONENT_IMAGE\n }\n return ConnectionControl._image\n }\n\n private _client: any\n\n render(context: CanvasRenderingContext2D) {\n var { left, top, width, height } = this.bounds\n context.beginPath()\n this.drawImage(context, ConnectionControl.image, left, top, width, height)\n }\n\n ready() {\n super.ready()\n this._init()\n }\n\n _init() {\n if (!this.app.isViewMode) return\n\n this._client = getClient()\n }\n\n dispose() {\n super.dispose()\n\n try {\n if (this._client) {\n this._client.stop()\n }\n } catch (e) {\n console.error(e)\n }\n delete this._client\n }\n\n get nature() {\n return NATURE\n }\n\n get client() {\n return this._client\n }\n\n get controlType() {\n return this.getState('controlType')\n }\n\n set controlType(controlType: string) {\n this.setState('controlType', controlType)\n this.controlConnect()\n }\n\n async controlConnect() {\n let { controlType, connectionName } = this.state\n\n if (!connectionName || !this.app.isViewMode) return\n\n switch (controlType) {\n case 'connect':\n case true:\n case 1:\n controlType = 'connect'\n break\n default:\n controlType = 'disconnect'\n }\n\n var client = this._client\n var query = ''\n\n query = `mutation{\n ${controlType}Connection(name: \"${connectionName}\") {\n status\n }\n }`\n\n if (client) {\n var response = await client.query({\n query: gql`\n ${query}\n `\n })\n\n this.data = response\n }\n }\n}\n\nComponent.register('connection-control', ConnectionControl)\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Shape } from '@hatiolab/things-scene';
|
|
2
|
+
declare const ConnectionStateSubscription_base: (new (...args: any[]) => {
|
|
3
|
+
isDataSource(): boolean;
|
|
4
|
+
}) & typeof Shape;
|
|
5
|
+
export default class ConnectionStateSubscription extends ConnectionStateSubscription_base {
|
|
6
|
+
static _image: HTMLImageElement;
|
|
7
|
+
static get image(): HTMLImageElement;
|
|
8
|
+
private subscription?;
|
|
9
|
+
dispose(): void;
|
|
10
|
+
render(context: CanvasRenderingContext2D): void;
|
|
11
|
+
ready(): void;
|
|
12
|
+
get nature(): {
|
|
13
|
+
mutable: boolean;
|
|
14
|
+
resizable: boolean;
|
|
15
|
+
rotatable: boolean;
|
|
16
|
+
properties: {
|
|
17
|
+
type: string;
|
|
18
|
+
label: string;
|
|
19
|
+
name: string;
|
|
20
|
+
property: {
|
|
21
|
+
options: () => Promise<string[]>;
|
|
22
|
+
};
|
|
23
|
+
}[];
|
|
24
|
+
help: string;
|
|
25
|
+
};
|
|
26
|
+
_initConnectionStateSubscription(): void;
|
|
27
|
+
startSubscribe(): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Component, DataSource, RectPath, Shape } from '@hatiolab/things-scene';
|
|
2
|
+
import { getClient, subscribe } from './origin-client';
|
|
3
|
+
import COMPONENT_IMAGE from '../assets/symbol-connection-state-subscription.png';
|
|
4
|
+
import gql from 'graphql-tag';
|
|
5
|
+
const NATURE = {
|
|
6
|
+
mutable: false,
|
|
7
|
+
resizable: true,
|
|
8
|
+
rotatable: true,
|
|
9
|
+
properties: [
|
|
10
|
+
{
|
|
11
|
+
type: 'select',
|
|
12
|
+
label: 'connection-name',
|
|
13
|
+
name: 'connectionName',
|
|
14
|
+
property: {
|
|
15
|
+
options: async () => {
|
|
16
|
+
var response = await getClient().query({
|
|
17
|
+
query: gql `
|
|
18
|
+
query {
|
|
19
|
+
connections {
|
|
20
|
+
items {
|
|
21
|
+
name
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
`
|
|
26
|
+
});
|
|
27
|
+
if (response.errors) {
|
|
28
|
+
return [''];
|
|
29
|
+
}
|
|
30
|
+
return [''].concat(response.data.connections.items.map((item) => item.name));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
help: 'scene/component/connection-state-subscription'
|
|
36
|
+
};
|
|
37
|
+
export default class ConnectionStateSubscription extends DataSource(RectPath(Shape)) {
|
|
38
|
+
static get image() {
|
|
39
|
+
if (!ConnectionStateSubscription._image) {
|
|
40
|
+
ConnectionStateSubscription._image = new Image();
|
|
41
|
+
ConnectionStateSubscription._image.src = COMPONENT_IMAGE;
|
|
42
|
+
}
|
|
43
|
+
return ConnectionStateSubscription._image;
|
|
44
|
+
}
|
|
45
|
+
dispose() {
|
|
46
|
+
var _a;
|
|
47
|
+
super.dispose();
|
|
48
|
+
(_a = this.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
49
|
+
delete this.subscription;
|
|
50
|
+
}
|
|
51
|
+
render(context) {
|
|
52
|
+
var { left, top, width, height } = this.bounds;
|
|
53
|
+
context.beginPath();
|
|
54
|
+
this.drawImage(context, ConnectionStateSubscription.image, left, top, width, height);
|
|
55
|
+
}
|
|
56
|
+
ready() {
|
|
57
|
+
if (!this.app.isViewMode)
|
|
58
|
+
return;
|
|
59
|
+
this._initConnectionStateSubscription();
|
|
60
|
+
}
|
|
61
|
+
get nature() {
|
|
62
|
+
return NATURE;
|
|
63
|
+
}
|
|
64
|
+
_initConnectionStateSubscription() {
|
|
65
|
+
if (!this.app.isViewMode)
|
|
66
|
+
return;
|
|
67
|
+
this.startSubscribe();
|
|
68
|
+
}
|
|
69
|
+
async startSubscribe() {
|
|
70
|
+
var { connectionName } = this.state;
|
|
71
|
+
this.subscription = await subscribe({
|
|
72
|
+
query: gql `subscription {
|
|
73
|
+
connectionState(name: "${connectionName}") {
|
|
74
|
+
name
|
|
75
|
+
state
|
|
76
|
+
timestamp
|
|
77
|
+
}
|
|
78
|
+
}`
|
|
79
|
+
}, {
|
|
80
|
+
next: async ({ data }) => {
|
|
81
|
+
if (data) {
|
|
82
|
+
this.data = data.connectionState;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
Component.register('connection-state-subscription', ConnectionStateSubscription);
|
|
89
|
+
//# sourceMappingURL=connection-state-subscription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-state-subscription.js","sourceRoot":"","sources":["../src/connection-state-subscription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAC/E,OAAO,EAAE,SAA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E,CAAA;QAChC,OAAO,IAAI,CAAC,YAAY,CAAA;IAC1B,CAAC;IAED,MAAM,CAAC,OAAiC;QACtC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAA;QAE9C,OAAO,CAAC,SAAS,EAAE,CAAA;QACnB,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,2BAA2B,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;IACtF,CAAC;IAED,KAAK;QACH,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU;YAAE,OAAM;QAChC,IAAI,CAAC,gCAAgC,EAAE,CAAA;IACzC,CAAC;IAED,IAAI,MAAM;QACR,OAAO,MAAM,CAAA;IACf,CAAC;IAED,gCAAgC;QAC9B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU;YAAE,OAAM;QAChC,IAAI,CAAC,cAAc,EAAE,CAAA;IACvB,CAAC;IAED,KAAK,CAAC,cAAc;QAClB,IAAI,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC,KAAK,CAAA;QAEnC,IAAI,CAAC,YAAY,GAAG,MAAM,SAAS,CACjC;YACE,KAAK,EAAE,GAAG,CAAA;mCACiB,cAAc;;;;;UAKvC;SACH,EACD;YACE,IAAI,EAAE,KAAK,EAAE,EAAE,IAAI,EAAiB,EAAE,EAAE;gBACtC,IAAI,IAAI,EAAE;oBACR,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,eAAe,CAAA;iBACjC;YACH,CAAC;SACF,CACF,CAAA;IACH,CAAC;CACF;AAED,SAAS,CAAC,QAAQ,CAAC,+BAA+B,EAAE,2BAA2B,CAAC,CAAA","sourcesContent":["import { Component, DataSource, RectPath, Shape } from '@hatiolab/things-scene'\nimport { getClient, subscribe } from './origin-client'\n\nimport COMPONENT_IMAGE from '../assets/symbol-connection-state-subscription.png'\nimport gql from 'graphql-tag'\n\nconst NATURE = {\n mutable: false,\n resizable: true,\n rotatable: true,\n properties: [\n {\n type: 'select',\n label: 'connection-name',\n name: 'connectionName',\n property: {\n options: async () => {\n var response = await getClient().query({\n query: gql`\n query {\n connections {\n items {\n name\n }\n }\n }\n `\n })\n if (response.errors) {\n return ['']\n }\n\n return [''].concat(response.data.connections.items.map((item: any) => item.name))\n }\n }\n }\n ],\n help: 'scene/component/connection-state-subscription'\n}\n\nexport default class ConnectionStateSubscription extends DataSource(RectPath(Shape)) {\n static _image: HTMLImageElement\n static get image() {\n if (!ConnectionStateSubscription._image) {\n ConnectionStateSubscription._image = new Image()\n ConnectionStateSubscription._image.src = COMPONENT_IMAGE\n }\n\n return ConnectionStateSubscription._image\n }\n\n private subscription?: {\n unsubscribe(): void\n }\n\n dispose() {\n super.dispose()\n\n this.subscription?.unsubscribe()\n delete this.subscription\n }\n\n render(context: CanvasRenderingContext2D) {\n var { left, top, width, height } = this.bounds\n\n context.beginPath()\n this.drawImage(context, ConnectionStateSubscription.image, left, top, width, height)\n }\n\n ready() {\n if (!this.app.isViewMode) return\n this._initConnectionStateSubscription()\n }\n\n get nature() {\n return NATURE\n }\n\n _initConnectionStateSubscription() {\n if (!this.app.isViewMode) return\n this.startSubscribe()\n }\n\n async startSubscribe() {\n var { connectionName } = this.state\n\n this.subscription = await subscribe(\n {\n query: gql`subscription {\n connectionState(name: \"${connectionName}\") {\n name\n state\n timestamp\n }\n }`\n },\n {\n next: async ({ data }: { data: any }) => {\n if (data) {\n this.data = data.connectionState\n }\n }\n }\n )\n }\n}\n\nComponent.register('connection-state-subscription', ConnectionStateSubscription)\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Shape } from '@hatiolab/things-scene';
|
|
2
|
+
declare const DataSubscription_base: (new (...args: any[]) => {
|
|
3
|
+
isDataSource(): boolean;
|
|
4
|
+
}) & typeof Shape;
|
|
5
|
+
export default class DataSubscription extends DataSubscription_base {
|
|
6
|
+
static _image: HTMLImageElement;
|
|
7
|
+
static get image(): HTMLImageElement;
|
|
8
|
+
private subscription?;
|
|
9
|
+
dispose(): void;
|
|
10
|
+
render(context: CanvasRenderingContext2D): void;
|
|
11
|
+
ready(): void;
|
|
12
|
+
get nature(): {
|
|
13
|
+
mutable: boolean;
|
|
14
|
+
resizable: boolean;
|
|
15
|
+
rotatable: boolean;
|
|
16
|
+
properties: {
|
|
17
|
+
type: string;
|
|
18
|
+
label: string;
|
|
19
|
+
name: string;
|
|
20
|
+
}[];
|
|
21
|
+
'value-property': string;
|
|
22
|
+
help: string;
|
|
23
|
+
};
|
|
24
|
+
get tag(): any;
|
|
25
|
+
set tag(tag: any);
|
|
26
|
+
_initDataSubscription(): void;
|
|
27
|
+
startSubscribe(): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Component, DataSource, RectPath, Shape } from '@hatiolab/things-scene';
|
|
2
|
+
import COMPONENT_IMAGE from '../assets/symbol-data-subscription.png';
|
|
3
|
+
import gql from 'graphql-tag';
|
|
4
|
+
import { subscribe } from './origin-client';
|
|
5
|
+
const NATURE = {
|
|
6
|
+
mutable: false,
|
|
7
|
+
resizable: true,
|
|
8
|
+
rotatable: true,
|
|
9
|
+
properties: [
|
|
10
|
+
{
|
|
11
|
+
type: 'string',
|
|
12
|
+
label: 'tag',
|
|
13
|
+
name: 'tag'
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
'value-property': 'tag',
|
|
17
|
+
help: 'scene/component/data-subscription'
|
|
18
|
+
};
|
|
19
|
+
export default class DataSubscription extends DataSource(RectPath(Shape)) {
|
|
20
|
+
static get image() {
|
|
21
|
+
if (!DataSubscription._image) {
|
|
22
|
+
DataSubscription._image = new Image();
|
|
23
|
+
DataSubscription._image.src = COMPONENT_IMAGE;
|
|
24
|
+
}
|
|
25
|
+
return DataSubscription._image;
|
|
26
|
+
}
|
|
27
|
+
dispose() {
|
|
28
|
+
var _a;
|
|
29
|
+
(_a = this.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
30
|
+
delete this.subscription;
|
|
31
|
+
super.dispose();
|
|
32
|
+
}
|
|
33
|
+
render(context) {
|
|
34
|
+
var { left, top, width, height } = this.bounds;
|
|
35
|
+
context.beginPath();
|
|
36
|
+
this.drawImage(context, DataSubscription.image, left, top, width, height);
|
|
37
|
+
}
|
|
38
|
+
ready() {
|
|
39
|
+
this._initDataSubscription();
|
|
40
|
+
}
|
|
41
|
+
get nature() {
|
|
42
|
+
return NATURE;
|
|
43
|
+
}
|
|
44
|
+
get tag() {
|
|
45
|
+
return this.state.tag;
|
|
46
|
+
}
|
|
47
|
+
set tag(tag) {
|
|
48
|
+
this.setState('tag', tag);
|
|
49
|
+
}
|
|
50
|
+
_initDataSubscription() {
|
|
51
|
+
if (!this.app.isViewMode)
|
|
52
|
+
return;
|
|
53
|
+
this.startSubscribe();
|
|
54
|
+
}
|
|
55
|
+
async startSubscribe() {
|
|
56
|
+
var { tag } = this.state;
|
|
57
|
+
this.subscription = await subscribe({
|
|
58
|
+
query: gql `
|
|
59
|
+
subscription {
|
|
60
|
+
data(tag: "${tag}") {
|
|
61
|
+
tag
|
|
62
|
+
data
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
`
|
|
66
|
+
}, {
|
|
67
|
+
next: async ({ data }) => {
|
|
68
|
+
if (data) {
|
|
69
|
+
this.data = data.data.data;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
Component.register('data-subscription', DataSubscription);
|
|
76
|
+
//# sourceMappingURL=data-subscription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-subscription.js","sourceRoot":"","sources":["../src/data-subscription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAE/E,O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QACR,OAAO,MAAM,CAAA;IACf,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAA;IACvB,CAAC;IAED,IAAI,GAAG,CAAC,GAAG;QACT,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;IAC3B,CAAC;IAED,qBAAqB;QACnB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU;YAAE,OAAM;QAEhC,IAAI,CAAC,cAAc,EAAE,CAAA;IACvB,CAAC;IAED,KAAK,CAAC,cAAc;QAClB,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAA;QAExB,IAAI,CAAC,YAAY,GAAG,MAAM,SAAS,CACjC;YACE,KAAK,EAAE,GAAG,CAAA;;yBAEO,GAAG;;;;;SAKnB;SACF,EACD;YACE,IAAI,EAAE,KAAK,EAAE,EAAE,IAAI,EAAiB,EAAE,EAAE;gBACtC,IAAI,IAAI,EAAE;oBACR,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAA;iBAC3B;YACH,CAAC;SACF,CACF,CAAA;IACH,CAAC;CACF;AAED,SAAS,CAAC,QAAQ,CAAC,mBAAmB,EAAE,gBAAgB,CAAC,CAAA","sourcesContent":["import { Component, DataSource, RectPath, Shape } from '@hatiolab/things-scene'\n\nimport COMPONENT_IMAGE from '../assets/symbol-data-subscription.png'\nimport gql from 'graphql-tag'\nimport { subscribe } from './origin-client'\n\nconst NATURE = {\n mutable: false,\n resizable: true,\n rotatable: true,\n properties: [\n {\n type: 'string',\n label: 'tag',\n name: 'tag'\n }\n ],\n 'value-property': 'tag',\n help: 'scene/component/data-subscription'\n}\n\nexport default class DataSubscription extends DataSource(RectPath(Shape)) {\n static _image: HTMLImageElement\n static get image() {\n if (!DataSubscription._image) {\n DataSubscription._image = new Image()\n DataSubscription._image.src = COMPONENT_IMAGE\n }\n\n return DataSubscription._image\n }\n\n private subscription?: {\n unsubscribe(): void\n }\n\n dispose() {\n this.subscription?.unsubscribe()\n delete this.subscription\n\n super.dispose()\n }\n\n render(context: CanvasRenderingContext2D) {\n var { left, top, width, height } = this.bounds\n\n context.beginPath()\n this.drawImage(context, DataSubscription.image, left, top, width, height)\n }\n\n ready() {\n this._initDataSubscription()\n }\n\n get nature() {\n return NATURE\n }\n\n get tag() {\n return this.state.tag\n }\n\n set tag(tag) {\n this.setState('tag', tag)\n }\n\n _initDataSubscription() {\n if (!this.app.isViewMode) return\n\n this.startSubscribe()\n }\n\n async startSubscribe() {\n var { tag } = this.state\n\n this.subscription = await subscribe(\n {\n query: gql`\n subscription {\n data(tag: \"${tag}\") {\n tag\n data\n }\n }\n `\n },\n {\n next: async ({ data }: { data: any }) => {\n if (data) {\n this.data = data.data.data\n }\n }\n }\n )\n }\n}\n\nComponent.register('data-subscription', DataSubscription)\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import DataSubscription from './data-subscription';
|
|
2
|
+
import ScenarioControl from './scenario-control';
|
|
3
|
+
import ScenarioRun from './scenario-run';
|
|
4
|
+
import ScenarioStart from './scenario-start';
|
|
5
|
+
import ScenarioStop from './scenario-stop';
|
|
6
|
+
import ScenarioInstanceSubscription from './scenario-instance-subscription';
|
|
7
|
+
import ScenarioQueueSubscription from './scenario-queue-subscription';
|
|
8
|
+
import ConnectionStateSubscription from './connection-state-subscription';
|
|
9
|
+
import ConnectionControl from './connection-control';
|
|
10
|
+
declare const _default: (typeof ConnectionControl | typeof ConnectionStateSubscription | typeof DataSubscription | typeof ScenarioControl | typeof ScenarioRun | typeof ScenarioStart | typeof ScenarioStop | typeof ScenarioInstanceSubscription | typeof ScenarioQueueSubscription)[];
|
|
11
|
+
export default _default;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import DataSubscription from './data-subscription';
|
|
2
|
+
import ScenarioControl from './scenario-control';
|
|
3
|
+
import ScenarioRun from './scenario-run';
|
|
4
|
+
import ScenarioStart from './scenario-start';
|
|
5
|
+
import ScenarioStop from './scenario-stop';
|
|
6
|
+
import ScenarioInstanceSubscription from './scenario-instance-subscription';
|
|
7
|
+
import ScenarioQueueSubscription from './scenario-queue-subscription';
|
|
8
|
+
import ConnectionStateSubscription from './connection-state-subscription';
|
|
9
|
+
import ConnectionControl from './connection-control';
|
|
10
|
+
export default [
|
|
11
|
+
DataSubscription,
|
|
12
|
+
ScenarioControl,
|
|
13
|
+
ScenarioRun,
|
|
14
|
+
ScenarioStart,
|
|
15
|
+
ScenarioStop,
|
|
16
|
+
ScenarioInstanceSubscription,
|
|
17
|
+
ScenarioQueueSubscription,
|
|
18
|
+
ConnectionStateSubscription,
|
|
19
|
+
ConnectionControl
|
|
20
|
+
];
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,qBAAqB,CAAA;AAClD,OAAO,eAAe,MAAM,oBAAoB,CAAA;AAChD,OAAO,WAAW,MAAM,gBAAgB,CAAA;AACxC,OAAO,aAAa,MAAM,kBAAkB,CAAA;AAC5C,OAAO,YAAY,MAAM,iBAAiB,CAAA;AAC1C,OAAO,4BAA4B,MAAM,kCAAkC,CAAA;AAC3E,OAAO,yBAAyB,MAAM,+BAA+B,CAAA;AACrE,OAAO,2BAA2B,MAAM,iCAAiC,CAAA;AACzE,OAAO,iBAAiB,MAAM,sBAAsB,CAAA;AAEpD,eAAe;IACb,gBAAgB;IAChB,eAAe;IACf,WAAW;IACX,aAAa;IACb,YAAY;IACZ,4BAA4B;IAC5B,yBAAyB;IACzB,2BAA2B;IAC3B,iBAAiB;CAClB,CAAA","sourcesContent":["import DataSubscription from './data-subscription'\nimport ScenarioControl from './scenario-control'\nimport ScenarioRun from './scenario-run'\nimport ScenarioStart from './scenario-start'\nimport ScenarioStop from './scenario-stop'\nimport ScenarioInstanceSubscription from './scenario-instance-subscription'\nimport ScenarioQueueSubscription from './scenario-queue-subscription'\nimport ConnectionStateSubscription from './connection-state-subscription'\nimport ConnectionControl from './connection-control'\n\nexport default [\n DataSubscription,\n ScenarioControl,\n ScenarioRun,\n ScenarioStart,\n ScenarioStop,\n ScenarioInstanceSubscription,\n ScenarioQueueSubscription,\n ConnectionStateSubscription,\n ConnectionControl\n]\n"]}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { ApolloClient, HttpLink, InMemoryCache, from } from '@apollo/client/core';
|
|
2
|
+
import { onError } from '@apollo/client/link/error';
|
|
3
|
+
import { SubscriptionClient } from 'subscriptions-transport-ws';
|
|
4
|
+
const defaultOptions = {
|
|
5
|
+
watchQuery: {
|
|
6
|
+
fetchPolicy: 'no-cache',
|
|
7
|
+
errorPolicy: 'ignore'
|
|
8
|
+
},
|
|
9
|
+
query: {
|
|
10
|
+
fetchPolicy: 'no-cache',
|
|
11
|
+
errorPolicy: 'all'
|
|
12
|
+
},
|
|
13
|
+
mutate: {
|
|
14
|
+
errorPolicy: 'all'
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const ERROR_HANDLER = ({ graphQLErrors, networkError }) => {
|
|
18
|
+
if (graphQLErrors) {
|
|
19
|
+
document.dispatchEvent(new CustomEvent('notify', {
|
|
20
|
+
detail: {
|
|
21
|
+
level: 'error',
|
|
22
|
+
message: graphQLErrors[0].message,
|
|
23
|
+
ex: graphQLErrors
|
|
24
|
+
}
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
if (networkError) {
|
|
28
|
+
const code = networkError.statusCode || '';
|
|
29
|
+
const message = `[Response-${code}]: ${networkError.message}`;
|
|
30
|
+
document.dispatchEvent(new CustomEvent('notify', {
|
|
31
|
+
detail: {
|
|
32
|
+
level: 'error',
|
|
33
|
+
message,
|
|
34
|
+
ex: networkError
|
|
35
|
+
}
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var client;
|
|
40
|
+
export function getClient() {
|
|
41
|
+
if (!client) {
|
|
42
|
+
var cache = new InMemoryCache();
|
|
43
|
+
client = new ApolloClient({
|
|
44
|
+
defaultOptions,
|
|
45
|
+
cache,
|
|
46
|
+
link: from([
|
|
47
|
+
onError(ERROR_HANDLER),
|
|
48
|
+
new HttpLink({
|
|
49
|
+
uri: '/graphql',
|
|
50
|
+
credentials: 'include'
|
|
51
|
+
})
|
|
52
|
+
])
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return client;
|
|
56
|
+
}
|
|
57
|
+
/* SubscriptionClient */
|
|
58
|
+
var subscriptionClient;
|
|
59
|
+
const getSubscriptionClient = async () => {
|
|
60
|
+
if (!subscriptionClient) {
|
|
61
|
+
subscriptionClient = new Promise((resolve, reject) => {
|
|
62
|
+
var client = new SubscriptionClient(location.origin.replace(/^http/, 'ws') + '/subscriptions', {
|
|
63
|
+
reconnect: true,
|
|
64
|
+
connectionParams: {
|
|
65
|
+
headers: {
|
|
66
|
+
/*
|
|
67
|
+
특정 도메인의 데이타만 받고자 하는 경우에, referer 정보를 제공해서 서버에서 서브도메인 정보를 취득하도록 한다.
|
|
68
|
+
referer: location.href
|
|
69
|
+
또는, 이미 서브도메인 정보를 알고 있다면,
|
|
70
|
+
'x-things-factory-domain': '[subdomain]'
|
|
71
|
+
을 보낼 수 있다.
|
|
72
|
+
관련 정보를 보내지 않는다면, 사용자가 권한을 가진 모든 도메인의 데이타를 수신하게 된다.
|
|
73
|
+
*/
|
|
74
|
+
referer: location.href
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
client.onError(err => {
|
|
79
|
+
//readyState === 3 인 경우 url을 잘 못 입력했거나, 서버에 문제가 있는 경우이므로 reconnect = false로 변경한다.
|
|
80
|
+
if (client.status === 3) {
|
|
81
|
+
// client.reconnect = false // reconnect is private property
|
|
82
|
+
client.close(true);
|
|
83
|
+
}
|
|
84
|
+
reject(err);
|
|
85
|
+
});
|
|
86
|
+
client.onConnected(() => {
|
|
87
|
+
resolve(client);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return await subscriptionClient;
|
|
92
|
+
};
|
|
93
|
+
var subscriptions = [];
|
|
94
|
+
export const subscribe = async (request, subscribe) => {
|
|
95
|
+
var client = await getSubscriptionClient();
|
|
96
|
+
var { unsubscribe } = client.request(request).subscribe(subscribe);
|
|
97
|
+
subscriptions.push(unsubscribe);
|
|
98
|
+
return {
|
|
99
|
+
unsubscribe() {
|
|
100
|
+
subscriptions.splice(subscriptions.indexOf(unsubscribe), 1);
|
|
101
|
+
unsubscribe();
|
|
102
|
+
if (subscriptions.length == 0) {
|
|
103
|
+
client.unsubscribeAll();
|
|
104
|
+
client.close(true);
|
|
105
|
+
subscriptionClient = null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
//# sourceMappingURL=origin-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"origin-client.js","sourceRoot":"","sources":["../src/origin-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AACjF,OAAO,EAAiB,OAAO,EAAE,MAAM,2BAA2B,CAAA;AAGlE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAE/D,MAAM,cAAc,GAAmB;IACrC,UAAU,EAAE;QACV,WAAW,EAAE,UAAU;QACvB,WAAW,EAAE,QAAQ;KACtB;IACD,KAAK,EAAE;QACL,WAAW,EAAE,UAAU;QACvB,WAAW,EAAE,KAAK;KACnB;IACD,MAAM,EAAE;QACN,WAAW,EAAE,KAAK;KACnB;CACF,CAAA;AAED,MAAM,aAAa,GAAG,CAAC,EAAE,aAAa,EAAE,YAAY,EAAiB,EAAE,EAAE;IACvE,IAAI,aAAa,EA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A;gBAElB,kBAAkB,GAAG,IAAI,CAAA;aAC1B;QACH,CAAC;KACF,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { ApolloClient, HttpLink, InMemoryCache, from } from '@apollo/client/core'\nimport { ErrorResponse, onError } from '@apollo/client/link/error'\n\nimport { DefaultOptions } from '@apollo/client'\nimport { SubscriptionClient } from 'subscriptions-transport-ws'\n\nconst defaultOptions: DefaultOptions = {\n watchQuery: {\n fetchPolicy: 'no-cache',\n errorPolicy: 'ignore'\n },\n query: {\n fetchPolicy: 'no-cache', //'network-only'\n errorPolicy: 'all'\n },\n mutate: {\n errorPolicy: 'all'\n }\n}\n\nconst ERROR_HANDLER = ({ graphQLErrors, networkError }: ErrorResponse) => {\n if (graphQLErrors) {\n document.dispatchEvent(\n new CustomEvent('notify', {\n detail: {\n level: 'error',\n message: graphQLErrors[0].message,\n ex: graphQLErrors\n }\n })\n )\n }\n\n if (networkError) {\n const code = (networkError as any).statusCode || ''\n const message = `[Response-${code}]: ${networkError.message}`\n\n document.dispatchEvent(\n new CustomEvent('notify', {\n detail: {\n level: 'error',\n message,\n ex: networkError\n }\n })\n )\n }\n}\n\nvar client: ApolloClient<any>\n\nexport function getClient() {\n if (!client) {\n var cache = new InMemoryCache()\n client = new ApolloClient({\n defaultOptions,\n cache,\n link: from([\n onError(ERROR_HANDLER),\n new HttpLink({\n uri: '/graphql',\n credentials: 'include'\n })\n ])\n })\n }\n\n return client\n}\n\n/* SubscriptionClient */\nvar subscriptionClient: Promise<SubscriptionClient> | null\n\nconst getSubscriptionClient = async () => {\n if (!subscriptionClient) {\n subscriptionClient = new Promise((resolve, reject) => {\n var client = new SubscriptionClient(location.origin.replace(/^http/, 'ws') + '/subscriptions', {\n reconnect: true,\n connectionParams: {\n headers: {\n /* \n 특정 도메인의 데이타만 받고자 하는 경우에, referer 정보를 제공해서 서버에서 서브도메인 정보를 취득하도록 한다.\n referer: location.href\n 또는, 이미 서브도메인 정보를 알고 있다면,\n 'x-things-factory-domain': '[subdomain]'\n 을 보낼 수 있다.\n 관련 정보를 보내지 않는다면, 사용자가 권한을 가진 모든 도메인의 데이타를 수신하게 된다.\n */\n referer: location.href\n }\n }\n })\n\n client.onError(err => {\n //readyState === 3 인 경우 url을 잘 못 입력했거나, 서버에 문제가 있는 경우이므로 reconnect = false로 변경한다.\n if (client.status === 3) {\n // client.reconnect = false // reconnect is private property\n client.close(true)\n }\n reject(err)\n })\n\n client.onConnected(() => {\n resolve(client)\n })\n })\n }\n\n return await subscriptionClient\n}\n\nvar subscriptions: (() => void)[] = []\n\nexport const subscribe = async (request: any, subscribe: any) => {\n var client = await getSubscriptionClient()\n var { unsubscribe } = client.request(request).subscribe(subscribe)\n\n subscriptions.push(unsubscribe)\n\n return {\n unsubscribe() {\n subscriptions.splice(subscriptions.indexOf(unsubscribe), 1)\n unsubscribe()\n\n if (subscriptions.length == 0) {\n client.unsubscribeAll()\n client.close(true)\n\n subscriptionClient = null\n }\n }\n }\n}\n"]}
|