forked from NRCHKB/node-red-contrib-homekit-bridged
-
Notifications
You must be signed in to change notification settings - Fork 0
/
homekit.html
788 lines (741 loc) · 33.9 KB
/
homekit.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
<script type="text/x-red" data-template-name="homekit-service">
<div class="form-row">
<label for="node-config-input-isParent"><i class="fa fa-tasks"></i> Service Hierarchy</label>
<select id="node-config-input-isParent">
<option value="true" selected="selected">Parent</option>
<option value="false">Linked</option>
</select>
</div>
<div id="isParent">
<div class="form-row">
<label for="node-input-bridge">
<i class="fa fa-rocket"></i>
Bridge</label>
<input id="node-input-bridge">
</div>
<div class="form-row">
<label for="node-input-accessoryCategory">
<i class="fa fa-cog"></i>
Accessory Category</label>
<select id="node-input-accessoryCategory">
<option value="">Choose...</option>
</select>
</div>
</div>
<div id="isLinked" style="display: none;">
<div class="form-row">
<label for="node-input-parentService">
<i class="fa fa-cog"></i>
Parent Service</label>
<select id="node-input-parentService">
<option value="">Choose...</option>
</select>
</div>
</div>
<div class="form-row">
<label for="node-input-serviceName">
<i class="fa fa-cog"></i>
Service</label>
<select id="node-input-serviceName">
<option value="">Choose...</option>
</select>
</div>
<div class="form-row">
<label for="node-input-topic"><i class="fa fa-tasks"></i> Topic</label>
<input type="text" id="node-input-topic" placeholder="Topic">
</div>
<div class="form-row">
<label> </label>
<input type="checkbox" id="node-input-filter" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-filter" style="width: 70%;"> <i class="fa fa-filter"></i> Filter on Topic</label>
</div>
<div class="form-row">
<label for="node-input-manufacturer"><i class="fa fa-wrench"></i> Manufacturer</label>
<input type="text" id="node-input-manufacturer" placeholder="Manufacturer">
</div>
<div class="form-row">
<label for="node-input-serialNo"><i class="fa fa-wrench"></i> Serial Number</label>
<input type="text" id="node-input-serialNo" placeholder="Serial Number">
</div>
<div class="form-row">
<label for="node-input-model"><i class="fa fa-wrench"></i> Model</label>
<input type="text" id="node-input-model" placeholder="Model">
</div>
<div class="form-row">
<label for="node-input-name">
<i class="fa fa-tag"></i>
Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div id="camera-configuration" style="display: none;">
<label> <i class="fa fa-video-camera"></i> Camera Configuration</label>
<div class="form-row">
<label for="node-input-cameraConfigVideoProcessor"><i class="fa fa-cog"></i> Video Processor</label>
<input type="text" id="node-input-cameraConfigVideoProcessor" placeholder="ffmpeg">
</div>
<div class="form-row">
<label for="node-input-cameraConfigSource"><i class="fa fa-tint"></i> Source</label>
<input type="text" id="node-input-cameraConfigSource" placeholder="">
</div>
<div class="form-row">
<label for="node-input-cameraConfigStillImageSource"><i class="fa fa-picture-o"></i> Still Image Source</label>
<input type="text" id="node-input-cameraConfigStillImageSource" placeholder="">
</div>
<div class="form-row">
<label for="node-input-cameraConfigMaxStreams"><i class="fa fa-tint"></i> Max Streams</label>
<input type="text" id="node-input-cameraConfigMaxStreams" placeholder="">
</div>
<div class="form-row">
<label for="node-input-cameraConfigMaxWidth"><i class="fa fa-text-width"></i> Max Width</label>
<input type="text" id="node-input-cameraConfigMaxWidth" placeholder="">
</div>
<div class="form-row">
<label for="node-input-cameraConfigMaxHeight"><i class="fa fa-text-height"></i> Max Height</label>
<input type="text" id="node-input-cameraConfigMaxHeight" placeholder="">
</div>
<div class="form-row">
<label for="node-input-cameraConfigMaxFPS"><i class="fa fa-clock-o"></i> Max FPS</label>
<input type="text" id="node-input-cameraConfigMaxFPS" placeholder="">
</div>
<div class="form-row">
<label for="node-input-cameraConfigMaxBitrate"><i class="fa fa-clock-o"></i> Max Bitrate</label>
<input type="text" id="node-input-cameraConfigMaxBitrate" placeholder="">
</div>
<div class="form-row">
<label for="node-input-cameraConfigVideoCodec"><i class="fa fa-video-camera"></i> Video Codec</label>
<input type="text" id="node-input-cameraConfigVideoCodec" placeholder="">
</div>
<div class="form-row">
<label for="node-input-cameraConfigAudioCodec"><i class="fa fa-video-camera"></i> Audio Codec</label>
<input type="text" id="node-input-cameraConfigAudioCodec" placeholder="">
</div>
<div class="form-row">
<label for="node-input-cameraConfigAudio"><i class="fa fa-headphones"></i> Audio</label>
<input type="checkbox" id="node-input-cameraConfigAudio">
</div>
<div class="form-row">
<label for="node-input-cameraConfigPacketSize"><i class="fa fa-get-pocket"></i> Packet Size</label>
<input type="text" id="node-input-cameraConfigPacketSize" placeholder="">
</div>
<div class="form-row">
<label for="node-input-cameraConfigVerticalFlip"><i class="fa fa-undo"></i> Vertical Flip</label>
<input type="checkbox" id="node-input-cameraConfigVerticalFlip">
</div>
<div class="form-row">
<label for="node-input-cameraConfigHorizontalFlip"><i class="fa fa-undo"></i> Horizontal Flip</label>
<input type="checkbox" id="node-input-cameraConfigHorizontalFlip">
</div>
<div class="form-row">
<label for="node-input-cameraConfigMapVideo"><i class="fa fa-video-camera"></i> Map Video</label>
<input type="text" id="node-input-cameraConfigMapVideo" placeholder="">
</div>
<div class="form-row">
<label for="node-input-cameraConfigMapAudio"><i class="fa fa-headphones"></i> Map Audio</label>
<input type="text" id="node-input-cameraConfigMapAudio" placeholder="">
</div>
<div class="form-row">
<label for="node-input-cameraConfigVideoFilter"><i class="fa fa-filter"></i> Video Filter</label>
<input type="text" id="node-input-cameraConfigVideoFilter" placeholder="">
</div>
<div class="form-row">
<label for="node-input-cameraConfigAdditionalCommandLine"><i class="fa fa-plus"></i> Additional Command Line</label>
<input type="text" id="node-input-cameraConfigAdditionalCommandLine" placeholder="">
</div>
<div class="form-row">
<label for="node-input-cameraConfigDebug"><i class="fa fa-bug"></i> Debug</label>
<input type="checkbox" id="node-input-cameraConfigDebug">
</div>
<div class="form-row">
<label for="node-input-cameraConfigSnapshotOutput"><i class="fa fa-picture-o"></i> Snapshot output</label>
<select id="node-input-cameraConfigSnapshotOutput">
<option value="disabled" selected="selected">Disabled</option>
<option value="path">Path</option>
<option value="content">Content</option>
</select>
</div>
</div>
<div class="form-row" style="margin-bottom: 0px;">
<label for="node-input-characteristicProperties" style="width: 100% !important;">
<i class="fa fa-wrench"></i>
Characteristic Properties</label>
<input type="hidden" id="node-input-characteristicProperties">
</div>
<div class="form-row node-text-editor-row">
<div style="height: 250px; min-height:150px;" class="node-text-editor" id="node-input-characteristicProperties-editor"></div>
</div>
</script>
<script type="text/x-red" data-help-name="homekit-service">
<h3 id="toc_5">Service</h3>
<p>The Service node represents the single device you want to control or query.</p>
<p>Every service node creates its own HAP accessory to keep things simple.</p>
<ul>
<li><strong>Service Hierarchy</strong>: Choose if this Service is Parent or Linked</li>
<ul>
<li>Parent has <strong>Bridge</strong> and <strong>Accessory Category</strong>: On what Bridge to host this Service and its Accessory and what kind of category is this Accessory, default <em>OTHER</em></li>
<li>Linked has <strong>Parent Service</strong>: On what Parent Service link this Service.</li>
</ul>
<li><strong>Topic</strong>: An optional property that can be configured in the node or, if left blank, can be set by <code>msg.topic</code>. If <em>Filter on Topic</em> is selected <code>msg.topic</code> of incoming messages must match the configured
value for the message to be accepted. If <em>Filter on Topic</em> is selected and no <em>Topic</em> is set on the node, then <code>msg.topic</code> must match the nodes <em>Name</em></li>
<li><strong>Manufacturer, Model, Serial Number</strong>: Can be anything you want.</li>
<li><strong>Service</strong>: Choose the type of Service from the list.</li>
<li><strong>Name</strong>: <em>optional</em></li>
<li><strong>Camera Configuration</strong>: Additional configuration for CameraControl service.</li>
<ul>
<li><strong>Video Processor</strong>: Video processor used for Camera. Default is <em>ffmpeg</em>.</li>
<li><strong>Source</strong>: Camera source used for video processor. Example for ffmpeg <em>-re -i rtsp://192.168.0.227:8554/unicast</em></li>
<li><strong>Still Image Source</strong>: Camera snapshot source used for video processor. Example for ffmpeg <em>-i http://faster_still_image_grab_url/this_is_optional.jpg</em></li>
<li><strong>Max Streams</strong>: Maximum number of streams that will be generated for this camera, default <em>2</em>.</li>
<li><strong>Max Width</strong>: Maximum width reported to HomeKit, default <em>1280</em>.</li>
<li><strong>Max Height</strong>: Maximum height reported to HomeKit, default <em>720</em>.</li>
<li><strong>Max FPS</strong>: Maximum frame rate of the stream, default <em>10</em>.</li>
<li><strong>Max Bitrate</strong>: Maximum bit rate of the stream in kbit/s, default <em>300</em>.</li>
<li><strong>Video Codec</strong>: If you're running on a RPi with the omx version of ffmpeg installed, you can change to the hardware accelerated video codec with this option, default <em>libx264</em>.</li>
<li><strong>Audio Codec</strong>: If you're running on a RPi with the omx version of ffmpeg installed, you can change to the hardware accelerated audio codec with this option, default <em>libfdk_aac</em>.</li>
<li><strong>Audio</strong>: Can be set to true to enable audio streaming from camera. To use audio ffmpeg must be compiled with --enable-libfdk-aac, default <em>false</em>.</li>
<li><strong>Packet Size</strong>: If audio or video is choppy try a smaller value, set to a multiple of 188, default <em>1316</em>.</li>
<li><strong>Vertical Flip</strong>: Flips the stream vertically, default <em>false</em>.</li>
<li><strong>Horizontal Flip</strong>: Flips the stream horizontally, default <em>false</em>.</li>
<li><strong>Map Video</strong>: Select the stream used for video, default <em>0:0</em>.</li>
<li><strong>Map Audio</strong>: Select the stream used for audio, default <em>0:1</em>.</li>
<li><strong>Video Filter</strong>: Allows a custom video filter to be passed to FFmpeg via -vf, defaults to <em>scale=1280:720</em>.</li>
<li><strong>Additional Command Line</strong>: Allows additional of extra command line options to FFmpeg, default <em>-tune zerolatency</em>.</li>
<li><strong>Debug</strong>: Show the output of ffmpeg in the log, default <em>false</em>.</li>
<li><strong>Snapshot output</strong>: Choose how to output camera snapshot</li>
<ul>
<li><strong>Disabled</strong>: there will be no output</li>
<li><strong>Path</strong>: file will be saved and path will be send to output, <em>msg.payload.cameraSnapshot</em> contains path value stored as a string.</li>
<li><strong>Content</strong>: file content will be send to output, <em>msg.payload.cameraSnapshot</em> contains Buffer object {"type":"Buffer","data":[]}.</li>
</ul>
</ul>
<li><strong>Characteristic Properties</strong>: Customize the properties of characteristics.</li>
</ul>
<h2 id="toc_6">Input Messages</h2>
<p>Input messages can be used to update any <em>Characteristic</em> that the selected <em>Service</em> provides. Simply pass the values-to-update as <code>msg.payload</code> object. </p>
<p><strong>Example</strong>: to signal that an <em>Outlet</em> is turned on and in use, send the following payload</p>
<div>
<pre><code class="language-javascript">{
"On": 1,
"OutletInUse": 1
}</code></pre>
</div>
<p><strong>Hint</strong>: to find out what <em>Characteristics</em> you can address, just send <code>{"foo":"bar"}</code> and watch the debug tab ;)</p>
<h2 id="toc_7">Output Messages</h2>
<p>Output messages are in the same format as input messages. They are emitted from the node when it receives <em>Characteristics</em> updates from a paired iOS device.</p>
<h2 id="toc_8">Characteristic Properties</h2>
<p><strong>Example</strong>: allow temperatures below 0°C</p>
<div>
<pre><code class="language-json">{
"CurrentTemperature": {
"minValue": -100
}
<p><strong>Example</strong>: limit fan speed multiples of 25%</p>
<div><pre><code class="language-json">{
"RotationSpeed": {
"minStep": 25
}
}</code></pre>
</div>
</script>
<script type="text/x-red" data-template-name="homekit-bridge">
<div class="form-row">
<label for="node-config-input-pinCode"><i class="fa fa-lock"></i> Pin Code</label>
<input type="text" id="node-config-input-pinCode" placeholder="xxx-xx-xxx">
</div>
<div class="form-row">
<label for="node-config-input-port"><i class="fa fa-plug"></i> Port</label>
<input type="text" id="node-config-input-port" placeholder="Leave blank to auto assign">
</div>
<div class="form-row">
<label> </label>
<input type="checkbox" id="node-config-input-allowInsecureRequest" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-config-input-allowInsecureRequest" style="width: 70%;"> <i class="fa fa-shield"></i> Allow Insecure Request</label>
</div>
<div class="form-row">
<label for="node-config-input-manufacturer"><i class="fa fa-wrench"></i> Manufacturer</label>
<input type="text" id="node-config-input-manufacturer" placeholder="Manufacturer">
</div>
<div class="form-row">
<label for="node-config-input-serialNo"><i class="fa fa-wrench"></i> Serial Number</label>
<input type="text" id="node-config-input-serialNo" placeholder="Serial Number">
</div>
<div class="form-row">
<label for="node-config-input-model"><i class="fa fa-wrench"></i> Model</label>
<input type="text" id="node-config-input-model" placeholder="Model">
</div>
<div class="form-row">
<label for="node-config-input-bridgeName"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-config-input-bridgeName" placeholder="Name">
</div>
<hr>
<div class="form-row">
<input type="checkbox" id="node-config-input-allowMessagePassthrough" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-config-input-allowMessagePassthrough" style="width: 70%;"> <i class="fa fa-step-forward"></i> Allow Message Passthrough</label>
</div>
<hr>
<div class="form-row">
<input type="checkbox" id="node-config-input-customMdnsConfig" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-config-input-customMdnsConfig" style="width: 70%;"> <i class="fa fa-filter"></i> Custom MDNS Configuration</label>
</div>
<div id="mdns-configuration" style="display: none;">
<div class="form-row">
<label for="node-config-input-mdnsMulticast"><i class="fa fa-ellipsis-v"></i> Multicast</label>
<input type="checkbox" id="node-config-input-mdnsMulticast" checked>
</div>
<div class="form-row">
<label for="node-config-input-mdnsInterface"><i class="fa fa-location-arrow"></i> Multicast Interface IP</label>
<input type="text" id="node-config-input-mdnsInterface" placeholder="">
</div>
<div class="form-row">
<label for="node-config-input-mdnsPort"><i class="fa fa-location-arrow"></i> Port</label>
<input type="text" id="node-config-input-mdnsPort" placeholder="">
</div>
<div class="form-row">
<label for="node-config-input-mdnsIp"><i class="fa fa-location-arrow"></i> Multicast Address IP</label>
<input type="text" id="node-config-input-mdnsIp" placeholder="">
</div>
<div class="form-row">
<label for="node-config-input-mdnsTtl"><i class="fa fa-repeat"></i> TTL</label>
<input type="text" id="node-config-input-mdnsTtl" placeholder="255">
</div>
<div class="form-row">
<label for="node-config-input-mdnsLoopback"><i class="fa fa-undo"></i> Loopback</label>
<input type="checkbox" id="node-config-input-mdnsLoopback" checked>
</div>
<div class="form-row">
<label for="node-config-input-mdnsReuseAddr"><i class="fa fa-location-arrow"></i> Reuse Address</label>
<input type="checkbox" id="node-config-input-mdnsReuseAddr" checked>
</div>
</div>
<hr>
</script>
<script type="text/x-red" data-help-name="homekit-bridge">
<h3 id="toc_4">Bridge</h3>
<p>The Bridge node is a configuration node, specifying the <em>bridge</em> that iOS sees, i.e. the device that is manually being added by the user. All accessories behind a bridge noded are then automatically added by iOS.
</p>
<ul>
<li><strong>Pin Code</strong>: Specify the Pin for the pairing process.</li>
<li><strong>Port</strong>: If you are behind a Firewall, you may want to specify a port. Otherwise leave empty.</li>
<li><strong>Allow Insecure Request</strong>: Should we allow insecure request? Default false.</li>
<li><strong>Manufacturer, Model, Serial Number</strong>: Can be anything you want.</li>
<li><strong>Name</strong>: If you intend to simulate a rocket, then why don't you call it <em>Rocket</em>.</li>
<li><strong>Allow Message Passthrough</strong>: If you allow then message from node input will be send to node output.</li>
<li><strong>Custom MDNS Configuration</strong>: Check if you would like to use custom mdns configuration.</li>
<ul>
<li><strong>Multicast</strong>: Use udp multicasting. Optional. Default true.</li>
<li><strong>Multicast Interface IP:</strong>: Explicitly specify a network interface. Optional. Defaults to all.</li>
<li><strong>Port</strong>: Set the udp port. Optional. Default 5353.</li>
<li><strong>Multicast Address IP</strong>: Set the udp ip. Optional. </li>
<li><strong>TTL</strong>: Set the multicast ttl. Optional. </li>
<li><strong>Loopback</strong>: Receive your own packets. Optional. Default true.</li>
<li><strong>Reuse Address</strong>: Set the reuseAddr option when creating the socket. Optional. Default true.</li>
</ul>
</ul>
</script>
<script type="text/javascript">
RED.validators.port = function(port){return port >= 1 && port <= 65535 && port === port.toString()};
</script>
<script type="text/javascript">
let serviceTypes;
let accessoryTypes;
//HomeKitServiceTypes
$.getJSON("homekit/service/types", function(data) {
serviceTypes = data;
});
//HomeKitAccessoryTypes
$.getJSON("homekit/accessory/types", function(data) {
accessoryTypes = data;
});
const cameraConfigRequiredField = function (value) {
if (this.serviceName === "CameraControl") {
return (value || "").toString().trim();
} else return true;
};
RED.nodes.registerType("homekit-service", {
category: "advanced",
paletteLabel: "homekit",
defaults: {
isParent: {
value: "false",
required: true
},
bridge: {
value: "",
type: "homekit-bridge",
required: false
},
accessoryCategory: {
value: "OTHER",
required: false
},
parentService: {
value: "",
required: false
},
name: {
value: "",
required: true,
validate: function(value) {
return value.length > 0;
}
},
serviceName: {
value: "",
required: true
},
topic: {
value:""
},
filter: {
value: false
},
manufacturer: {
value: "Default Manufacturer",
required: true
},
model: {
value: "Default Model",
required: true
},
serialNo: {
value: "Default Serial Number",
required: true
},
cameraConfigVideoProcessor: {
value: "ffmpeg",
validate: cameraConfigRequiredField
},
cameraConfigSource: {
validate: cameraConfigRequiredField
},
cameraConfigStillImageSource: {
required: false
},
cameraConfigMaxStreams: {
value: 2,
validate: cameraConfigRequiredField
},
cameraConfigMaxWidth: {
value: 1280,
validate: cameraConfigRequiredField
},
cameraConfigMaxHeight: {
value: 720,
validate: cameraConfigRequiredField
},
cameraConfigMaxFPS: {
value: 10,
validate: cameraConfigRequiredField
},
cameraConfigMaxBitrate: {
value: 300,
validate: cameraConfigRequiredField
},
cameraConfigVideoCodec: {
value: "libx264",
validate: cameraConfigRequiredField
},
cameraConfigAudioCodec: {
value: "libfdk_aac",
validate: cameraConfigRequiredField
},
cameraConfigAudio: {
value: false
},
cameraConfigPacketSize: {
value: 1316,
validate: cameraConfigRequiredField
},
cameraConfigVerticalFlip: {
value: false
},
cameraConfigHorizontalFlip: {
value: false
},
cameraConfigMapVideo: {
value: "0:0",
validate: cameraConfigRequiredField
},
cameraConfigMapAudio: {
value: "0:1",
validate: cameraConfigRequiredField
},
cameraConfigVideoFilter: {
value: "scale=1280:720",
validate: cameraConfigRequiredField
},
cameraConfigAdditionalCommandLine: {
value: "-tune zerolatency",
validate: cameraConfigRequiredField
},
cameraConfigDebug: {
value: false
},
cameraConfigSnapshotOutput: {
value: "disabled",
validate: cameraConfigRequiredField
},
characteristicProperties: {
value: "{}",
validate: function(value) {
if (value.length === 0) {
return true;
}
try {
JSON.parse(value);
} catch (e) {
return false;
}
return value[0] === "{";
}
}
},
inputs: 1,
outputs: 2,
outputLabels: function(index) {
if (index === 0) {
return "default"
}
if (index === 1) {
return "camera snapshot"
}
return ""
},
icon: "homekit.png",
color: "#fcc127",
label: function() {
return this.name || this.serviceName || "Service";
},
labelStyle: function() {
return this.name ? "node_label_italic" : "";
},
oneditprepare: function() {
let node = this;
let isParentToggle = $("#node-config-input-isParent");
if (node.isParent === false) {
isParentToggle.val("false");
} else {
isParentToggle.val("true");
}
let isLinkedDiv = $("#isLinked");
let isParentDiv = $("#isParent");
isParentToggle.change(function(){
if(isParentToggle.val() === "true") {
isLinkedDiv.fadeOut("fast");
isParentDiv.fadeIn("fast");
} else {
isParentDiv.fadeOut("fast");
isLinkedDiv.fadeIn("fast");
}
}).change();
const selectServiceName = $("#node-input-serviceName");
for (let key in serviceTypes) {
if (!serviceTypes.hasOwnProperty(key)) continue;
selectServiceName.append(
$("<option></option>")
.val(key)
.text(key)
);
}
let cameraConfiguration = $("#camera-configuration");
selectServiceName
.find("option")
.filter(function() {
return $(this).val() === node.serviceName;
})
.attr("selected", true);
selectServiceName.change(function(){
if(this.value === "CameraControl") {
cameraConfiguration.fadeIn("fast");
} else {
cameraConfiguration.fadeOut("fast");
}
}).change();
const selectCategoryName = $("#node-input-accessoryCategory");
for (let key in accessoryTypes) {
if (!accessoryTypes.hasOwnProperty(key)) continue;
selectCategoryName.append(
$("<option></option>")
.val(key)
.text(key)
);
}
selectCategoryName
.find("option")
.filter(function() {
return $(this).val() === node.accessoryCategory;
})
.attr("selected", true);
node.editor = RED.editor.createEditor({
id: "node-input-characteristicProperties-editor",
mode: "ace/mode/json",
value: $("#node-input-characteristicProperties").val()
});
const selectParentService = $("#node-input-parentService");
const candidateNodes = RED.nodes.filterNodes({type: "homekit-service"});
const inSubflow = !!RED.nodes.subflow(node.z);
candidateNodes.forEach(function(n) {
if (!n.name || n.name.length < 1 || !n.isParent) {
return;
}
if (n.id === node.id) {
return;
}
if (inSubflow) {
if (n.z !== node.z) {
return;
}
} else {
if (!!RED.nodes.subflow(n.z)) {
return;
}
}
let sublabel;
let tab = RED.nodes.workspace(n.z);
if (tab) {
sublabel = tab.label || tab.id;
} else {
tab = RED.nodes.subflow(n.z);
sublabel = "subflow : " + tab.name;
}
const value = n.id;
const text = n.name + " (" + sublabel + ")";
selectParentService.append(
$("<option></option>")
.val(value)
.text(text)
);
});
selectParentService
.find("option")
.filter(function() {
return $(this).val() === node.parentService;
})
.attr("selected", true);
selectParentService.change();
},
oneditsave: function() {
let node = this;
node.isParent = $("#node-config-input-isParent").val() === "true";
if (!node.isParent) {
node.parentService = $("#node-input-parentService option:selected").val();
}
node.serviceName = $("#node-input-serviceName option:selected").val();
$("#node-input-characteristicProperties").val(node.editor.getValue());
node.editor.destroy();
delete node.editor;
},
oneditcancel: function() {
this.editor.destroy();
delete this.editor;
},
oneditresize: function(size) {
const rows = $("#dialog-form>div:not(.node-text-editor-row)");
let height = $("#dialog-form").height();
for (let i = 0; i < rows.size(); i++) {
height -= $(rows[i]).outerHeight(true);
}
const editorRow = $("#dialog-form>div.node-text-editor-row");
height -=
parseInt(editorRow.css("marginTop")) +
parseInt(editorRow.css("marginBottom"));
$(".node-text-editor").css("height", height + "px");
this.editor.resize();
}
});
</script>
<script type="text/javascript">
RED.nodes.registerType("homekit-bridge", {
category: "config",
defaults: {
bridgeName: {
value: "",
required: true
},
pinCode: {
value: "111-11-111",
required: true,
validate: RED.validators.regex(/[0-9]{3}-[0-9]{2}-[0-9]{3}/)
},
port: {
required: false,
validate: function (value) {
if (value) return RED.validators.port(value);
else return true;
}
},
allowInsecureRequest: {
value: false,
required: true
},
manufacturer: {
value: "Default Manufacturer",
required: true
},
model: {
value: "Default Model",
required: true
},
serialNo: {
value: "Default Serial Number",
required: true
},
customMdnsConfig: {
value: false,
required: false
},
mdnsMulticast: {
value: true,
required: false
},
mdnsInterface: {
required: false
},
mdnsPort: {
required: false,
validate: function (value) {
if (value) return RED.validators.port(value);
else return true;
}
},
mdnsIp: {
required: false
},
mdnsTtl: {
required: false
},
mdnsLoopback: {
value: true,
required: false
},
mdnsReuseAddr: {
value: true,
required: false
},
allowMessagePassthrough: {
value: true,
required: true
}
},
label: function() {
return this.bridgeName || "Bridge";
},
labelStyle: function() {
return this.bridgeName ? "node_label_italic" : "";
},
oneditprepare: function () {
if (typeof this.allowMessagePassthrough == "undefined") {
this.allowMessagePassthrough = true
$("#node-config-input-allowMessagePassthrough").prop('checked', true);
}
let customMdnsConfigCheckbox = $("#node-config-input-customMdnsConfig");
let mdnsConfiguration = $("#mdns-configuration");
customMdnsConfigCheckbox.change(function(){
if(this.checked) {
mdnsConfiguration.fadeIn("fast");
} else {
mdnsConfiguration.fadeOut("fast");
}
}).change();
}
});
</script>