Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature camera flash #1824

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@ngx-formly/core": "^5.10.22",
"@ngx-formly/material": "^5.10.22",
"@ngx-formly/schematics": "^5.10.22",
"@numbersprotocol/preview-camera": "github:numbersprotocol/preview-camera#release-0.0.2-auto-rotate-fix",
"@numbersprotocol/preview-camera": "github:numbersprotocol/preview-camera",
"@numbersprotocol/preview-video": "github:numbersprotocol/preview-video",
"@techiediaries/ngx-qrcode": "^9.1.0",
"async-mutex": "^0.3.2",
Expand Down
5 changes: 5 additions & 0 deletions src/app/features/home/custom-camera/custom-camera.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
>
<ng-container *ngIf="(mode$ | ngrxPush) === 'capture'">
<div id="camera-flash-placeholder"></div>

<mat-icon class="flash-camera-button" (click)="enableTorch()">
{{ isFlashOn ? 'flash_on' : 'flash_off' }}
</mat-icon>

<div
class="select-from-go-pro-camera-button"
*ngIf="lastConnectedGoProDevice$ | ngrxPush"
Expand Down
6 changes: 6 additions & 0 deletions src/app/features/home/custom-camera/custom-camera.page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ mat-icon {
width: 36px;
}

mat-icon.flash-camera-button {
position: absolute;
top: 16px;
left: 16px;
}

mat-icon.close-camera-button {
position: absolute;
top: 16px;
Expand Down
17 changes: 17 additions & 0 deletions src/app/features/home/custom-camera/custom-camera.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export class CustomCameraPage implements OnInit, OnDestroy {
curCaptureType?: 'image' | 'video' = 'image';
curCaptureSrc?: string;

isFlashOn = false;

readonly lastConnectedGoProDevice$ =
this.goProBluetoothService.lastConnectedDevice$;

Expand All @@ -67,6 +69,12 @@ export class CustomCameraPage implements OnInit, OnDestroy {
).then((listener: any) => (this.captureVideoFinishedListener = listener));

this.startPreviewCamera();

this.isTorchOn().then(value => {
console.log(`isFlashOn: ${value.result}`);

return (this.isFlashOn = value.result);
});
}

async ionViewDidEnter() {
Expand Down Expand Up @@ -167,6 +175,15 @@ export class CustomCameraPage implements OnInit, OnDestroy {
this.leaveCustomCamera();
}

async isTorchOn() {
return this.customCameraService.isTorchOn();
}

async enableTorch() {
await this.customCameraService.enableTorch(!this.isFlashOn);
this.isFlashOn = (await this.customCameraService.isTorchOn()).result;
}

async leaveCustomCamera() {
return this.location.back();
}
Expand Down
10 changes: 10 additions & 0 deletions src/app/features/home/custom-camera/custom-camera.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ export class CustomCameraService {
await this.filesystemPlugin.deleteFile({ path: filePath });
}

// eslint-disable-next-line class-methods-use-this
async isTorchOn() {
return await PreviewCamera.isTorchOn();
}

// eslint-disable-next-line class-methods-use-this
async enableTorch(enable: boolean) {
return await PreviewCamera.enableTorch({ enable });
}

private changeGlobalCSSBackgroundToTransparent() {
document.querySelector('body')?.classList.add(this.globalCSSClass);
document.querySelector('ion-app')?.classList.add(this.globalCSSClass);
Expand Down