Skip to main content

bn.createCameraContext

createCameraContext(): CameraContext

description return a CameraContext instance for the current page

remark supported jssdk >= 4.11.0

example

const cameraContext = bn.createCameraContext()
cameraContext.takePhoto({}).then((res) => {
console.log(res)
})

Returns

CameraContext

Interface: CameraContext

NameTypeDescription
takePhoto(options): Promise<TakePhotoCallbackResult>take a photo, return the temp file path of the photo
startRecord(options): Promise<StartRecordCallbackResult>start record video
stopRecord(options): Promise<StopRecordCallbackResult>stop record video
setZoom(options): Promise<SetZoomCallbackResult>set zoom of camera

takePhoto

takePhoto(options): Promise<TakePhotoCallbackResult>

take a photo, return the temp file path of the photo

Parameters

NameType
optionsTakePhotoOptions

Returns

Promise<TakePhotoCallbackResult>


startRecord

startRecord(options): Promise<StartRecordCallbackResult>

start record video

Parameters

NameType
optionsStartRecordOptions

Returns

Promise<StartRecordCallbackResult>


stopRecord

stopRecord(options): Promise<StopRecordCallbackResult>

stop record video

Parameters

NameType
optionsStopRecordOptions

Returns

Promise<StopRecordCallbackResult>


setZoom

setZoom(options): Promise<SetZoomCallbackResult>

set zoom of camera

Parameters

NameType
optionsSetZoomOptions

Returns

Promise<SetZoomCallbackResult>

Interface: TakePhotoCallbackResult

NameTypeDescription
tempImagePathstringimage file path
errMsg?string

Interface: TakePhotoOptions

NameTypeDescription
quality?"normal" | "high" | "low"photo quality, default normal
selfieMirror?booleanis selfie mirror, default true, only work for front camera. Android is not supported yet
onSuccess?(res): voidcallback when success
onFail?(err): voidcallback when fail
onComplete?(res): voidcallback when complete (success or fail)

onSuccess

Optional onSuccess(res): void

callback when success

Parameters

NameType
resTakePhotoCallbackResult

Returns

void


onFail

Optional onFail(err): void

callback when fail

Parameters

NameType
errOnErrorCallbackResult

Returns

void


onComplete

Optional onComplete(res): void

callback when complete (success or fail)

Parameters

NameType
resTakePhotoCallbackResult | OnErrorCallbackResult

Returns

void

Interface: OnErrorCallbackResult

NameTypeDescription
errnonumber
errMsgstring

Interface: StartRecordCallbackResult

NameTypeDescription

Interface: StartRecordOptions

NameTypeDescription
timeout?numberlargest record time in seconds, default 30s
selfieMirror?booleanis selfie mirror, default true, only work for front camera. Android is not supported yet
timeoutCallback?RecordTimeoutCallbackrecord timeout callback
onSuccess?(res): voidcallback when success
onFail?(err): voidcallback when fail
onComplete?(res): voidcallback when complete (success or fail)

onSuccess

Optional onSuccess(res): void

callback when success

Parameters

NameType
resStartRecordCallbackResult

Returns

void


onFail

Optional onFail(err): void

callback when fail

Parameters

NameType
errOnErrorCallbackResult

Returns

void


onComplete

Optional onComplete(res): void

callback when complete (success or fail)

Parameters

NameType
resStartRecordCallbackResult | OnErrorCallbackResult

Returns

void

Interface: StopRecordCallbackResult

NameTypeDescription
tempThumbPathstringthumbnail file path
tempVideoPathstringvideo file path
errMsg?string

Interface: StopRecordOptions

NameTypeDescription

Interface: SetZoomCallbackResult

NameTypeDescription
zoomnumberzoomed value
errMsg?string

Interface: SetZoomOptions

NameTypeDescription
zoomnumberzoom value, range 1 ~ maxZoom
onSuccess?(res): voidcallback when success
onFail?(err): voidcallback when fail
onComplete?(res): voidcallback when complete (success or fail)

onSuccess

Optional onSuccess(res): void

callback when success

Parameters

NameType
resSetZoomCallbackResult

Returns

void


onFail

Optional onFail(err): void

callback when fail

Parameters

NameType
errOnErrorCallbackResult

Returns

void


onComplete

Optional onComplete(res): void

callback when complete (success or fail)

Parameters

NameType
resSetZoomCallbackResult | OnErrorCallbackResult

Returns

void