-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex_template.html
1735 lines (1580 loc) · 88.7 KB
/
index_template.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
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Foscam API</title>
<meta name="description" content="A simple HTML page to control a Foscam API compatible camera. Foscam-IPCamera-CGI-User-Guide (PDF) 1.0.16. All platform ( + except 3518A ?).">
<meta name="author" content="hyttysmyrkky">
<style>
body {background-color: #1d2d47;}
h1 {color: white; font-size: 10px;}
h2 {color: white; font-size: 16px;}
h3 {color: #e0e9ff; font-size: 14px; margin-bottom:0; padding-bottom: 0px; padding-top: 15px;}
p {color: silver; font-size: 13px;}
p.autogenerated {color: lime; font-size: 13px; margin:0; padding:4px;}
p.viewer {
color: white;
font-size: 12px;
padding:0px;
font-weight: bold;
position: relative;
z-index: 1000;
background-color: black;
opacity : 0.7;
}
iframe {background-color: white;}
form {color: white;}
form.autogenerated {padding-top: 0px;}
input.largerCheckbox {
width: 60px;
height: 40px;
}
input.autogenerated {margin:2px; padding:2px;}
label {color: silver; font-size: 13px;}
label.autogenerated {margin:2px; padding:2px;}
button.danger { color: red; }
button.sendToCamera { color: blue; }
button.showhide {
background-color: white;
font-size: 12px;
}
button.viewer {
background-color: white;
font-size: 9px;
font-weight: bold;
position: relative;
z-index: 1000;
opacity : 0.7;
}
button.ptz {
width: 100%;
height: 100%;
}
button.ptz_preset {
padding: 6px;
}
table.ptz {
width: 100%;
max-width: 600px;
}
td.ptz {
text-align: center;
color: silver;
font-size: 12px;
}
input.sendToCamera { color: blue; }
select.cameraselector {background-color: lime; padding:4px;}
table.checkboxImageTable, table.checkboxScheduleTable, table.checkboxLinkageTable, table.help, table.ViewerSetupOptions {
border: 4px solid;
border-collapse: collapse;
background-position: center;
-moz-background-size: 100% 100%;
-webkit-background-size: 100% 100%;
background-size: 100% 100%;
}
th.checkboxImageTable, tr.checkboxImageTable, td.checkboxImageTable {
color: silver;
font-size: 13px;
margin:0;
padding-left: 12px;
padding-right: 12px;
padding-top: : 20px;
padding-bottom: : 20px;
border:solid 1px #000000;
}
input.checkboxImageTable {
border: none;
outline: none;
position: relative;
opacity : 0.5;
-ms-transform: scale(2, 1.5); /* IE */
-moz-transform: scale(2, 1.5); /* FF */
-webkit-transform: scale(2, 1.5); /* Safari and Chrome */
-o-transform: scale(2, 1.5); /* Opera */
transform: scale(2, 1.5);
}
th.checkboxScheduleTable, tr.checkboxScheduleTable, td.checkboxScheduleTable {
color: silver;
font-size: 10px;
margin:0;
border:solid 1px #000000;
}
th.checkboxLinkageTable, tr.checkboxLinkageTable, td.checkboxLinkageTable, tr.help, td.help, tr.ViewerSetupOptions, td.ViewerSetupOptions {
color: silver;
font-size: 13px;
border:solid 1px #000000;
padding: 5px;
}
pre {
color: white;
}
a:link, a:visited {
color: silver;
}
a:hover, a:active {
color: white;
}
img.operate {
max-width: 100vw;
max-height: 60vh;
}
@media (min-aspect-ratio: 1/1) {
img.viewer {
width: 100vw;
height: 100vh;
padding: 0px;
position: absolute;
left: 0px;
top: 0px;
}
}
@media (max-aspect-ratio: 1/1) {
img.viewer {
max-width: 100vw;
max-height: 100vh;
padding: 0px;
position: absolute;
left: 0px;
top: 0px;
}
}
.viewerContainer {
border: 0px;
position: relative;
padding: 0px;
margin: 0;
}
.zeropadding {
padding: 0px;
margin: 0;
}
.somepadding {
padding: 3px;
margin: 3px;
}
</style>
</head>
<body onload="main();" class="zeropadding">
<div id="headerButtons" class="somepadding">
<h1>FOSCAM API</h1>
<label>Show/Hide:</label>
<button onclick="toggleView('Setup')" id="SetupToggle" class="showhide">Add/Remove camera</button>
<button onclick="toggleView('InitialSetup')" id="InitialSetupToggle" class="showhide">Initial setup & Help</button>
<button onclick="toggleView('Status')" id="StatusToggle" class="showhide">Status</button>
<button onclick="toggleView('Basic')" id="BasicToggle" class="showhide">Basic</button>
<button onclick="toggleView('Network')" id="NetworkToggle" class="showhide">Network</button>
<button onclick="toggleView('Video')" id="VideoToggle" class="showhide">Video</button>
<button onclick="toggleView('Detector')" id="DetectorToggle" class="showhide">Detector</button>
<button onclick="toggleView('Record')" id="RecordToggle" class="showhide">Record</button>
<button onclick="toggleView('System')" id="SystemToggle" class="showhide">System</button>
<button onclick="toggleView('PTZ')" id="PTZToggle" class="showhide">PTZ</button>
<button onclick="toggleView('Operate')" id="OperateToggle" class="showhide">Operate</button>
<button onclick="toggleView('Custom')" id="CustomToggle" class="showhide">Custom</button>
<button onclick="toggleView('ViewerSetup')" id="ViewerSetupToggle" class="showhide">Viewer Setup</button>
<button onclick="toggleViewerView()" id="ViewerToggle" class="showhide">Viewer</button>
<br>
<label for="selectedCamera">Select the camera to control:</label>
<select name="selectedCamera" id="selectedCamera" class="cameraselector" onchange="selectCamera()"></select>
<label for="onlyShowCmdUrlCheckbox">Only show command URL</label>
<input type="checkbox" id="onlyShowCmdUrlCheckbox">
</div>
<div id="Setup" style="display: none;" class="somepadding">
<hr>
<h2>Add new or edit</h2>
<p>Save a camera (its address and credentials) for this user interface. Data is saved to localStorage only on the browser you are using. Requests to cameras use unencrypted HTTP and the credentials are clear-text and show up in the browser page history. Use this web page only on your personal machine, and so that the cameras are accessed via LAN (or VPN or similar). On the other hand, if you can access your cameras over the internet without VPN or similar, you should reconfigure your firewalls.</p>
<form id="form" onsubmit="return false;" target="_blank">
<label for="cameraIp">IP address of the camera: (after connecting the camera, find this e.g. in router settings)</label><br>
<input type="text" id="cameraIp" name="cameraIp" placeholder="192.168.12.34"><br>
<label for="cameraPort">Port: (default for Opticam: 88)</label><br>
<input type="text" id="cameraPort" name="cameraPort" placeholder="88"><br><br>
<input type="checkbox" id="cameraIsOldSd" name="cameraIsOldSd">
<label for="cameraIsOldSd">The camera is an older SD (usually VGA resolution) camera (uses IP Camera CGI V1.27 API)</label><br><br>
<label for="cameraName">Name (optional & only for this UI)</label><br>
<input type="text" id="cameraName" name="cameraName" placeholder=""><br><br>
<label for="cameraUser">Username: (factory default: admin)</label><br>
<input type="text" id="cameraUser" name="cameraUser" placeholder="admin"><br>
<label for="cameraPass">Password: (factory default is empty)</label><br>
<input type="password" id="cameraPass" name="cameraPass" value=""><br><br>
<input type="submit" onclick="setupSaveCamera();" value="Add/Save camera"/>
</form>
<br>
<p>After resetting (or when setupping a new) camera, the default user is 'admin', password empty. Use this to replace that user with the username/password given above. NOTE: This only reads the IP/username/password fields above, and does NOT use the selected camera.</p>
<button id="replaceFactoryUser" class="sendToCamera" onclick="replaceFactoryUser()">Change factory-default user/password with credentials above</button>
<br><br>
<h2>Remove</h2>
<p>Choose the camera to remove from the green 'Select the camera to control' dropdown list at the top of the page. Deleting a camera only affects this user interface (and not the camera hardware) and deletes the data you have saved with the 'Add new or edit' above.</p>
<button onclick="deleteCamera()">Delete selected camera</button>
<br><br>
<h2>Remove all</h2>
<p>Reset all data saved for this UI (in localStorage). (Does not affect camera hardware in any way.)</p>
<button onclick="resetGlobals()" class="danger">Reset saved data</button>
<h2>Export/Import</h2>
<p>Export the data saved for this UI (in localStorage). When importing the exported file, all current settings will be lost. (Does not affect camera hardware in any way.) Warning: The exported file will contain all camera credentials as clear-text.</p>
<a id="downloadStart" style="display:none" download="FoscamApiExportedSettings.json">.</a>
<button onclick="exportLocalStorage()">Export data (localStorage) to file and download</button><br>
<button onclick="debug()">Print data to console</button><br>
<h3>Import</h3>
<form id="importSettingsFileForm">
<label for="selectedImportFile">Select the settings file: </label>
<input type="file" id="selectedImportFile" accept=".json">
<button>Import</button>
</form>
<br><br>
</div>
<div id="InitialSetup" style="display: none;" class="somepadding">
<hr>
<div>
<h2>Help</h2>
<p>This user interface for the Foscam API aims to be a portable, simple and easy-to-modify tool to install and manage Foscam API compatible cameras. Older SD/VGA cameras (IP Camera CGI V1.27) are not yet fully supported, and all the documentation etc. are for HD cameras (Foscam IPCamera CGI > 1.0.16).</p>
<p>This html file only requires JavaScript to work, and has no external dependencies. This on the other hand means quite a raw and clumsy user experience.</p>
<p>Commands are sent to the camera by opening the parsed URL as a new tab. The camera returns a response as an XML which you can see on the new tab. Therefore, some popups must be allowed, and also it makes it impossible to automatically process the response, unfortunately.</p>
<p>If you want to only see the parsed URL and not send the command when clicking the buttons with blue text, select the "Only show command URL" checkbox". On Linux you can turn the URL into a curl command with this syntax:</p>
<pre>curl 'PasteFullUrlHere'</pre>
<p>The RTSP video stream can be accessed with this kind of URLs (main, sub, audio):</p>
<pre>rtsp://user:password@192.168.1.123:88/videoMain</pre>
<pre>rtsp://user:password@192.168.1.123:88/videoSub</pre>
<pre>rtsp://user:password@192.168.1.123:88/audio</pre>
<p>If you are looking for a setting, you can show all categories by clicking the buttons at the top of this page and then use the search functionality of your browser. This user interface cannot know the model of your camera, so for example Wifi and PTZ (pan tilt zoom) settings are always visible but only work for cameras that support them. For more information about how this html file itself was developed, see the readme in <a href="https://github.com/hyttysmyrkky/foscam_cgi_api_html">GitHub: hyttysmyrkky/foscam_cgi_api_html</a>.</p>
<h3>How to interpret the response from camera</h3>
<p>The camera responds with an XML, for example when querying the IR LED config (getInfraLedConfig):</p>
<pre>
<CGI_Result>
<result>0</result>
<mode>0</mode>
</CGI_Result>
</pre>
<p><result> 0 means success. Other codes for 'result':</p>
<table class="help">
<tr class="help">
<th class="help"><result></th>
<th class="help">Meaning</th>
</tr>
<tr class="help">
<td class="help">0</td>
<td class="help">Success</td>
</tr>
<tr class="help">
<td class="help">-1</td>
<td class="help">CGI request string format error</td>
</tr>
<tr class="help">
<td class="help">-2</td>
<td class="help">Username or password error</td>
</tr>
<tr class="help">
<td class="help">-3</td>
<td class="help">Access denied</td>
</tr>
<tr class="help">
<td class="help">-4</td>
<td class="help">CGI execute fail</td>
</tr>
<tr class="help">
<td class="help">-5</td>
<td class="help">Timeout</td>
</tr>
<tr class="help">
<td class="help">-7</td>
<td class="help">Unknown error</td>
</tr>
</table>
<p>The rest of the returned values depend on the command. If you look at the corresponding setter commands (in this case 'setInfraLedConfig'), most of them have a dropdown list of the options for the given parameter. From that list you can figure out the meaning of 0, 1, 2 and so on.</p>
<p>In some cases you have to look at the Foscam API PDF documentation.</p>
<h2>Initial setup</h2>
<p>In the table below there is a collection of the most commonly required commands when setupping a new camera. If you already changed the factory-default user in the 'Add/Remove camera' step, you can skip the 'changeUserNameAndPwdTogether' below. If you are setupping multiple cameras, take a look at the Custom view: There you can save the parameters (e.g. FTP server settings) and send them easily to all cameras.</p>
<table class="help">
<tr class="help">
<th class="help">Description</th>
<th class="help">Getter (read) command</th>
<th class="help">Setter (write) command</th>
</tr>
<tr class="help">
<td class="help">Get users, change the factory-default</td>
<td class="help">getUserList</td>
<td class="help">changeUserNameAndPwdTogether</td>
</tr>
<tr class="help">
<td class="help">Test get a still image</td>
<td class="help">snapPicture2</td>
<td class="help"></td>
</tr>
<tr class="help">
<td class="help">Camera name</td>
<td class="help">getDevName</td>
<td class="help">setDevName</td>
</tr>
<tr class="help">
<td class="help">Wifi settings (if your camera model supports wifi)</td>
<td class="help">getWifiConfig</td>
<td class="help">setWifiSetting</td>
</tr>
<tr class="help">
<td class="help">Clock settings</td>
<td class="help">getSystemTime</td>
<td class="help">setSystemTime</td>
</tr>
<tr class="help">
<td class="help">FTP settings</td>
<td class="help">getFtpConfig</td>
<td class="help">setFtpConfig</td>
</tr>
<tr class="help">
<td class="help">P2P settings (disable if not needed)</td>
<td class="help">getP2PEnable</td>
<td class="help">setP2PEnable</td>
</tr>
<tr class="help">
<td class="help">Email alarm settings when motion is detected</td>
<td class="help">getSMTPConfig</td>
<td class="help">setSMTPConfig</td>
</tr>
<tr class="help">
<td class="help">Snapshot settings, select save location SD card or FTP</td>
<td class="help">getSnapConfig</td>
<td class="help">setSnapConfig</td>
</tr>
<tr class="help">
<td class="help">Motion detection settings</td>
<td class="help">getMotionDetectConfig</td>
<td class="help">setMotionDetectConfig</td>
</tr>
<tr class="help">
<td class="help">Recording settings, select save location SD card or FTP</td>
<td class="help">getRecordPath</td>
<td class="help">setRecordPath</td>
</tr>
<tr class="help">
<td class="help">Length of recorded video clip</td>
<td class="help">getAlarmRecordConfig</td>
<td class="help">setAlarmRecordConfig</td>
</tr>
<tr class="help">
<td class="help">Cloud settings (disable if not needed)</td>
<td class="help">getCloudConfig</td>
<td class="help">setCloudConfig</td>
</tr>
<tr class="help">
<td class="help">OSD settings (text overlay on image)</td>
<td class="help">getOSDSetting</td>
<td class="help">setOSDSetting</td>
</tr>
<tr class="help">
<td class="help">PTZ presets, if your camera supports PTZ. Add a new preset.</td>
<td class="help">getPTZPresetPointList</td>
<td class="help">ptzAddPresetPoint</td>
</tr>
<tr class="help">
<td class="help">PTZ mode when camera boots (2 = go to preset)</td>
<td class="help">getPTZSelfTestMode</td>
<td class="help">setPTZSelfTestMode</td>
</tr>
<tr class="help">
<td class="help">PTZ preset to go at boot</td>
<td class="help">getPTZPrePointForSelfTest</td>
<td class="help">setPTZPrePointForSelfTest</td>
</tr>
<tr class="help">
<td class="help">Brightness</td>
<td class="help">getImageSetting</td>
<td class="help">setBrightness</td>
</tr>
<tr class="help">
<td class="help">Resolution and bitrate: currently active preset ("streamType")</td>
<td class="help">getMainVideoStreamType</td>
<td class="help">setMainVideoStreamType</td>
</tr>
<tr class="help">
<td class="help">Resolution and bitrate settings</td>
<td class="help">getVideoStreamParam</td>
<td class="help">setVideoStreamParam</td>
</tr>
<tr class="help">
<td class="help">Reboot camera</td>
<td class="help">rebootSystem</td>
<td class="help"></td>
</tr>
</table>
</div>
</div>
<div id="Status" style="display: none;" class="somepadding">
<hr><h2>Status</h2>
</div>
<div id="Basic" style="display: none;" class="somepadding">
<hr><h2>Basic</h2>
</div>
<div id="Network" style="display: none;" class="somepadding">
<hr><h2>Network</h2>
</div>
<div id="Video" style="display: none;" class="somepadding">
<hr><h2>Video</h2>
</div>
<div id="Detector" style="display: none;" class="somepadding">
<hr><h2>Detector</h2>
<div>
<h3 class="cmdTitle">Motion detection area and schedule</h3>
<p class="description">Motion will be detected in the checked boxes. You can set a snapshot image from the camera to the background of the table by clicking the 'Browse'. Before that you have to manually get the image (see the 'Operate' view) and save the image as jpg. When the correct area is selected, click the 'Apply area' button which will read the values from the table to the parameter fields of 'setMotionDetectConfig' below. Then set the other parameters and click 'Send to camera'.</p>
<p class="description">This UI cannot read the currently active setting from the camera automatically, but the inputted setting is saved to localStorage for the selected camera.</p>
<div id="checkboxImageTable">
<input type="file" id="image_input" accept="image/jpg">
<button onclick="motionDetectAreaTable.setAll(true)">Select all</button>
<button onclick="motionDetectAreaTable.setAll(false)">Deselect all</button>
<button onclick="motionDetectAreaTable.applyToCmdParams()">Apply area</button>
</div>
<div id="checkboxScheduleTable">
<p class="description">Motion detection is enabled during every selected (starting) half an hour. Click 'Apply schedule' to read the table values to the parameter fields below.</p>
<button onclick="motionDetectScheduleTable.setAll(true)">Select all</button>
<button onclick="motionDetectScheduleTable.setAll(false)">Deselect all</button>
<button onclick="motionDetectScheduleTable.applyToCmdParams()">Apply schedule</button>
</div>
<div id="checkboxLinkageTable">
<p class="description">The linkage (or action) what happens when motion is detected, is also defined the same way. Click 'Apply linkage' to read the table values to the parameter fields below.</p>
<button onclick="motionDetectLinkageTable.setAll(true)">Select all</button>
<button onclick="motionDetectLinkageTable.setAll(false)">Deselect all</button>
<button onclick="motionDetectLinkageTable.applyToCmdParams()">Apply linkage</button>
</div>
</div>
</div>
<div id="Record" style="display: none;" class="somepadding">
<hr><h2>Record</h2>
</div>
<div id="System" style="display: none;" class="somepadding">
<hr><h2>System</h2>
<h3>importConfig</h3>
<p>(Not tested, may not work at all?)</p>
<form name="form5" method="post" target="retframe" enctype="multipart/form-data" action="javascript:getUrl('importConfig');">
<input type="file" name="setting_file">
<input type="submit" value="import">
</form>
<h3>fwUpgrade</h3>
<p>(Not tested, so commented-out for now.)</p>
<!-- TODO: NOT TESTED and potentially harmful, so commented-out now.
<form name="form5" method="post" target="retframe" enctype="multipart/form-data" action="javascript:getUrl('fwUpgrade');">
<input type="file" name="fw_file">
<input type="submit" value="upgrade">
</form>
-->
</div>
<div id="PTZ" style="display: none;" class="somepadding">
<hr><h2>PTZ</h2>
</div>
<div id="Operate" style="display: none;" class="somepadding">
<hr><h2>Operate</h2>
<div>
<button onclick="getStillImage()" id="operateViewSnapshotButton">Get/Refresh the image (also by clicking the image)</button>
<br>
<img onclick="getStillImage()" class="operate" id="operateViewSnapshot" src=""/>
<br>
<table class="ptz">
<tr>
<td colspan="2">
<button onpointerdown="ptz('ptzMoveUp')" onpointerup="ptz('ptzStopRun')" class="ptz">^</button>
</td>
<td class="ptz">Zoom</td>
<td class="ptz">Focus</td>
</tr>
<tr>
<td>
<button onpointerdown="ptz('ptzMoveLeft')" onpointerup="ptz('ptzStopRun')" class="ptz"><</button>
</td>
<td>
<button onpointerdown="ptz('ptzMoveRight')" onpointerup="ptz('ptzStopRun')" class="ptz">></button>
</td>
<td>
<button onpointerdown="ptz('zoomIn')" onpointerup="ptz('zoomStop')" class="ptz">+ in</button>
</td>
<td>
<button onpointerdown="ptz('focusFar')" onpointerup="ptz('focusStop')" class="ptz">far</button>
</td>
</tr>
<tr>
<td colspan="2">
<button onpointerdown="ptz('ptzMoveDown')" onpointerup="ptz('ptzStopRun')" class="ptz">v</button>
</td>
<td>
<button onpointerdown="ptz('zoomOut')" onpointerup="ptz('zoomStop')" class="ptz">- out</button>
</td>
<td>
<button onpointerdown="ptz('focusNear')" onpointerup="ptz('focusStop')" class="ptz">near</button>
</td>
</tr>
</table>
<pre id="ptzShowSentCmd" class="ptz">-</pre>
<button onclick="ptz('openInfraLed')">IR on</button>
<button onclick="ptz('setInfraLedConfig', {'mode':'0'})">IR auto</button>
<button onclick="ptz('closeInfraLed')">IR off</button>
<br><br>
<label for="gotoPreset1">Presets:</label>
<button onclick="ptz('ptzGotoPresetPoint', {'name':'1'})" class="ptz_preset" id="gotoPreset1" >1</button>
<button onclick="ptz('ptzGotoPresetPoint', {'name':'2'})" class="ptz_preset">2</button>
<button onclick="ptz('ptzGotoPresetPoint', {'name':'3'})" class="ptz_preset">3</button>
<button onclick="ptz('ptzGotoPresetPoint', {'name':'4'})" class="ptz_preset">4</button>
<button onclick="ptz('ptzGotoPresetPoint', {'name':'5'})" class="ptz_preset">5</button>
<button onclick="ptz('ptzGotoPresetPoint', {'name':'6'})" class="ptz_preset">6</button>
<button onclick="ptz('ptzGotoPresetPoint', {'name':'7'})" class="ptz_preset">7</button>
<button onclick="ptz('ptzGotoPresetPoint', {'name':'8'})" class="ptz_preset">8</button>
<button onclick="ptz('ptzGotoPresetPoint', {'name':'9'})" class="ptz_preset">9</button>
<button onclick="ptz('ptzGotoPresetPoint', {'name':'0'})" class="ptz_preset">0</button>
<button onclick="ptz('ptzGotoPresetPoint', {'name':'a'})" class="ptz_preset">a</button>
<button onclick="ptz('ptzGotoPresetPoint', {'name':'b'})" class="ptz_preset">b</button>
<br><br>
<label for="addPresetSelected">Set/Add preset (to be the current position):</label>
<select name="addPresetSelected" id="addPresetSelected">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="0">0</option>
<option value="a">a</option>
<option value="b">b</option>
</select>
<button onclick="ptz('ptzAddPresetPoint')">Set</button>
<br>
<img height="0" width="0" id="operateViewDummyForPtz" src=""/>
<br>
<label for="rtspMain">Open stream (RTSP):</label>
<button onclick="openRtspStream('videoMain')" id="rtspMain">Video, main</button>
<button onclick="openRtspStream('videoSub')" id="rtspSub">Video, sub</button>
<button onclick="openRtspStream('audio')" id="rtspAudio">Audio</button>
</div>
</div>
<div id="Custom" style="display: none;" class="somepadding">
<hr><h2>Custom</h2>
<p>Here you can essentially save a set of parameters to easily send the same command later. For example, useful for making buttons "Enable motion detection" and "Disable motion detection".</p>
<div id="customCmdControls">
</div>
<h3>Add new</h3>
<label for="selectedCustomCommand">Select the command:</label>
<select name="selectedCustomCommand" id="selectedCustomCommand" class="commandselector" onchange="selectCustomCommand()"></select>
<div id="customCmdControlCreate">
</div>
<br>
<label for="addCustomCommandName">Name or description for the custom command:</label><br>
<input type="text" id="addCustomCommandName" name="addCustomCommandName" placeholder="e.g. set my time zone"><br>
<label for="addCustomCommandFixedCamera">Only for one (currently selected) camera</label>
<input type="checkbox" id="addCustomCommandFixedCamera" name="addCustomCommandFixedCamera"><br>
<button onclick="addCustomCommand()" id="addCustomCommandButton">Add</button>
</div>
<div id="ViewerSetup" style="display: none;" class="somepadding">
<hr><h2>Viewer Setup</h2>
<p>The Viewer displays still images from the selected cameras in a loop. Here you can set which cameras are included.</p>
<div id="ViewerSetupOptions"></div>
<br>
<label for="viewerRefreshInterval">Viewer refresh interval (in seconds)</label>
<input type="text" oninput="this.value = this.value.replace(/[^0-9.]/g, ''); this.value = this.value.replace(/(\..*)\./g, '$1'); this.value = Math.round(this.value);" id="viewerRefreshInterval"><br>
<label for="viewerConsecutiveImages">Number of consecutive images from one camera</label>
<input type="text" oninput="this.value = this.value.replace(/[^0-9.]/g, ''); this.value = this.value.replace(/(\..*)\./g, '$1'); this.value = Math.round(this.value);" id="viewerConsecutiveImages"><br><br>
<button onclick="saveViewerSettings()" id="SaveViewerSetupOptions">Save and apply</button>
</div>
<div id="Viewer" class="viewerContainer" style="display: none;">
<button onclick="toggleViewerView()" id="toggleViewerBackButton" class="viewer"><- Back</button>
<button onclick="viewer.jumpToPreviousCamera()" class="viewer">Previous camera</button>
<button onclick="viewer.jumpToNextCamera()" class="viewer">Next camera</button>
<button onclick="viewer.pause()" class="viewer">Pause</button>
<button onclick="viewer.continue()" class="viewer">Continue</button>
<button onclick="viewer.manualRefreshImage()" class="viewer">Refresh (click image)</button>
<p class="viewer" style="display:inline" id="ViewerStatus"> Select some cameras in the Viewer Setup to start the Viewer. </p>
<br>
<img class="viewer" id="viewerImage" onload="viewer.imageLoaded()" onerror="viewer_imageLoadError()" onclick="viewer.manualRefreshImage()" src=""/>
</div>
<script>
let globals;
const globalsVersion = 4; // Increment this when globals is changed so that a migration (or resetGlobals()) is needed.
let logDebugLevel = false;
let viewerSetupCameraTable;
let viewer;
class View {
constructor(defaulVisible = false, apiCommands = []) {
this.isVisible = defaulVisible;
this.apiCommands = apiCommands;
}
}
class Camera {
constructor(ip, user, password, cameraName = "", port = 88, isOldSdCamera = false) {
this.ip = ip;
this.port = port;
this.user = user;
this.password = password;
this.cameraName = cameraName;
this.isOldSdCamera = isOldSdCamera; // old standard definition cameras use a different API (IP Camera CGI V1.27)
this.keyName = ip+":"+port+" ("+user+") "+ cameraName;
this.motionDetectAreaTableState = "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111";
this.motionDetectScheduleTableState = "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111";
this.motionDetectLinkageTableState = "0111";
this.ViewerSetupOptions = "0";
}
}
// General functions for UI and saving/loading settings:
function main(){
// Load the globals, or create, if not exist:
globals = JSON.parse(localStorage.getItem('globals'));
if (globals === null){
logDebug("Globals was null");
resetGlobals();
}
migrateGlobals(globalsVersion);
// Set the default contents of the views:
setDefaultViewContents();
// Set the selectedCamera which defines the camera being controlled:
var selectCameraDropdown = document.getElementById("selectedCamera");
selectCameraDropdown.length = 0;
if (Object.keys(globals.setup.cameras).length <= 0){
globals.selectedCamera = null;
}
else {
// Set the available cameras to the dropdown:
for (const [key, value] of Object.entries(globals.setup.cameras)){
selectCameraDropdown.add(new Option(key, key));
}
if (globals.selectedCamera === null){
globals.selectedCamera = Object.keys(globals.setup.cameras)[0];
}
selectCameraDropdown.value = globals.selectedCamera;
// Load the motion detection area and schedule table settings of the selected camera:
motionDetectAreaTable.load(globals.setup.cameras[globals.selectedCamera].motionDetectAreaTableState);
motionDetectScheduleTable.load(globals.setup.cameras[globals.selectedCamera].motionDetectScheduleTableState);
motionDetectLinkageTable.load(globals.setup.cameras[globals.selectedCamera].motionDetectLinkageTableState);
}
// Construct views:
generateViews();
// Show or hide the views:
refreshViewVisibility(null);
saveGlobals();
}
function resetGlobals(){
logDebug("Resetting globals.");
globals = {
"setup" : {
"cameras": {},
},
"selectedCamera" : null,
"views" : {
"Setup" : new View(true),
"InitialSetup" : new View(false),
"Status" : new View(false),
"Basic" : new View(false),
"Network" : new View(false),
"Video" : new View(false),
"Detector" : new View(false),
"Record" : new View(false),
"System" : new View(false),
"PTZ" : new View(false),
"Operate" : new View(false),
"Custom" : new View(false),
"ViewerSetup" : new View(false),
},
"customCommands" : {}, // The saved buttons of the Custom view
"viewerConsecutiveImages" : 3,
"viewerRefreshInterval_ms" : 4000,
"viewerIsEnabled" : false,
"version" : globalsVersion,
}
globals.views.Setup.isVisible = true;
logDebug(globals);
saveGlobals();
main(); // or reload? window.location.reload();
}
// Migrations for the globals in localStorage:
function migrateGlobals(toVersion) {
if ("version" in globals) {
var currentGlobalsVersion = globals.version;
}
else {
var currentGlobalsVersion = 0;
}
// migrations only up possible:
while (currentGlobalsVersion < toVersion) {
if (currentGlobalsVersion == 0) {
console.log("Migrating globals from v. 0 to 1");
globals.views.ViewerSetup = new View(false); // add a new View
}
else if (currentGlobalsVersion == 1) {
console.log("Migrating globals from v. 1 to 2");
globals.viewerConsecutiveImages = 3;
globals.viewerRefreshInterval = 4000; // add a couple of persisted settings
}
else if (currentGlobalsVersion == 2) {
console.log("Migrating globals from v. 2 to 3");
globals.viewerIsEnabled = false; // add more settings
}
else if (currentGlobalsVersion == 3) {
console.log("Migrating globals from v. 3 to 4");
globals.viewerRefreshInterval_ms = globals.viewerRefreshInterval; // rename to be unique and have the unit
}
currentGlobalsVersion++;
globals.version = currentGlobalsVersion;
logDebug(globals);
}
saveGlobals();
}
function setDefaultViewContents() {
globals.views.Status.apiCommands = ["getDevName", "getDevInfo", "getDevState", "getSessionList", "getFirewallConfig", "getLog"];
globals.views.Basic.apiCommands = ["getDevName", "setDevName", "getSystemTime", "setSystemTime", "getUserList", "addAccount", "delAccount", "changeUserName", "changePassword", "changeUserNameAndPwdTogether"];
globals.views.Network.apiCommands = ["getIPInfo", "setIpInfo", "getWifiConfig", "setWifiSetting", "getSMTPConfig", "setSMTPConfig", "smtpTest", "getFtpConfig", "setFtpConfig", "testFtpServer", "getPortInfo", "setPortInfo", "getP2PEnable", "setP2PEnable", "getP2PPort", "setP2PPort", "getP2PInfo", "getDDNSConfig", "setDDNSConfig"];
globals.views.Video.apiCommands = ["getMainVideoStreamType", "setMainVideoStreamType", "getVideoStreamParam", "setVideoStreamParam", "getSubVideoStreamType", "setSubVideoStreamType", "getSubVideoStreamParam", "setSubVideoStreamParam", "getOSDSetting", "setOSDSetting", "getSnapConfig", "setSnapConfig", "getScheduleSnapConfig", "setScheduleSnapConfig", "getImageSetting", "setHue", "setBrightness", "setContrast", "setSaturation", "setSharpness", "setPwrFreq", "getMirrorAndFlipSetting", "mirrorVideo", "flipVideo"];
globals.views.Detector.apiCommands = ["setMotionDetectConfig", "getMotionDetectConfig", "getAudioAlarmConfig", "setAudioAlarmConfig"];
globals.views.Record.apiCommands = ["getRecordPath", "setRecordPath", "getAlarmRecordConfig", "setAlarmRecordConfig", "getRecordList", "getRecordList2", "getScheduleRecordConfig", "setScheduleRecordConfig", "getMultiDevList", "getMultiDevDetailInfo", "addMultiDev", "delMultiDev", "getDeFrameLevel", "setDeFrameLevel", "getCloudConfig", "setCloudConfig", "selectCloudServer", "getCloudToken", "getCloudQuota", "testCloudServer"];
globals.views.System.apiCommands = ["exportConfig", "restoreToFactorySetting", "rebootSystem"];
globals.views.PTZ.apiCommands = ["getPTZSpeed", "setPTZSpeed", "getPTZPresetPointList", "ptzAddPresetPoint", "ptzDeletePresetPoint", "ptzGotoPresetPoint", "getPTZSelfTestMode", "setPTZSelfTestMode", "getPTZPrePointForSelfTest", "setPTZPrePointForSelfTest", "getZoomSpeed", "setZoomSpeed", "ptzGetCruiseMapList", "ptzGetCruiseMapInfo", "ptzSetCruiseMap", "ptzDelCruiseMap", "ptzStartCruise", "ptzStopCruise", "getCruiseTime", "setCruiseTime", "getCruiseTimeCustomed", "setCruiseTimeCustomed", "getCruiseLoopCnt", "setCruiseLoopCnt", "getCruiseCtrlMode", "setCruiseCtrlMode", "getCruisePrePointLingerTime", "setCruisePrePointLingerTime"];
globals.views.Operate.apiCommands = ["snapPicture2", "snapPicture", "getInfraLedConfig", "setInfraLedConfig", "openInfraLed", "closeInfraLed", "zoomIn", "zoomOut", "zoomStop", "ptzMoveUp", "ptzMoveDown", "ptzMoveLeft", "ptzMoveRight", "ptzStopRun", "focusFar", "focusNear", "focusStop"];
}
function saveGlobals(){
localStorage.setItem("globals", JSON.stringify(globals));
}
// Functions to handle views:
function toggleView(viewName){
globals.views[viewName]["isVisible"] = !globals.views[viewName]["isVisible"];
refreshViewVisibility(viewName);
saveGlobals();
}
function toggleViewerView() { // A special toggle which enables and disables the Viewer and its timer essentially.
if (!viewer.enabled) {
viewer.enable();
}
else {
viewer.disable();
}
refreshViewVisibility(null);
}
function refreshViewVisibility(viewName){
if (viewName === null) {
// Refresh all
for (const [key, value] of Object.entries(globals.views)){
if (!viewer.enabled) {
// Normal case.
var display = globals.views[key]["isVisible"] ? "block" : "none";
}
else {
var display = "none"; // If Viewer is enabled, hide everything else.
}
document.getElementById(key).style.display = display;
// Set the toggle button color:
document.getElementById(key+"Toggle").style = globals.views[key]["isVisible"] ? "background-color:#ffd557": "background-color:white";
}
// If Viewer is enabled, hide everything else.
document.getElementById("headerButtons").style.display = viewer.enabled ? "none" : "block";
document.getElementById("Viewer").style.display = viewer.enabled ? "block" : "none";
}
else {
var display = globals.views[viewName]["isVisible"] ? "block" : "none";
document.getElementById(viewName).style.display = display;
// Set the toggle button color:
document.getElementById(viewName+"Toggle").style = globals.views[viewName]["isVisible"] ? "background-color:#ffd557": "background-color:white";
}
}
function generateViews(){
// Delete old to prevent duplicates from appearing:
document.querySelectorAll('.autogenerated').forEach(e => e.remove());
for (const [key, value] of Object.entries(globals.views)){
generateView(key, value);
}
// Create the Custom view as a special case:
// Populate the dropdown of the 'Add new':
selectedCustomCommandDropdown = document.getElementById("selectedCustomCommand")
selectedCustomCommandDropdown.length = 0;
for (const key of Object.keys(commandJson).sort()){
selectedCustomCommandDropdown.add(new Option(key, key));
}
// Also create the saved buttons:
refreshCustomCmdControlsView();
// The Viewer as another special case:
// Create the list of available cameras to ViewerSetup:
document.getElementById("ViewerSetupOptions").innerHTML = ""; // Clear old stuff
var allAvailableCameraKeys = Object.keys(globals.setup.cameras);
// Create the settings table, and load the saved state:
viewerSetupCameraTable = new checkboxTable(["enabled"], allAvailableCameraKeys, "ViewerSetupOptions", "viewerSetupCameraTable", "vs", "vse", true); // not completely suitable class for this...
viewerSetupCameraTable.loadRowdataFromCameras();
// Load other saved settings to the text fields:
document.getElementById("viewerConsecutiveImages").value = globals.viewerConsecutiveImages;
document.getElementById("viewerRefreshInterval").value = globals.viewerRefreshInterval_ms / 1000;
// Create the Viewer itself:
viewer = new Viewer(globals.viewerRefreshInterval_ms, globals.viewerConsecutiveImages, globals.viewerIsEnabled);
// The active/enabled state of the Viewer is persisted in the globals. If enabled, start timers etc:
if (viewer.enabled) {
viewer.enable();
}
}
function generateView(viewName, view){
var viewElement = document.getElementById(viewName);
// Dynamically create a control for each listed API command:
view.apiCommands.forEach(function (cmd, index) {
// Header, e.g. "setSaturation"
var header = document.createElement('h3');
header.setAttribute('class', "autogenerated");
header.append(cmd);
viewElement.appendChild(header);
// Description what the API command does
var descriptionText = document.createElement('p');
descriptionText.append(commandJson[cmd]["Function"]);
descriptionText.setAttribute('class', "autogenerated");
viewElement.appendChild(descriptionText);
// Create the command parameter fields and/or the send button:
createCommandControl(viewElement, cmd);
});
}
function createCommandControl(viewElement, cmd, addSendButton = true, idSuffix = "") {
var exampleParams = commandJson[cmd]["ExampleParams"];
var paramOptions = commandJson[cmd]["paramOptions"];
if (exampleParams === null) {
// Probably a get-command. A single button is enough.
if (addSendButton) {
const b = document.createElement("button");
b.setAttribute('onclick', "sendCommand('"+cmd+"', false);");
b.setAttribute('class', "sendToCamera autogenerated");
b.innerHTML = "Get (from camera)";
viewElement.appendChild(b);
}
}
else {
// Probably a set-command. Add a form where the parameter values can be inputted.
const f = document.createElement("form");
f.setAttribute('target', "_blank");
f.setAttribute('onsubmit', "return false;");
f.setAttribute('class', "autogenerated");
// Add all required parameters to the form. Note that the Foscam API (always?) requires that all parameters are given,
// and any missing parameters are reset to some default. This means you cannot set only one parameter value of a
// set command.
for (const [paramName, exampleValue] of Object.entries(exampleParams)){
var paramInputId = cmd+paramName+idSuffix; // Note: this format (with empty idSuffix) is assumed also elsewhere (when clicking the send button)
// label of a parameter
const l = document.createElement("label");
l.innerHTML = paramName;
l.setAttribute('for', paramInputId);
l.setAttribute('class', "autogenerated");
f.appendChild(l);
if (paramOptions !== null && (paramName in paramOptions))
{
// A dropdown for inputting the parameter value
const i = document.createElement("select");
i.setAttribute('id', paramInputId);
i.setAttribute('name', paramInputId);
i.setAttribute('class', "autogenerated");
if (paramOptions[paramName]['optionsType'] == 'list') {
// only a list of options is known
paramOptions[paramName]['options'].forEach(function (optionValue, index) {
i.add(new Option(optionValue, optionValue));
});
}
else { // assume optionsType == 'dict'
// a map of names and values is known
for (const [optionName, optionValue] of Object.entries(paramOptions[paramName]['options'])){
i.add(new Option(optionName, optionValue));
}
}
i.value = exampleValue;
f.appendChild(i);
}
else {
// A text box for inputting the parameter value
const i = document.createElement("input");
i.setAttribute('id', paramInputId);
i.setAttribute('name', paramInputId);
i.setAttribute('type', "text");
i.setAttribute('placeholder', exampleValue);
i.setAttribute('class', "autogenerated");
f.appendChild(i);
}
f.appendChild(document.createElement("br"));
}
if (addSendButton) {
// the send button
const s = document.createElement("input");
s.setAttribute('type', "submit");
s.setAttribute('class', "sendToCamera autogenerated");
s.setAttribute('value', "Send to camera");
s.setAttribute('onclick', "sendCommand('"+cmd+"', true);");
f.appendChild(s);
}
viewElement.appendChild(f);
}
}
// Setup functions:
function setupSaveCamera() {
var ip = document.getElementById("cameraIp").value;
var port = document.getElementById("cameraPort").value;
if (!port) {
port = "88";
}
var isOlderSdCamera = document.getElementById("cameraIsOldSd").checked;
var name = document.getElementById("cameraName").value;
if (!name) {
name = "";
}
var user = document.getElementById("cameraUser").value;
var pass = document.getElementById("cameraPass").value;
if (!ip || !user) {
alert("Set the IP address, username and password to the fields above.");
throw "IP or user name was empty.";
}
var newCamera = new Camera(ip, user, pass, name, port, isOlderSdCamera);
globals.setup.cameras[newCamera.keyName] = newCamera;
logDebug("Saved new camera. Now cameras:");
logDebug(globals.setup.cameras);
if (globals.selectedCamera === null){
globals.selectedCamera = Object.keys(globals.setup.cameras)[0];
}
saveGlobals();
main();
}
function deleteCamera() {
if (globals.selectedCamera != null){
var cameraToDelete = globals.selectedCamera;
logDebug("Deleting camera "+ cameraToDelete);
delete globals.setup.cameras[cameraToDelete];