Commit fb3fa52ae8a6a43bb49a204be221d95d867ec6cc
1 parent
1844058d
Fix updated data from web camera input widget
Showing
3 changed files
with
21 additions
and
13 deletions
... | ... | @@ -8044,6 +8044,11 @@ |
8044 | 8044 | "resolved": "https://registry.npmjs.org/leaflet/-/leaflet-1.6.0.tgz", |
8045 | 8045 | "integrity": "sha512-CPkhyqWUKZKFJ6K8umN5/D2wrJ2+/8UIpXppY7QDnUZW5bZL5+SEI2J7GBpwh4LIupOKqbNSQXgqmrEJopHVNQ==" |
8046 | 8046 | }, |
8047 | + "leaflet-editable": { | |
8048 | + "version": "1.2.0", | |
8049 | + "resolved": "https://registry.npmjs.org/leaflet-editable/-/leaflet-editable-1.2.0.tgz", | |
8050 | + "integrity": "sha512-wG11JwpL8zqIbypTop6xCRGagMuWw68ihYu4uqrqc5Ep0wnEJeyob7NB2Rt5t74Oih4rwJ3OfwaGbzdowOGfYQ==" | |
8051 | + }, | |
8047 | 8052 | "leaflet-polylinedecorator": { |
8048 | 8053 | "version": "1.6.0", |
8049 | 8054 | "resolved": "https://registry.npmjs.org/leaflet-polylinedecorator/-/leaflet-polylinedecorator-1.6.0.tgz", |
... | ... | @@ -9021,10 +9026,10 @@ |
9021 | 9026 | "integrity": "sha512-4O3GWAYJaauMCILm07weko2rHA8a4kjn7+8Lg4s1d7SxwS/3IpkVD/GljbRrIJ1c1W/XGJ3GbuK7RyYZEJChhw==" |
9022 | 9027 | }, |
9023 | 9028 | "ngx-flowchart": { |
9024 | - "version": "git://github.com/thingsboard/ngx-flowchart.git#97a77477ca8579becf0e3a07866046b4536fe30a", | |
9029 | + "version": "git://github.com/thingsboard/ngx-flowchart.git#7a02f4748b5e7821a883c903107af5f20415d026", | |
9025 | 9030 | "from": "git://github.com/thingsboard/ngx-flowchart.git#master", |
9026 | 9031 | "requires": { |
9027 | - "tslib": "^1.10.0" | |
9032 | + "tslib": "^1.13.0" | |
9028 | 9033 | }, |
9029 | 9034 | "dependencies": { |
9030 | 9035 | "tslib": { | ... | ... |
... | ... | @@ -16,11 +16,11 @@ |
16 | 16 | |
17 | 17 | --> |
18 | 18 | <div fxLayout="column" fxLayoutAlign="center center" class="tb-web-camera" tb-fullscreen [fullscreen]="isShowCamera"> |
19 | - <div [fxShow]="isEntityDetected && dataKeyDetected && isCameraSupport && isDeviceDetect" fxFlexFill> | |
19 | + <div *ngIf="isEntityDetected && dataKeyDetected && isCameraSupport && isDeviceDetect" fxFlexFill> | |
20 | 20 | <div [fxShow]="!isShowCamera" fxLayout="column" fxLayoutAlign="space-between center" fxFlexFill> |
21 | 21 | <div class="tb-web-camera__last-photo" fxFlex> |
22 | 22 | <span [fxShow]="!lastPhoto" class="tb-web-camera__last-photo_text" translate>widgets.input-widgets.no-image</span> |
23 | - <img [fxShow]="lastPhoto" class="tb-web-camera__last-photo_img" [src]="lastPhoto" alt="last photo"/> | |
23 | + <img [fxShow]="lastPhoto" class="tb-web-camera__last-photo_img" [src]="safeLastPhoto" alt="last photo"/> | |
24 | 24 | </div> |
25 | 25 | <button mat-raised-button color="primary" (click)="takePhoto()"> |
26 | 26 | {{ "widgets.input-widgets.take-photo" | translate }} |
... | ... | @@ -59,16 +59,16 @@ |
59 | 59 | </div> |
60 | 60 | </div> |
61 | 61 | </div> |
62 | - <div class="message-text" [fxHide]="isEntityDetected"> | |
62 | + <div class="message-text" *ngIf="!isEntityDetected"> | |
63 | 63 | {{ 'widgets.input-widgets.no-entity-selected' | translate }} |
64 | 64 | </div> |
65 | - <div class="message-text" [fxShow]="isEntityDetected && !dataKeyDetected"> | |
65 | + <div class="message-text" *ngIf="isEntityDetected && !dataKeyDetected"> | |
66 | 66 | {{ 'widgets.input-widgets.no-datakey-selected' | translate }} |
67 | 67 | </div> |
68 | - <div class="message-text" [fxShow]="isEntityDetected && dataKeyDetected && !isCameraSupport"> | |
68 | + <div class="message-text" *ngIf="isEntityDetected && dataKeyDetected && !isCameraSupport"> | |
69 | 69 | {{ 'widgets.input-widgets.no-support-web-camera' | translate }} |
70 | 70 | </div> |
71 | - <div class="message-text" [fxShow]="isEntityDetected && dataKeyDetected && isCameraSupport && !isDeviceDetect"> | |
71 | + <div class="message-text" *ngIf="isEntityDetected && dataKeyDetected && isCameraSupport && !isDeviceDetect"> | |
72 | 72 | {{ 'widgets.input-widgets.no-support-web-camera' | translate }} |
73 | 73 | </div> |
74 | 74 | </div> | ... | ... |
... | ... | @@ -37,6 +37,8 @@ import { AttributeService } from '@core/http/attribute.service'; |
37 | 37 | import { EntityId } from '@shared/models/id/entity-id'; |
38 | 38 | import { AttributeScope, DataKeyType } from '@shared/models/telemetry/telemetry.models'; |
39 | 39 | import { Observable } from 'rxjs'; |
40 | +import { isString } from '@core/utils'; | |
41 | +import { DomSanitizer, SafeUrl } from '@angular/platform-browser'; | |
40 | 42 | |
41 | 43 | interface WebCameraInputWidgetSettings { |
42 | 44 | widgetTitle: string; |
... | ... | @@ -62,6 +64,7 @@ export class WebCameraInputWidgetComponent extends PageComponent implements OnIn |
62 | 64 | private overlay: Overlay, |
63 | 65 | private utils: UtilsService, |
64 | 66 | private attributeService: AttributeService, |
67 | + private sanitizer: DomSanitizer | |
65 | 68 | ) { |
66 | 69 | super(store); |
67 | 70 | } |
... | ... | @@ -109,8 +112,8 @@ export class WebCameraInputWidgetComponent extends PageComponent implements OnIn |
109 | 112 | isPreviewPhoto = false; |
110 | 113 | singleDevice = true; |
111 | 114 | updatePhoto = false; |
112 | - previewPhoto: any; | |
113 | - lastPhoto: any; | |
115 | + previewPhoto: SafeUrl; | |
116 | + lastPhoto: SafeUrl; | |
114 | 117 | |
115 | 118 | private static hasGetUserMedia(): boolean { |
116 | 119 | return !!(window.navigator.mediaDevices && window.navigator.mediaDevices.getUserMedia); |
... | ... | @@ -159,8 +162,8 @@ export class WebCameraInputWidgetComponent extends PageComponent implements OnIn |
159 | 162 | |
160 | 163 | private updateWidgetData(data: Array<DatasourceData>) { |
161 | 164 | const keyData = data[0].data; |
162 | - if (keyData && keyData.length) { | |
163 | - this.lastPhoto = keyData[0][1]; | |
165 | + if (keyData?.length && isString(keyData[0][1]) && keyData[0][1].startsWith('data:image/')) { | |
166 | + this.lastPhoto = this.sanitizer.bypassSecurityTrustUrl(keyData[0][1]); | |
164 | 167 | } |
165 | 168 | } |
166 | 169 | |
... | ... | @@ -256,7 +259,7 @@ export class WebCameraInputWidgetComponent extends PageComponent implements OnIn |
256 | 259 | |
257 | 260 | const mimeType: string = this.settings.imageFormat ? this.settings.imageFormat : WebCameraInputWidgetComponent.DEFAULT_IMAGE_TYPE; |
258 | 261 | const quality: number = this.settings.imageQuality ? this.settings.imageQuality : WebCameraInputWidgetComponent.DEFAULT_IMAGE_QUALITY; |
259 | - this.previewPhoto = this.canvasElement.toDataURL(mimeType, quality); | |
262 | + this.previewPhoto = this.sanitizer.bypassSecurityTrustUrl(this.canvasElement.toDataURL(mimeType, quality)); | |
260 | 263 | this.isPreviewPhoto = true; |
261 | 264 | } |
262 | 265 | ... | ... |