Skip to content

Commit 5a3b627

Browse files
dceejayknolleary
andauthored
UI webcam save defaults (#75)
* one more go at ui-list spacing * Allow ui-webcam to save default camera in browser and set camera via msg.camera * Revert "one more go at ui-list spacing" This reverts commit a65f3e7. * Update node-red-node-ui-webcam/ui_webcam.js Co-authored-by: Nick O'Leary <nick.oleary@gmail.com> * Update node-red-node-ui-webcam/ui_webcam.js Co-authored-by: Nick O'Leary <nick.oleary@gmail.com> * Update node-red-node-ui-webcam/ui_webcam.js Co-authored-by: Nick O'Leary <nick.oleary@gmail.com> Co-authored-by: Nick O'Leary <nick.oleary@gmail.com>
1 parent 36d3e12 commit 5a3b627

File tree

6 files changed

+41
-20
lines changed

6 files changed

+41
-20
lines changed

node-red-node-ui-list/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-node-ui-list",
3-
"version": "0.3.6",
3+
"version": "0.3.5",
44
"description": "Node-RED Dashboard UI widget node for simple list",
55
"author": "Hiroyasu Nishiyama",
66
"contributors": [

node-red-node-ui-list/ui_list.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ module.exports = function(RED) {
5757
var desc = (allowHTML ? String.raw`<span ng-bind-html="item.description | trusted"></span>` : String.raw`{{item.description}}`);
5858
var icon = String.raw`
5959
<img src="{{item.icon}}" class="md-avatar" ng-if="(item.icon !== undefined) && (item.icon !== null)">
60-
<md-icon aria-label="{{item.desc}}" style="color:`+config.tcol+String.raw`" ng-if="(item.icon === undefined) && (item.icon_name !== undefined)"><ui-icon icon="{{item.icon_name}}"></ui-icon></md-icon>
60+
<md-icon aria-label="{{item.desc}}" style="height:unset; margin-top:auto; color:`+config.tcol+String.raw`" ng-if="(item.icon === undefined) && (item.icon_name !== undefined)"><ui-icon icon="{{item.icon_name}}"></ui-icon></md-icon>
6161
<span class="md-avatar" style="font-size:x-large; height:unset;" ng-if="(item.icon === undefined) && (item.icon_unicode !== undefined)"><h1>{{item.icon_unicode}}</h1></span>
6262
<md-icon class="md-avatar-icon" aria-label="{{item.desc}}" ng-if="(item.icon === null) && (item.icon_name === undefined) && (item.icon_unicode === undefined)"></md-icon>
6363
`;

node-red-node-ui-webcam/README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
node-red-node-ui-webcam
2-
============================
2+
=======================
33

44
A Node-RED UI widget node that allows images to be captured from the dashboard.
55

@@ -21,6 +21,9 @@ If a message is passed to the `ui_webcam` node with the `capture` property set,
2121
and if the webcam has been activated on the dashboard, it will capture an image
2222
without the user having to click on the button.
2323

24+
The user can select the default camera to use in the on-screen widget dropdown.
25+
This will be used for future sessions with that browser until changed.
26+
2427
## Browser Support
2528

2629
This node will work in all modern browsers, but not IE.

node-red-node-ui-webcam/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-node-ui-webcam",
3-
"version": "0.3.0",
3+
"version": "0.4.0",
44
"description": "A Node-RED ui node to capture images from a webcam.",
55
"author": "Nick O'Leary",
66
"license": "Apache-2.0",

node-red-node-ui-webcam/ui_webcam.html

+14-10
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
hideCaptureButton: { value: false },
3737
showImage: { value: 2 },
3838
mirror: { value: true },
39-
format: { value:"png" }
39+
format: { value: "png" }
4040
},
4141
inputs:1,
4242
outputs:1,
@@ -121,36 +121,36 @@
121121
<button class="editor-button" id="node-input-size"></button>
122122
</div>
123123
<br />
124-
<div class="form-row" style="min-width: 470px">
125-
<label style="vertical-align: top"><i class="fa fa-cog"></i> Options</label>
124+
<div class="form-row" style="min-width:470px">
125+
<label style="vertical-align:top"><i class="fa fa-cog"></i> Options</label>
126126
<div style="display:inline-block; min-width:350px; width:calc(100% - 120px);">
127127
<div class="form-row">
128-
<label style="width: auto" for="node-input-autoStart">
128+
<label style="width:auto" for="node-input-autoStart">
129129
<input style="width:auto; margin:0" type="checkbox" id="node-input-autoStart"> Start webcam automatically
130130
</label>
131131
</div>
132132
<div class="form-row">
133-
<label style="width: auto" for="node-input-showImage-enable">
133+
<label style="width:auto" for="node-input-showImage-enable">
134134
<input style="width:auto; margin:0" type="checkbox" id="node-input-showImage-enable"> Show image after capture
135135
</label>
136136
<div class="node-row-ui-webcam-showImage-timeout">
137137
<label style="margin-bottom:0; margin-left:20px; width:auto" for="node-input-showImage-timeout">
138-
<input style="width:auto; margin:0" type="checkbox" id="node-input-showImage-timeout"> Clear image after <input style="width:60px; margin: 0" type="text" id="node-input-showImage-time"> seconds
138+
<input style="width:auto; margin:0" type="checkbox" id="node-input-showImage-timeout"> Clear image after <input style="width:60px; margin:0" type="text" id="node-input-showImage-time"> seconds
139139
</label>
140140
</div>
141141
</div>
142142
<div class="form-row">
143-
<label style="width: auto" for="node-input-hideCaptureButton">
143+
<label style="width:auto" for="node-input-hideCaptureButton">
144144
<input style="width:auto; margin:0" type="checkbox" id="node-input-hideCaptureButton"> Hide capture button
145145
</label>
146146
</div>
147147
<div class="form-row">
148-
<label style="width: auto" for="node-input-countdown">
148+
<label style="width:auto" for="node-input-countdown">
149149
<input style="width:auto; margin:0" type="checkbox" id="node-input-countdown"> Use 5 second countdown when triggered
150150
</label>
151151
</div>
152152
<div class="form-row">
153-
<label style="width: auto" for="node-input-mirror">
153+
<label style="width:auto" for="node-input-mirror">
154154
<input style="width:auto; margin:0" type="checkbox" id="node-input-mirror"> Mirror image from webcam
155155
</label>
156156
</div>
@@ -181,12 +181,16 @@ <h3>Inputs</h3>
181181
<dt>capture</dt>
182182
<dd>If set, this will trigger the webcam to capture an image. The webcam must
183183
have been activated on the dashboard first.</dd>
184+
<dt>camera<span class="property-type">Number</span></dt>
185+
<dd>If set to a number that is the index of an available camera, the stream will switch to that camera.</dd>
184186
</dl>
185187
<h3>Outputs</h3>
186188
<dl class="message-properties">
187189
<dt>payload<span class="property-type">Buffer</span></dt>
188-
<dd>The captured image as a png or jpeg.</dd>
190+
<dd>The captured image as a png or jpeg. Most image recognition processes prefer jpeg.</dd>
189191
</dl>
190192
<h3>Details</h3>
193+
The user may set the preferred camera from a dropdown in the on-screen widget.
194+
This will be used by default for future sessions.
191195
<p></p>
192196
</script>

node-red-node-ui-webcam/ui_webcam.js

+20-6
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ module.exports = function(RED) {
221221
$scope.changeCamera = function(deviceId) {
222222
oldActiveCamera = activeCamera;
223223
activeCamera = $scope.data.cameras[deviceId].deviceId;
224+
window.localStorage.setItem("node-red-node-ui-webcam-activeCam",deviceId);
224225
$scope.disableCamera();
225226
$scope.enableCamera();
226227
}
@@ -275,7 +276,10 @@ module.exports = function(RED) {
275276
$scope.data.stream = stream;
276277
$("#ui_webcam_toolbar_"+$scope.$id).show();
277278
if (activeCamera === null) {
278-
activeCamera = stream.getTracks()[0].getSettings().deviceId;
279+
var cam = parseInt(window.localStorage.getItem("node-red-node-ui-webcam-activeCam") || 0);
280+
if (cam < stream.getTracks().length) {
281+
activeCamera = stream.getTracks()[cam].getSettings().deviceId;
282+
}
279283
}
280284
}).catch(handleError);
281285
}
@@ -377,12 +381,22 @@ module.exports = function(RED) {
377381
};
378382

379383
$scope.$watch('msg', function(msg) {
380-
if (!msg) {
381-
return;
382-
}
383-
if (!active) {
384-
return;
384+
if (!msg) { return; }
385+
if (msg.camera !== undefined) {
386+
if (!isNaN(parseInt(msg.camera))) {
387+
var c = parseInt(msg.camera);
388+
if (c >= 0 || c < 16) {
389+
oldActiveCamera = activeCamera;
390+
$scope.disableCamera();
391+
activeCamera = null;
392+
window.localStorage.setItem("node-red-node-ui-webcam-activeCam",c);
393+
if (active !== false) {
394+
$scope.enableCamera();
395+
}
396+
}
397+
}
385398
}
399+
if (!active) { return; }
386400
var img = document.querySelector("img#ui_webcam_image_"+$scope.$id);
387401
if (msg.capture) {
388402
msg.payload = takePhoto();

0 commit comments

Comments
 (0)