
Product
Socket Now Supports pylock.toml Files
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
camera-component
Advanced tools
A Javascript camera component, made with Stencil.js. This is a web component and as such, it does not depend on any framework.
Anyhow it works well with Angular, React, Vue, Stencil, JQuery, any other unimaginable framework or none at all.
See example in examples folder
<script type="module" src="https://unpkg.com/camera-component/dist/camera-component/camera-component.esm.js"></script>
<script nomodule src="https://unpkg.com/camera-component/dist/camera-component/camera-component.js"></script>
<camera-component id="cam" show-preview="true"></camera-component>
<button onclick="cam.start()">Open the camera in embedded mode</button>
<button onclick="cam.start(1)">Open the camera in a modal</button>
<script>
const cam = document.getElementById('cam');
cam.addEventListener('picture', (e) => console.log('Picture in base 64:', e.detail));
cam.addEventListener('backButton', () => console.log('backButton'));
cam.addEventListener('webcamStop', () => console.log('webcamStop'));
</script>
Include the following scripts on the html page:
<script type="module" src="https://unpkg.com/camera-component/dist/camera-component/camera-component.esm.js"></script>
<script nomodule src="https://unpkg.com/camera-component/dist/camera-component/camera-component.js"></script>
Install using npm
npm install camera-component --save
or yarn
yarn add camera-component
// index.js
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
import { applyPolyfills, defineCustomElements } from 'camera-component/loader';
ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();
applyPolyfills().then(() => {
defineCustomElements(window);
});
// App.jsx
import React from 'react';
import 'camera-component';
const App = () => {
return <camera-component />
}
export default App;
// app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
FormsModule,
],
bootstrap: [AppComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
export class AppModule {}
// main.ts
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
import { applyPolyfills, defineCustomElements } from 'camera-component/loader';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.log(err));
applyPolyfills().then(() => {
defineCustomElements()
})
// app.component.ts
import {Component, ElementRef, ViewChild} from '@angular/core';
import 'camera-component';
@Component({
selector: 'app-home',
template: `<camera-component #cam></camera-component>`,
styleUrls: ['./home.component.scss'],
})
export class AppComponent {
@ViewChild('cam') camComponent: ElementRef<HTMLCamComponentElement>;
async onAction() {
await this.camComponent.nativeElement.camComponentMethod();
}
}
// app.component.html
<camera-component />
import { Component } from '@stencil/core';
import 'camera-component';
@Component({
tag: 'camera',
styleUrl: 'camera.scss'
})
export class Camera {
render() {
return (
<camera-component />
);
}
}
This is the camera component, ready to start the cam. It works in two different modes: embedded or in a modal.
<camera-component id="cam" show-preview="true"></camera-component>
<button onclick="cam.start()">Open the camera in embedded mode</button>
<button onclick="cam.start(1)">Open the camera in a modal</button>
<script>
const cam = document.getElementById('cam');
cam.addEventListener('picture', (e) => console.log('Picture in base 64:', e.detail));
cam.addEventListener('backButton', () => console.log('backButton'));
cam.addEventListener('webcamStop', () => console.log('webcamStop'));
</script>
See documentation on Github or complete example
This is the low level camera controller.
<camera-controller id="cam"></camera-controller>
<button onclick="cam.flipCam()">Flip</button>
<button onclick="cam.takePicture()">Take picture</button>
<button onclick="cam.stopWebcam()">Stop cam</button>
<script>
const cam = document.getElementById('cam');
cam.addEventListener('picture', (e) => console.log('Picture in base 64:', e.detail.snapshot));
cam.addEventListener('backButton', () => console.log('backButton'));
cam.addEventListener('webcamStop', () => console.log('webcamStop'));
</script>
See documentation on Github or complete example
Camera component, this is the main component.
Property | Attribute | Description | Type | Default |
---|---|---|---|---|
allowGallery | allow-gallery | If true, allows taking picture from gallery | boolean | true |
backButtonStopCam | back-button-stop-cam | If true, stops cam when back button is pushed | boolean | true |
orientation | orientation | Camera selected - user: front camera - environtment: back camera | CamOrientation.environment | CamOrientation.user | CamOrientation.environment |
showPreview | show-preview | If true, shows image preview when snap | boolean | true |
Event | Description | Type |
---|---|---|
backButton | Event emitted when back button is pushed | CustomEvent<void> |
picture | Event emitted when snap | CustomEvent<any> |
webcamStop | Event emitted when cam stop | CustomEvent<any> |
start(camMode?: CamMode) => Promise<void>
Method to open the camera
Type: Promise<void>
void
stop() => Promise<void>
Method to stop the camera
Type: Promise<void>
void
graph TD;
camera-component --> camera-controller
camera-controller --> ion-footer
camera-controller --> ion-button
camera-controller --> ion-icon
ion-button --> ion-ripple-effect
style camera-component fill:#f9f,stroke:#333,stroke-width:4px
Built with StencilJS
Camera controller component
Property | Attribute | Description | Type | Default |
---|---|---|---|---|
allowGallery | allow-gallery | If true, allows taking picture from gallery | boolean | true |
backButtonStopCam | back-button-stop-cam | If true, stops cam when back button is pushed | boolean | true |
camMode | cam-mode | Camera mode | CamMode.embedded | CamMode.modal | undefined |
height | height | Video element height | number | undefined |
orientation | orientation | Selected camera - user: front camera - environtment: back camera | CamOrientation.environment | CamOrientation.user | CamOrientation.environment |
showPreview | show-preview | If true, shows image preview when snap | boolean | true |
width | width | Video element width | number | undefined |
Event | Description | Type |
---|---|---|
backButton | Event emitted when back button is pushed | CustomEvent<void> |
picture | Event emitted when snap | CustomEvent<any> |
webcamStop | Event emitted when cam is stoped | CustomEvent<any> |
flipCam() => Promise<void>
Switch between front and back cam
Type: Promise<void>
void
resize(width: number, height: number) => Promise<void>
Change the video element size
Type: Promise<void>
void
stopWebcam() => Promise<void>
Stop the webcam Emits webcamStop event
Type: Promise<void>
void
takePicture() => Promise<void>
Captures the picture Emits picture event
Type: Promise<void>
void
graph TD;
camera-controller --> ion-footer
camera-controller --> ion-button
camera-controller --> ion-icon
ion-button --> ion-ripple-effect
camera-component --> camera-controller
style camera-controller fill:#f9f,stroke:#333,stroke-width:4px
Built with StencilJS
FAQs
Vainilla JavaScript Camera Component
The npm package camera-component receives a total of 26 weekly downloads. As such, camera-component popularity was classified as not popular.
We found that camera-component demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
Security News
Research
Socket uncovered two npm packages that register hidden HTTP endpoints to delete all files on command.
Research
Security News
Malicious Ruby gems typosquat Fastlane plugins to steal Telegram bot tokens, messages, and files, exploiting demand after Vietnam’s Telegram ban.