@norgate-av/react-crestron-ch5-hooks 1.0.0
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/LICENSE +21 -0
- package/README.md +914 -0
- package/dist/hooks/index.d.ts +18 -0
- package/dist/hooks/useCrestronAnalog/index.d.ts +11 -0
- package/dist/hooks/useCrestronAnalogCollection/index.d.ts +12 -0
- package/dist/hooks/useCrestronDigital/index.d.ts +11 -0
- package/dist/hooks/useCrestronDigitalCollection/index.d.ts +12 -0
- package/dist/hooks/useCrestronPublishAnalog/index.d.ts +9 -0
- package/dist/hooks/useCrestronPublishAnalogCollection/index.d.ts +10 -0
- package/dist/hooks/useCrestronPublishDigital/index.d.ts +9 -0
- package/dist/hooks/useCrestronPublishDigitalCollection/index.d.ts +10 -0
- package/dist/hooks/useCrestronPublishSerial/index.d.ts +9 -0
- package/dist/hooks/useCrestronPublishSerialCollection/index.d.ts +10 -0
- package/dist/hooks/useCrestronSerial/index.d.ts +11 -0
- package/dist/hooks/useCrestronSerialCollection/index.d.ts +12 -0
- package/dist/hooks/useCrestronSubscribeAnalog/index.d.ts +11 -0
- package/dist/hooks/useCrestronSubscribeAnalogCollection/index.d.ts +12 -0
- package/dist/hooks/useCrestronSubscribeDigital/index.d.ts +11 -0
- package/dist/hooks/useCrestronSubscribeDigitalCollection/index.d.ts +12 -0
- package/dist/hooks/useCrestronSubscribeSerial/index.d.ts +11 -0
- package/dist/hooks/useCrestronSubscribeSerialCollection/index.d.ts +12 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +8 -0
- package/dist/react-crestron-ch5-hooks.cjs.development.js +643 -0
- package/dist/react-crestron-ch5-hooks.cjs.development.js.map +1 -0
- package/dist/react-crestron-ch5-hooks.cjs.production.min.js +2 -0
- package/dist/react-crestron-ch5-hooks.cjs.production.min.js.map +1 -0
- package/dist/react-crestron-ch5-hooks.esm.js +602 -0
- package/dist/react-crestron-ch5-hooks.esm.js.map +1 -0
- package/dist/react-crestron-ch5-hooks.umd.development.js +645 -0
- package/dist/react-crestron-ch5-hooks.umd.development.js.map +1 -0
- package/dist/react-crestron-ch5-hooks.umd.production.min.js +2 -0
- package/dist/react-crestron-ch5-hooks.umd.production.min.js.map +1 -0
- package/dist/types/Analog/index.d.ts +1 -0
- package/dist/types/AnalogStateCallback/index.d.ts +3 -0
- package/dist/types/Digital/index.d.ts +1 -0
- package/dist/types/DigitalStateCallback/index.d.ts +3 -0
- package/dist/types/IAnalogEventAction/index.d.ts +4 -0
- package/dist/types/IAnalogSignal/index.d.ts +5 -0
- package/dist/types/IAnalogState/index.d.ts +4 -0
- package/dist/types/IBaseEventAction/index.d.ts +3 -0
- package/dist/types/IBaseSignal/index.d.ts +4 -0
- package/dist/types/IBaseState/index.d.ts +3 -0
- package/dist/types/IDigitalEventAction/index.d.ts +7 -0
- package/dist/types/IDigitalSignal/index.d.ts +5 -0
- package/dist/types/IDigitalState/index.d.ts +4 -0
- package/dist/types/ISerialEventAction/index.d.ts +4 -0
- package/dist/types/ISerialSignal/index.d.ts +5 -0
- package/dist/types/ISerialState/index.d.ts +4 -0
- package/dist/types/IStateSubscription/index.d.ts +4 -0
- package/dist/types/Serial/index.d.ts +1 -0
- package/dist/types/SerialStateCallback/index.d.ts +3 -0
- package/dist/types/StateCallback/index.d.ts +1 -0
- package/dist/types/index.d.ts +20 -0
- package/dist/utils/getSignalCollection.d.ts +3 -0
- package/dist/utils/index.d.ts +1 -0
- package/package.json +135 -0
package/README.md
ADDED
|
@@ -0,0 +1,914 @@
|
|
|
1
|
+
# React Crestron CH5 Hooks ⚓
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
<img src="./assets/logo.svg" alt="react-logo" width="200" />
|
|
5
|
+
<img src="./assets/crestron-ch5-logo.png" alt="ch5-logo" width="200" />
|
|
6
|
+
</div>
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
[](https://github.com/Norgate-AV-Solutions-Ltd/react-crestron-ch5-hooks/actions/workflows/main.yml)
|
|
11
|
+
[](https://codecov.io/gh/Norgate-AV-Solutions-Ltd/react-crestron-ch5-hooks)
|
|
12
|
+
[](https://coveralls.io/github/Norgate-AV-Solutions-Ltd/react-crestron-ch5-hooks?branch=develop)
|
|
13
|
+
[](https://conventionalcommits.org)
|
|
14
|
+
[](http://commitizen.github.io/cz-cli/)
|
|
15
|
+
[](#contributors)
|
|
16
|
+
[](https://www.npmjs.com/package/@norgate-av/react-crestron-ch5-hooks)
|
|
17
|
+
[](LICENSE)
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
A collection of React custom hooks ⚓ for Crestron CH5 project development.
|
|
22
|
+
|
|
23
|
+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
24
|
+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
25
|
+
|
|
26
|
+
## Contents 📖
|
|
27
|
+
|
|
28
|
+
- [Features :package:](#features-package)
|
|
29
|
+
- [Installation :zap:](#installation-zap)
|
|
30
|
+
- [Usage :rocket:](#usage-rocket)
|
|
31
|
+
- [Publish :arrow_right:](#publish-arrow_right)
|
|
32
|
+
- [useCrestronPublishAnalog](#usecrestronpublishanalog)
|
|
33
|
+
- [useCrestronPublishDigital](#usecrestronpublishdigital)
|
|
34
|
+
- [useCrestronPublishSerial](#usecrestronpublishserial)
|
|
35
|
+
- [useCrestronPublishAnalogCollection](#usecrestronpublishanalogcollection)
|
|
36
|
+
- [useCrestronPublishDigitalCollection](#usecrestronpublishdigitalcollection)
|
|
37
|
+
- [useCrestronPublishSerialCollection](#usecrestronpublishserialcollection)
|
|
38
|
+
- [Subscribe :arrow_left:](#subscribe-arrow_left)
|
|
39
|
+
- [useCrestronSubscribeAnalog](#usecrestronsubscribeanalog)
|
|
40
|
+
- [useCrestronSubscribeDigital](#usecrestronsubscribedigital)
|
|
41
|
+
- [useCrestronSubscribeSerial](#usecrestronsubscribeserial)
|
|
42
|
+
- [useCrestronSubscribeAnalogCollection](#usecrestronsubscribeanalogcollection)
|
|
43
|
+
- [useCrestronSubscribeDigitalCollection](#usecrestronsubscribedigitalcollection)
|
|
44
|
+
- [useCrestronSubscribeSerialCollection](#usecrestronsubscribeserialcollection)
|
|
45
|
+
- [Publish & Subscribe :left_right_arrow:](#publish--subscribe-left_right_arrow)
|
|
46
|
+
- [useCrestronAnalog](#usecrestronanalog)
|
|
47
|
+
- [useCrestronDigital](#usecrestrondigital)
|
|
48
|
+
- [useCrestronSerial](#usecrestronserial)
|
|
49
|
+
- [useCrestronAnalogCollection](#usecrestronanalogcollection)
|
|
50
|
+
- [useCrestronDigitalCollection](#usecrestrondigitalcollection)
|
|
51
|
+
- [useCrestronSerialCollection](#usecrestronserialcollection)
|
|
52
|
+
- [Optional Subscribe Callback :phone:](#optional-subscribe-callback-phone)
|
|
53
|
+
- [Types :keyboard:](#types-keyboard)
|
|
54
|
+
- [Aliases](#aliases)
|
|
55
|
+
- [Analog](#analog)
|
|
56
|
+
- [Digital](#digital)
|
|
57
|
+
- [Serial](#serial)
|
|
58
|
+
- [Event Actions](#event-actions)
|
|
59
|
+
- [IBaseEventAction](#ibaseeventaction)
|
|
60
|
+
- [IAnalogEventAction](#ianalogeventaction)
|
|
61
|
+
- [IDigitalEventAction](#idigitaleventaction)
|
|
62
|
+
- [ISerialEventAction](#iserialeventaction)
|
|
63
|
+
- [State](#state)
|
|
64
|
+
- [IBaseState](#ibasestate)
|
|
65
|
+
- [IAnalogState](#ianalogstate)
|
|
66
|
+
- [IDigitalState](#idigitalstate)
|
|
67
|
+
- [ISerialState](#iserialstate)
|
|
68
|
+
- [IStateSubscription](#istatesubscription)
|
|
69
|
+
- [StateCallback](#statecallback)
|
|
70
|
+
- [AnalogStateCallback](#analogstatecallback)
|
|
71
|
+
- [DigitalStateCallback](#digitalstatecallback)
|
|
72
|
+
- [SerialStateCallback](#serialstatecallback)
|
|
73
|
+
- [Signals](#signals)
|
|
74
|
+
- [IBaseSignal](#ibasesignal)
|
|
75
|
+
- [IAnalogSignal](#ianalogsignal)
|
|
76
|
+
- [IDigitalSignal](#idigitalsignal)
|
|
77
|
+
- [ISerialSignal](#iserialsignal)
|
|
78
|
+
- [Team :soccer:](#team-soccer)
|
|
79
|
+
- [Contributors :sparkles:](#contributors-sparkles)
|
|
80
|
+
- [LICENSE :balance_scale:](#license-balance_scale)
|
|
81
|
+
|
|
82
|
+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
|
83
|
+
|
|
84
|
+
## Features :package:
|
|
85
|
+
|
|
86
|
+
✅ Collection of 18 hooks
|
|
87
|
+
|
|
88
|
+
✅ CommonJS, UMD and ESM Support
|
|
89
|
+
|
|
90
|
+
✅ Built-in Type definitions for TypeScript
|
|
91
|
+
|
|
92
|
+
## Installation :zap:
|
|
93
|
+
|
|
94
|
+
```sh
|
|
95
|
+
npm install @norgate-av/react-crestron-ch5-hooks
|
|
96
|
+
|
|
97
|
+
# or
|
|
98
|
+
|
|
99
|
+
yarn add @norgate-av/react-crestron-ch5-hooks
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Usage :rocket:
|
|
103
|
+
|
|
104
|
+
### Publish :arrow_right:
|
|
105
|
+
|
|
106
|
+
#### useCrestronPublishAnalog
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
import { useCrestronPublishAnalog } from "@norgate-av/react-crestron-ch5-hooks";
|
|
110
|
+
|
|
111
|
+
export const SomeAwesomeComponent = () => {
|
|
112
|
+
const [action] = useCrestronPublishAnalog("some-analog-join-or-name");
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<div>
|
|
116
|
+
<h1>Analog Event Actions</h1>
|
|
117
|
+
<button onClick={() => action.setValue(666)}>Set Value</button>
|
|
118
|
+
</div>
|
|
119
|
+
);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export default SomeAwesomeComponent;
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
#### useCrestronPublishDigital
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
import { useCrestronPublishDigital } from "@norgate-av/react-crestron-ch5-hooks";
|
|
129
|
+
|
|
130
|
+
export const SomeAwesomeComponent = () => {
|
|
131
|
+
const [action] = useCrestronPublishDigital("some-digital-join-or-name");
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<div>
|
|
135
|
+
<h1>Digital Event Actions</h1>
|
|
136
|
+
<button
|
|
137
|
+
onTouchStart={() => action.setValue(true)}
|
|
138
|
+
onTouchEnd={() => action.setValue(false)}
|
|
139
|
+
>
|
|
140
|
+
Set Value
|
|
141
|
+
</button>
|
|
142
|
+
|
|
143
|
+
<button
|
|
144
|
+
onTouchStart={() => action.push()}
|
|
145
|
+
onTouchEnd={() => action.release()}
|
|
146
|
+
>
|
|
147
|
+
Push/Release
|
|
148
|
+
</button>
|
|
149
|
+
|
|
150
|
+
<button onClick={() => action.click()}>Click</button>
|
|
151
|
+
</div>
|
|
152
|
+
);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export default SomeAwesomeComponent;
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
#### useCrestronPublishSerial
|
|
159
|
+
|
|
160
|
+
```tsx
|
|
161
|
+
import { useCrestronPublishSerial } from "@norgate-av/react-crestron-ch5-hooks";
|
|
162
|
+
|
|
163
|
+
export const SomeAwesomeComponent = () => {
|
|
164
|
+
const [action] = useCrestronPublishSerial("some-serial-join-or-name");
|
|
165
|
+
|
|
166
|
+
return (
|
|
167
|
+
<div>
|
|
168
|
+
<h1>Serial Event Actions</h1>
|
|
169
|
+
<button onClick={() => action.setValue("cowbell")}>
|
|
170
|
+
Set Value
|
|
171
|
+
</button>
|
|
172
|
+
</div>
|
|
173
|
+
);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
export default SomeAwesomeComponent;
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
#### useCrestronPublishAnalogCollection
|
|
180
|
+
|
|
181
|
+
```tsx
|
|
182
|
+
import { useCrestronPublishAnalogCollection } from "@norgate-av/react-crestron-ch5-hooks";
|
|
183
|
+
|
|
184
|
+
export const SomeAwesomeComponent = () => {
|
|
185
|
+
const [action1, action2, action3] = useCrestronPublishAnalogCollection([
|
|
186
|
+
"some-analog-join-or-name",
|
|
187
|
+
"2",
|
|
188
|
+
"3",
|
|
189
|
+
]);
|
|
190
|
+
|
|
191
|
+
return (
|
|
192
|
+
<div>
|
|
193
|
+
<h1>Analog Event Actions Collection</h1>
|
|
194
|
+
<button onClick={() => action1.setValue(666)}>Set Value 1</button>
|
|
195
|
+
<button onClick={() => action2.setValue(666)}>Set Value 2</button>
|
|
196
|
+
<button onClick={() => action3.setValue(666)}>Set Value 3</button>
|
|
197
|
+
</div>
|
|
198
|
+
);
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
export default SomeAwesomeComponent;
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
#### useCrestronPublishDigitalCollection
|
|
205
|
+
|
|
206
|
+
```tsx
|
|
207
|
+
import { useCrestronPublishDigitalCollection } from "@norgate-av/react-crestron-ch5-hooks";
|
|
208
|
+
|
|
209
|
+
export const SomeAwesomeComponent = () => {
|
|
210
|
+
const [action1, action2, action3] = useCrestronPublishDigitalCollection([
|
|
211
|
+
"some-digital-join-or-name",
|
|
212
|
+
"2",
|
|
213
|
+
"3",
|
|
214
|
+
]);
|
|
215
|
+
|
|
216
|
+
return (
|
|
217
|
+
<div>
|
|
218
|
+
<h1>Digital Event Actions Collection</h1>
|
|
219
|
+
<button
|
|
220
|
+
onTouchStart={() => action1.setValue(true)}
|
|
221
|
+
onTouchEnd={() => action1.setValue(false)}
|
|
222
|
+
>
|
|
223
|
+
Set Value 1
|
|
224
|
+
</button>
|
|
225
|
+
|
|
226
|
+
<button
|
|
227
|
+
onTouchStart={() => action1.push()}
|
|
228
|
+
onTouchEnd={() => action1.release()}
|
|
229
|
+
>
|
|
230
|
+
Push/Release 1
|
|
231
|
+
</button>
|
|
232
|
+
|
|
233
|
+
<button onClick={() => action1.click()}>Click 1</button>
|
|
234
|
+
|
|
235
|
+
<button
|
|
236
|
+
onTouchStart={() => action2.setValue(true)}
|
|
237
|
+
onTouchEnd={() => action2.setValue(false)}
|
|
238
|
+
>
|
|
239
|
+
Set Value 2
|
|
240
|
+
</button>
|
|
241
|
+
|
|
242
|
+
<button
|
|
243
|
+
onTouchStart={() => action2.push()}
|
|
244
|
+
onTouchEnd={() => action2.release()}
|
|
245
|
+
>
|
|
246
|
+
Push/Release 2
|
|
247
|
+
</button>
|
|
248
|
+
|
|
249
|
+
<button onClick={() => action2.click()}>Click 2</button>
|
|
250
|
+
|
|
251
|
+
<button
|
|
252
|
+
onTouchStart={() => action3.setValue(true)}
|
|
253
|
+
onTouchEnd={() => action3.setValue(false)}
|
|
254
|
+
>
|
|
255
|
+
Set Value 3
|
|
256
|
+
</button>
|
|
257
|
+
|
|
258
|
+
<button
|
|
259
|
+
onTouchStart={() => action3.push()}
|
|
260
|
+
onTouchEnd={() => action3.release()}
|
|
261
|
+
>
|
|
262
|
+
Push/Release 3
|
|
263
|
+
</button>
|
|
264
|
+
<button onClick={() => action3.click()}>Click 3</button>
|
|
265
|
+
</div>
|
|
266
|
+
);
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
export default SomeAwesomeComponent;
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
#### useCrestronPublishSerialCollection
|
|
273
|
+
|
|
274
|
+
```tsx
|
|
275
|
+
import { useCrestronPublishSerialCollection } from "@norgate-av/react-crestron-ch5-hooks";
|
|
276
|
+
|
|
277
|
+
export const SomeAwesomeComponent = () => {
|
|
278
|
+
const [action1, action2, action3] = useCrestronPublishSerialCollection([
|
|
279
|
+
"some-serial-join-or-name",
|
|
280
|
+
"2",
|
|
281
|
+
"3",
|
|
282
|
+
]);
|
|
283
|
+
|
|
284
|
+
return (
|
|
285
|
+
<div>
|
|
286
|
+
<h1>Serial Event Actions Collection</h1>
|
|
287
|
+
<button onClick={() => action1.setValue("cowbell")}>
|
|
288
|
+
Set Value 1
|
|
289
|
+
</button>
|
|
290
|
+
|
|
291
|
+
<button onClick={() => action2.setValue("cowbell")}>
|
|
292
|
+
Set Value 2
|
|
293
|
+
</button>
|
|
294
|
+
|
|
295
|
+
<button
|
|
296
|
+
onClick={() =>
|
|
297
|
+
action3.setValue("That's enough cowbell for now!")
|
|
298
|
+
}
|
|
299
|
+
>
|
|
300
|
+
Set Value 3
|
|
301
|
+
</button>
|
|
302
|
+
</div>
|
|
303
|
+
);
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
export default SomeAwesomeComponent;
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### Subscribe :arrow_left:
|
|
310
|
+
|
|
311
|
+
#### useCrestronSubscribeAnalog
|
|
312
|
+
|
|
313
|
+
```tsx
|
|
314
|
+
import { useCrestronSubscribeAnalog } from "@norgate-av/react-crestron-ch5-hooks";
|
|
315
|
+
|
|
316
|
+
export const SomeAwesomeComponent = () => {
|
|
317
|
+
const [state] = useCrestronSubscribeAnalog("some-analog-join-or-name");
|
|
318
|
+
|
|
319
|
+
return (
|
|
320
|
+
<div>
|
|
321
|
+
<h1>Analog State</h1>
|
|
322
|
+
<h2>Value: {state.value}</h2>
|
|
323
|
+
</div>
|
|
324
|
+
);
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
export default SomeAwesomeComponent;
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
#### useCrestronSubscribeDigital
|
|
331
|
+
|
|
332
|
+
```tsx
|
|
333
|
+
import { useCrestronSubscribeDigital } from "@norgate-av/react-crestron-ch5-hooks";
|
|
334
|
+
|
|
335
|
+
export const SomeAwesomeComponent = () => {
|
|
336
|
+
const [state] = useCrestronSubscribeDigital("some-digital-join-or-name");
|
|
337
|
+
|
|
338
|
+
return (
|
|
339
|
+
<div>
|
|
340
|
+
<h1>Digital State</h1>
|
|
341
|
+
<h2>Value: {state.value ? "True" : "False"}</h2>
|
|
342
|
+
</div>
|
|
343
|
+
);
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
export default SomeAwesomeComponent;
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
#### useCrestronSubscribeSerial
|
|
350
|
+
|
|
351
|
+
```tsx
|
|
352
|
+
import { useCrestronSubscribeSerial } from "@norgate-av/react-crestron-ch5-hooks";
|
|
353
|
+
|
|
354
|
+
export const SomeAwesomeComponent = () => {
|
|
355
|
+
const [state] = useCrestronSubscribeSerial("some-serial-join-or-name");
|
|
356
|
+
|
|
357
|
+
return (
|
|
358
|
+
<div>
|
|
359
|
+
<h1>Serial State</h1>
|
|
360
|
+
<h2>Value: {state.value}</h2>
|
|
361
|
+
</div>
|
|
362
|
+
);
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
export default SomeAwesomeComponent;
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
#### useCrestronSubscribeAnalogCollection
|
|
369
|
+
|
|
370
|
+
```tsx
|
|
371
|
+
import { useCrestronSubscribeAnalogCollection } from "@norgate-av/react-crestron-ch5-hooks";
|
|
372
|
+
|
|
373
|
+
export const SomeAwesomeComponent = () => {
|
|
374
|
+
const [state1, state2, state3] = useCrestronSubscribeAnalogCollection([
|
|
375
|
+
"some-analog-join-or-name",
|
|
376
|
+
"2",
|
|
377
|
+
"3",
|
|
378
|
+
]);
|
|
379
|
+
|
|
380
|
+
return (
|
|
381
|
+
<div>
|
|
382
|
+
<h1>Analog State Collection</h1>
|
|
383
|
+
<h2>Value 1: {state1.value}</h2>
|
|
384
|
+
<h2>Value 2: {state2.value}</h2>
|
|
385
|
+
<h2>Value 3: {state3.value}</h2>
|
|
386
|
+
</div>
|
|
387
|
+
);
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
export default SomeAwesomeComponent;
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
#### useCrestronSubscribeDigitalCollection
|
|
394
|
+
|
|
395
|
+
```tsx
|
|
396
|
+
import { useCrestronSubscribeDigitalCollection } from "@norgate-av/react-crestron-ch5-hooks";
|
|
397
|
+
|
|
398
|
+
export const SomeAwesomeComponent = () => {
|
|
399
|
+
const [state1, state2, state3] = useCrestronSubscribeDigitalCollection([
|
|
400
|
+
"some-digital-join-or-name",
|
|
401
|
+
"2",
|
|
402
|
+
"3",
|
|
403
|
+
]);
|
|
404
|
+
|
|
405
|
+
return (
|
|
406
|
+
<div>
|
|
407
|
+
<h1>Digital State Collection</h1>
|
|
408
|
+
<h2>Value 1: {state1.value ? "True" : "False"}</h2>
|
|
409
|
+
<h2>Value 2: {state2.value ? "True" : "False"}</h2>
|
|
410
|
+
<h2>Value 3: {state3.value ? "True" : "False"}</h2>
|
|
411
|
+
</div>
|
|
412
|
+
);
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
export default SomeAwesomeComponent;
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
#### useCrestronSubscribeSerialCollection
|
|
419
|
+
|
|
420
|
+
```tsx
|
|
421
|
+
import { useCrestronSubscribeSerialCollection } from "@norgate-av/react-crestron-ch5-hooks";
|
|
422
|
+
|
|
423
|
+
export const SomeAwesomeComponent = () => {
|
|
424
|
+
const [state1, state2, state3] = useCrestronSubscribeSerialCollection([
|
|
425
|
+
"some-serial-join-or-name",
|
|
426
|
+
"2",
|
|
427
|
+
"3",
|
|
428
|
+
]);
|
|
429
|
+
|
|
430
|
+
return (
|
|
431
|
+
<div>
|
|
432
|
+
<h1>Serial State Collection</h1>
|
|
433
|
+
<h2>Value 1: {state1.value}</h2>
|
|
434
|
+
<h2>Value 2: {state2.value}</h2>
|
|
435
|
+
<h2>Value 3: {state3.value}</h2>
|
|
436
|
+
</div>
|
|
437
|
+
);
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
export default SomeAwesomeComponent;
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
### Publish & Subscribe :left_right_arrow:
|
|
444
|
+
|
|
445
|
+
#### useCrestronAnalog
|
|
446
|
+
|
|
447
|
+
```tsx
|
|
448
|
+
import { useCrestronAnalog } from "@norgate-av/react-crestron-ch5-hooks";
|
|
449
|
+
|
|
450
|
+
export const SomeAwesomeComponent = () => {
|
|
451
|
+
const [signal] = useCrestronAnalog("some-analog-join-or-name");
|
|
452
|
+
|
|
453
|
+
return (
|
|
454
|
+
<div>
|
|
455
|
+
<h1>Analog Signal</h1>
|
|
456
|
+
<h2>Value: {signal.state.value}</h2>
|
|
457
|
+
|
|
458
|
+
<button onClick={() => signal.action.setValue(666)}>
|
|
459
|
+
Set Value
|
|
460
|
+
</button>
|
|
461
|
+
</div>
|
|
462
|
+
);
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
export default SomeAwesomeComponent;
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
#### useCrestronDigital
|
|
469
|
+
|
|
470
|
+
```tsx
|
|
471
|
+
import { useCrestronDigital } from "@norgate-av/react-crestron-ch5-hooks";
|
|
472
|
+
|
|
473
|
+
export const SomeAwesomeComponent = () => {
|
|
474
|
+
const [signal] = useCrestronDigital("some-digital-join-or-name");
|
|
475
|
+
|
|
476
|
+
return (
|
|
477
|
+
<div>
|
|
478
|
+
<h1>Digital Signal</h1>
|
|
479
|
+
<h2>Value: {signal.state.value ? "True" : "False"}</h2>
|
|
480
|
+
|
|
481
|
+
<button
|
|
482
|
+
onTouchStart={() => signal.action.setValue(true)}
|
|
483
|
+
onTouchEnd={() => signal.action.setValue(false)}
|
|
484
|
+
>
|
|
485
|
+
Set Value
|
|
486
|
+
</button>
|
|
487
|
+
|
|
488
|
+
<button
|
|
489
|
+
onTouchStart={() => signal.action.push()}
|
|
490
|
+
onTouchEnd={() => signal.action.release()}
|
|
491
|
+
>
|
|
492
|
+
Push/Release
|
|
493
|
+
</button>
|
|
494
|
+
|
|
495
|
+
<button onClick={() => signal.action.click()}>Click</button>
|
|
496
|
+
</div>
|
|
497
|
+
);
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
export default SomeAwesomeComponent;
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
#### useCrestronSerial
|
|
504
|
+
|
|
505
|
+
```tsx
|
|
506
|
+
import { useCrestronSerial } from "@norgate-av/react-crestron-ch5-hooks";
|
|
507
|
+
|
|
508
|
+
export const SomeAwesomeComponent = () => {
|
|
509
|
+
const [signal] = useCrestronSerial("some-serial-join-or-name");
|
|
510
|
+
|
|
511
|
+
return (
|
|
512
|
+
<div>
|
|
513
|
+
<h1>Serial Signal</h1>
|
|
514
|
+
<h2>Value: {signal.state.value}</h2>
|
|
515
|
+
|
|
516
|
+
<button onClick={() => signal.action.setValue("cowbell")}>
|
|
517
|
+
Set Value
|
|
518
|
+
</button>
|
|
519
|
+
</div>
|
|
520
|
+
);
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
export default SomeAwesomeComponent;
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
#### useCrestronAnalogCollection
|
|
527
|
+
|
|
528
|
+
```tsx
|
|
529
|
+
import { useCrestronAnalogCollection } from "@norgate-av/react-crestron-ch5-hooks";
|
|
530
|
+
|
|
531
|
+
export const SomeAwesomeComponent = () => {
|
|
532
|
+
const [signal1, signal2, signal3] = useCrestronAnalogCollection([
|
|
533
|
+
"some-analog-join-or-name",
|
|
534
|
+
"2",
|
|
535
|
+
"3",
|
|
536
|
+
]);
|
|
537
|
+
|
|
538
|
+
return (
|
|
539
|
+
<div>
|
|
540
|
+
<h1>Analog Signal Collection</h1>
|
|
541
|
+
<h2>Value 1: {signal1.state.value}</h2>
|
|
542
|
+
<h2>Value 2: {signal2.state.value}</h2>
|
|
543
|
+
<h2>Value 3: {signal3.state.value}</h2>
|
|
544
|
+
|
|
545
|
+
<button onClick={() => signal1.action.setValue(666)}>
|
|
546
|
+
Set Value 1
|
|
547
|
+
</button>
|
|
548
|
+
|
|
549
|
+
<button onClick={() => signal2.action.setValue(666)}>
|
|
550
|
+
Set Value 2
|
|
551
|
+
</button>
|
|
552
|
+
|
|
553
|
+
<button onClick={() => signal3.action.setValue(666)}>
|
|
554
|
+
Set Value 3
|
|
555
|
+
</button>
|
|
556
|
+
</div>
|
|
557
|
+
);
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
export default SomeAwesomeComponent;
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
#### useCrestronDigitalCollection
|
|
564
|
+
|
|
565
|
+
```tsx
|
|
566
|
+
import { useCrestronDigitalCollection } from "@norgate-av/react-crestron-ch5-hooks";
|
|
567
|
+
|
|
568
|
+
export const SomeAwesomeComponent = () => {
|
|
569
|
+
const [signal1, signal2, signal3] = useCrestronDigitalCollection([
|
|
570
|
+
"some-digital-join-or-name",
|
|
571
|
+
"2",
|
|
572
|
+
"3",
|
|
573
|
+
]);
|
|
574
|
+
|
|
575
|
+
return (
|
|
576
|
+
<div>
|
|
577
|
+
<h1>Digital Signal Collection</h1>
|
|
578
|
+
<h2>Value 1: {signal1.state.value ? "True" : "False"}</h2>
|
|
579
|
+
<h2>Value 2: {signal2.state.value ? "True" : "False"}</h2>
|
|
580
|
+
<h2>Value 3: {signal3.state.value ? "True" : "False"}</h2>
|
|
581
|
+
|
|
582
|
+
<button
|
|
583
|
+
onTouchStart={() => signal1.action.setValue(true)}
|
|
584
|
+
onTouchEnd={() => signal1.action.setValue(false)}
|
|
585
|
+
>
|
|
586
|
+
Set Value 1
|
|
587
|
+
</button>
|
|
588
|
+
|
|
589
|
+
<button
|
|
590
|
+
onTouchStart={() => signal1.action.push()}
|
|
591
|
+
onTouchEnd={() => signal1.action.release()}
|
|
592
|
+
>
|
|
593
|
+
Push/Release 1
|
|
594
|
+
</button>
|
|
595
|
+
|
|
596
|
+
<button onClick={() => signal1.action.click()}>Click 1</button>
|
|
597
|
+
|
|
598
|
+
<button
|
|
599
|
+
onTouchStart={() => signal2.action.setValue(true)}
|
|
600
|
+
onTouchEnd={() => signal2.action.setValue(false)}
|
|
601
|
+
>
|
|
602
|
+
Set Value 2
|
|
603
|
+
</button>
|
|
604
|
+
|
|
605
|
+
<button
|
|
606
|
+
onTouchStart={() => signal2.action.push()}
|
|
607
|
+
onTouchEnd={() => signal2.action.release()}
|
|
608
|
+
>
|
|
609
|
+
Push/Release 2
|
|
610
|
+
</button>
|
|
611
|
+
|
|
612
|
+
<button onClick={() => signal2.action.click()}>Click 2</button>
|
|
613
|
+
|
|
614
|
+
<button
|
|
615
|
+
onTouchStart={() => signal3.action.setValue(true)}
|
|
616
|
+
onTouchEnd={() => signal3.action.setValue(false)}
|
|
617
|
+
>
|
|
618
|
+
Set Value 3
|
|
619
|
+
</button>
|
|
620
|
+
|
|
621
|
+
<button
|
|
622
|
+
onTouchStart={() => signal3.action.push()}
|
|
623
|
+
onTouchEnd={() => signal3.action.release()}
|
|
624
|
+
>
|
|
625
|
+
Push/Release 3
|
|
626
|
+
</button>
|
|
627
|
+
<button onClick={() => signal3.action.click()}>Click 3</button>
|
|
628
|
+
</div>
|
|
629
|
+
);
|
|
630
|
+
};
|
|
631
|
+
|
|
632
|
+
export default SomeAwesomeComponent;
|
|
633
|
+
```
|
|
634
|
+
|
|
635
|
+
#### useCrestronSerialCollection
|
|
636
|
+
|
|
637
|
+
```tsx
|
|
638
|
+
import { useCrestronSerialCollection } from "@norgate-av/react-crestron-ch5-hooks";
|
|
639
|
+
|
|
640
|
+
export const SomeAwesomeComponent = () => {
|
|
641
|
+
const [signal1, signal2, signal3] = useCrestronSerialCollection([
|
|
642
|
+
"some-serial-join-or-name",
|
|
643
|
+
"2",
|
|
644
|
+
"3",
|
|
645
|
+
]);
|
|
646
|
+
|
|
647
|
+
return (
|
|
648
|
+
<div>
|
|
649
|
+
<h1>Serial Signal Collection</h1>
|
|
650
|
+
<h2>Value 1: {signal1.state.value}</h2>
|
|
651
|
+
<h2>Value 2: {signal2.state.value}</h2>
|
|
652
|
+
<h2>Value 3: {signal3.state.value}</h2>
|
|
653
|
+
|
|
654
|
+
<button onClick={() => action1.setValue("cowbell")}>
|
|
655
|
+
Set Value 1
|
|
656
|
+
</button>
|
|
657
|
+
|
|
658
|
+
<button onClick={() => action2.setValue("cowbell")}>
|
|
659
|
+
Set Value 2
|
|
660
|
+
</button>
|
|
661
|
+
|
|
662
|
+
<button
|
|
663
|
+
onClick={() =>
|
|
664
|
+
action3.setValue("That's enough cowbell for now!")
|
|
665
|
+
}
|
|
666
|
+
>
|
|
667
|
+
Set Value 3
|
|
668
|
+
</button>
|
|
669
|
+
</div>
|
|
670
|
+
);
|
|
671
|
+
};
|
|
672
|
+
|
|
673
|
+
export default SomeAwesomeComponent;
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
### Optional Subscribe Callback :phone:
|
|
677
|
+
|
|
678
|
+
All hooks that subscribe to state can be passed an optional [callback](#statecallback) to be called when the state changes.
|
|
679
|
+
|
|
680
|
+
```tsx
|
|
681
|
+
import { useCrestronSubscribeAnalogCollection } from "@norgate-av/react-crestron-ch5-hooks";
|
|
682
|
+
|
|
683
|
+
export const SomeAwesomeComponent = () => {
|
|
684
|
+
const [state1, state2, state3] = useCrestronSubscribeAnalogCollection(
|
|
685
|
+
["some-analog-join-or-name", "2", "3"],
|
|
686
|
+
(value, signalName) => {
|
|
687
|
+
console.log(`Signal: ${signalName}, New Value: ${value}`);
|
|
688
|
+
},
|
|
689
|
+
);
|
|
690
|
+
|
|
691
|
+
return (
|
|
692
|
+
<div>
|
|
693
|
+
<h1>Analog State Collection</h1>
|
|
694
|
+
<h2>Value 1: {state1.value}</h2>
|
|
695
|
+
<h2>Value 2: {state2.value}</h2>
|
|
696
|
+
<h2>Value 3: {state3.value}</h2>
|
|
697
|
+
</div>
|
|
698
|
+
);
|
|
699
|
+
};
|
|
700
|
+
|
|
701
|
+
export default SomeAwesomeComponent;
|
|
702
|
+
```
|
|
703
|
+
|
|
704
|
+
The `signalName` parameter on the [callback](#statecallback) is also optional and can be omitted if you only have one signal.
|
|
705
|
+
|
|
706
|
+
```tsx
|
|
707
|
+
import { useCrestronSubscribeAnalog } from "@norgate-av/react-crestron-ch5-hooks";
|
|
708
|
+
|
|
709
|
+
export const SomeAwesomeComponent = () => {
|
|
710
|
+
const [state] = useCrestronSubscribeAnalog(
|
|
711
|
+
"some-analog-join-or-name",
|
|
712
|
+
(value) => {
|
|
713
|
+
console.log(`New Value: ${value}`);
|
|
714
|
+
},
|
|
715
|
+
);
|
|
716
|
+
|
|
717
|
+
return (
|
|
718
|
+
<div>
|
|
719
|
+
<h1>Analog State</h1>
|
|
720
|
+
<h2>Value: {state.value}</h2>
|
|
721
|
+
</div>
|
|
722
|
+
);
|
|
723
|
+
};
|
|
724
|
+
|
|
725
|
+
export default SomeAwesomeComponent;
|
|
726
|
+
```
|
|
727
|
+
|
|
728
|
+
## Types :keyboard:
|
|
729
|
+
|
|
730
|
+
### Aliases
|
|
731
|
+
|
|
732
|
+
#### Analog
|
|
733
|
+
|
|
734
|
+
```ts
|
|
735
|
+
export declare type Analog = number;
|
|
736
|
+
```
|
|
737
|
+
|
|
738
|
+
#### Digital
|
|
739
|
+
|
|
740
|
+
```ts
|
|
741
|
+
export declare type Digital = boolean;
|
|
742
|
+
```
|
|
743
|
+
|
|
744
|
+
#### Serial
|
|
745
|
+
|
|
746
|
+
```ts
|
|
747
|
+
export declare type Serial = string;
|
|
748
|
+
```
|
|
749
|
+
|
|
750
|
+
### Event Actions
|
|
751
|
+
|
|
752
|
+
#### IBaseEventAction
|
|
753
|
+
|
|
754
|
+
```ts
|
|
755
|
+
export declare interface IBaseEventAction<T> {
|
|
756
|
+
setValue: (value: T) => void;
|
|
757
|
+
}
|
|
758
|
+
```
|
|
759
|
+
|
|
760
|
+
#### IAnalogEventAction
|
|
761
|
+
|
|
762
|
+
```ts
|
|
763
|
+
export declare interface IAnalogEventAction extends IBaseEventAction<Analog> {}
|
|
764
|
+
```
|
|
765
|
+
|
|
766
|
+
#### IDigitalEventAction
|
|
767
|
+
|
|
768
|
+
```ts
|
|
769
|
+
export declare interface IDigitalEventAction extends IBaseEventAction<Digital> {
|
|
770
|
+
push: () => void;
|
|
771
|
+
release: () => void;
|
|
772
|
+
click: () => void;
|
|
773
|
+
}
|
|
774
|
+
```
|
|
775
|
+
|
|
776
|
+
#### ISerialEventAction
|
|
777
|
+
|
|
778
|
+
```ts
|
|
779
|
+
export declare interface ISerialEventAction extends IBaseEventAction<Serial> {}
|
|
780
|
+
```
|
|
781
|
+
|
|
782
|
+
### State
|
|
783
|
+
|
|
784
|
+
#### IBaseState
|
|
785
|
+
|
|
786
|
+
```ts
|
|
787
|
+
export declare interface IBaseState<T> {
|
|
788
|
+
value: T;
|
|
789
|
+
}
|
|
790
|
+
```
|
|
791
|
+
|
|
792
|
+
#### IAnalogState
|
|
793
|
+
|
|
794
|
+
```ts
|
|
795
|
+
export declare interface IAnalogState extends IBaseState<Analog> {}
|
|
796
|
+
```
|
|
797
|
+
|
|
798
|
+
#### IDigitalState
|
|
799
|
+
|
|
800
|
+
```ts
|
|
801
|
+
export declare interface IDigitalState extends IBaseState<Digital> {}
|
|
802
|
+
```
|
|
803
|
+
|
|
804
|
+
#### ISerialState
|
|
805
|
+
|
|
806
|
+
```ts
|
|
807
|
+
export declare interface ISerialState extends IBaseState<Serial> {}
|
|
808
|
+
```
|
|
809
|
+
|
|
810
|
+
#### IStateSubscription
|
|
811
|
+
|
|
812
|
+
```ts
|
|
813
|
+
export declare interface IStateSubscription {
|
|
814
|
+
id: string;
|
|
815
|
+
signalName: string;
|
|
816
|
+
}
|
|
817
|
+
```
|
|
818
|
+
|
|
819
|
+
#### StateCallback
|
|
820
|
+
|
|
821
|
+
```ts
|
|
822
|
+
export declare type StateCallback<T> = (value: T, signalName?: string) => void;
|
|
823
|
+
```
|
|
824
|
+
|
|
825
|
+
#### AnalogStateCallback
|
|
826
|
+
|
|
827
|
+
```ts
|
|
828
|
+
export declare type AnalogStateCallback = StateCallback<Analog>;
|
|
829
|
+
```
|
|
830
|
+
|
|
831
|
+
#### DigitalStateCallback
|
|
832
|
+
|
|
833
|
+
```ts
|
|
834
|
+
export declare type DigitalStateCallback = StateCallback<Digital>;
|
|
835
|
+
```
|
|
836
|
+
|
|
837
|
+
#### SerialStateCallback
|
|
838
|
+
|
|
839
|
+
```ts
|
|
840
|
+
export declare type SerialStateCallback = StateCallback<Serial>;
|
|
841
|
+
```
|
|
842
|
+
|
|
843
|
+
### Signals
|
|
844
|
+
|
|
845
|
+
#### IBaseSignal
|
|
846
|
+
|
|
847
|
+
```ts
|
|
848
|
+
export declare interface IBaseSignal<TState, TAction> {
|
|
849
|
+
state: TState;
|
|
850
|
+
action: TAction;
|
|
851
|
+
}
|
|
852
|
+
```
|
|
853
|
+
|
|
854
|
+
#### IAnalogSignal
|
|
855
|
+
|
|
856
|
+
```ts
|
|
857
|
+
export declare interface IAnalogSignal
|
|
858
|
+
extends IBaseSignal<IAnalogState, IAnalogEventAction> {}
|
|
859
|
+
```
|
|
860
|
+
|
|
861
|
+
#### IDigitalSignal
|
|
862
|
+
|
|
863
|
+
```ts
|
|
864
|
+
export declare interface IDigitalSignal
|
|
865
|
+
extends IBaseSignal<IDigitalState, IDigitalEventAction> {}
|
|
866
|
+
```
|
|
867
|
+
|
|
868
|
+
#### ISerialSignal
|
|
869
|
+
|
|
870
|
+
```ts
|
|
871
|
+
export declare interface ISerialSignal
|
|
872
|
+
extends IBaseSignal<ISerialState, ISerialEventAction> {}
|
|
873
|
+
```
|
|
874
|
+
|
|
875
|
+
## Team :soccer:
|
|
876
|
+
|
|
877
|
+
This project is maintained by the following person(s) and a bunch of [awesome contributors](https://github.com/Norgate-AV-Solutions-Ltd/react-crestron-ch5-hooks/graphs/contributors).
|
|
878
|
+
|
|
879
|
+
<table>
|
|
880
|
+
<tr>
|
|
881
|
+
<td align="center"><a href="https://github.com/damienbutt"><img src="https://avatars.githubusercontent.com/damienbutt?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Damien Butt</b></sub></a><br /></td>
|
|
882
|
+
</tr>
|
|
883
|
+
</table>
|
|
884
|
+
|
|
885
|
+
## Contributors :sparkles:
|
|
886
|
+
|
|
887
|
+
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
888
|
+
|
|
889
|
+
[](#contributors-)
|
|
890
|
+
|
|
891
|
+
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
892
|
+
|
|
893
|
+
Thanks go to these awesome people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
|
894
|
+
|
|
895
|
+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
|
896
|
+
<!-- prettier-ignore-start -->
|
|
897
|
+
<!-- markdownlint-disable -->
|
|
898
|
+
<table>
|
|
899
|
+
<tr>
|
|
900
|
+
<td align="center"><a href="https://github.com/features/security"><img src="https://avatars.githubusercontent.com/u/27347476?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Dependabot</b></sub></a><br /><a href="#maintenance-dependabot" title="Maintenance">🚧</a></td>
|
|
901
|
+
</tr>
|
|
902
|
+
</table>
|
|
903
|
+
|
|
904
|
+
<!-- markdownlint-restore -->
|
|
905
|
+
<!-- prettier-ignore-end -->
|
|
906
|
+
|
|
907
|
+
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
908
|
+
|
|
909
|
+
This project follows the [all-contributors](https://allcontributors.org) specification.
|
|
910
|
+
Contributions of any kind are welcome!
|
|
911
|
+
|
|
912
|
+
## LICENSE :balance_scale:
|
|
913
|
+
|
|
914
|
+
[MIT](LICENSE)
|