buildfire.services.camera
This service accesses the device's camera.
This service works only on devices
Requirements
Widget
Include camera.js
file in widget header right after the buildfire.min.js
<head>
<!-- ... -->
<script src="../../../scripts/buildfire.min.js"></script>
<script src="../../../scripts/buildfire/services/camera/camera.js"></script>
</head>
Methods
getPicture()
buildfire.services.camera.getPicture(options, callback)
This method will open the device's default camera application that allows users to snap pictures by default. It may also ask the user for permission to access the Camera if it hasn't previously.
buildfire.services.camera.getPicture({}, (err, imageData) => {
if (err) return console.error(err);
console.log("Image src is" + imageData);
});
options
Name | Type | Required | Description | Default |
---|---|---|---|---|
quality | number | no | Quality of the saved image, expressed as a range of 0-100, where 100 is typically full resolution with no loss from file compression. | 50 |
destinationType | number | no | Choose the format of the return value. 0 for Data_URL, 1 for FILE_URI. | 1 |
sourceType | number | no | Set the source of the picture. "0 for PHOTOLIBRARY, 1 for CAMERA and 2 for SAVEDPHOTOALBUM". | 1 |
upload | boolean | no | Allows automatic upload of the captured image to pubilcFiles. The callback will return a url to the uploaded image. Setting this option to true will ignore destinationType. | false |
callback(err, imageData)
Callback function that provides the image data
Name | Type | Description |
---|---|---|
err | string | error string, null when operation is successful |
imageData | string | Image src or data uri, depending on destinationType |
getVideo()
buildfire.services.camera.getVideo(options, callback)
This method will open the device's default camera application that allows users to record videos. It may also ask the user for permission to access the camera and microphone if it hasn't previously.
buildfire.services.camera.getVideo({}, (err, videoData) => {
if (err) return console.error(err);
console.log("Video src is" + videoData.localURI);
});
options
Name | Type | Required | Description | Default |
---|---|---|---|---|
quality | number | no | 0 will record in low quality, 1 records high quality | 0 |
duration | number | no | Maximum Recording duration, in seconds. | 300 |
upload | boolean | no | Allows automatic upload of the captured video to pubilcFiles. The callback will return a url to the uploaded video. | false |
Some Android devices do not support duration
. The video will be trimmed to match the max duration, and trimmed
will return as true
callback(err, videoData)
Callback function that provides the video data
Name | Type | Description |
---|---|---|
err | string | error string, null when operation is successful |
videoData.localURI | string | Local URI for the captured video |
videoData.path | string | Full path for the captured video |
videoData.url | string | If upload was passed, this URL points to the uploaded video |
videoData.trimmed | boolean | If duration was passed, but the device does not support it, the video will be trimmed |
isAuthorized()
buildfire.services.camera.isAuthorized(options, callback)
Checks if the device has a camera and the application is authorized to use it as well.
buildfire.services.camera.isAuthorized(null, (err, status) => {
if (err) return console.error(err);
console.log("is Authorized:" + status);
});
options
Reserved for future usage. can be passed as null
.
callback(err, status)
Callback function that provides the status
Name | Type | Description |
---|---|---|
err | string | error string, REBUILD_REQUIRED indicates that current build needs updating, null when operation is successful |
status | boolean | Authorization status |
requestAuthorization()
buildfire.services.camera.requestAuthorization(options, callback)
Requests camera authorization for the application that will show a native prompt asking the user to authorize the camera.
buildfire.services.camera.requestAuthorization(null, (err, result) => {
if (err) return console.error(err);
console.log("request authorization:" + result);
});
options
Reserved for future usage. can be passed as null
.
callback(err, result)
Callback function that provides the result
Name | Type | Description |
---|---|---|
err | string | error string, REBUILD_REQUIRED indicates that current build needs updating, null when operation is successful |
result | string | request result, one of DENIED_ONCE, DENIED_ALWAYS, GRANTED_WHEN_IN_USE, GRANTED or authorized for iOS |
- For iOS devices, denying authorization request would set the authorization status to
DENIED_ALWAYS
which means the only way to allow it back is by changing it from the settings. - For Android devices, denying twice or explicitly selecting Don't ask again would set the authorization status to
DENIED_ALWAYS
.
Using navigator.mediaDevices.getUserMedia
on Android would require restarting the app if the user denied and then allowed the permission within the same session.