@mpxjs/api-proxy 2.10.16-beta.1 → 2.10.16-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { noop } from '@mpxjs/utils'
|
|
2
|
+
|
|
3
|
+
const qualityValue = {
|
|
4
|
+
high: 90,
|
|
5
|
+
normal: 75,
|
|
6
|
+
low: 50,
|
|
7
|
+
original: 100
|
|
8
|
+
}
|
|
9
|
+
export default class CreateCamera {
|
|
10
|
+
constructor () {
|
|
11
|
+
const navigation = Object.values(global.__mpxPagesMap || {})[0]?.[1]
|
|
12
|
+
this.camera = navigation?.camera || {}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
setZoom (options = {}) {
|
|
16
|
+
const { zoom, success = noop, fail = noop, complete = noop } = options
|
|
17
|
+
if (this.camera.setZoom) {
|
|
18
|
+
this.camera.setZoom(zoom)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
takePhoto (options = {}) {
|
|
22
|
+
const { success = noop, fail = noop, complete = noop } = options
|
|
23
|
+
const takePhoto = this.camera.getTakePhoto?.()
|
|
24
|
+
if (takePhoto) {
|
|
25
|
+
takePhoto({
|
|
26
|
+
quality: qualityValue[options.quality || 'normal']
|
|
27
|
+
}).then((res) => {
|
|
28
|
+
const result = {
|
|
29
|
+
errMsg: 'takePhoto:ok',
|
|
30
|
+
tempImagePath: res.path
|
|
31
|
+
}
|
|
32
|
+
success(result)
|
|
33
|
+
complete(result)
|
|
34
|
+
}).catch(() => {
|
|
35
|
+
const result = {
|
|
36
|
+
errMsg: 'takePhoto:fail'
|
|
37
|
+
}
|
|
38
|
+
fail(result)
|
|
39
|
+
complete(result)
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
startRecord (options = {}) {
|
|
44
|
+
let { timeout = 30, success = noop, fail = noop, complete = noop, timeoutCallback = noop } = options
|
|
45
|
+
timeout = timeout > 300 ? 300 : timeout
|
|
46
|
+
let recordTimer = null
|
|
47
|
+
let isTimeout = false
|
|
48
|
+
const startRecord = this.camera.getStartRecord?.()
|
|
49
|
+
if (startRecord) {
|
|
50
|
+
const result = {
|
|
51
|
+
errMsg: 'startRecord:ok'
|
|
52
|
+
}
|
|
53
|
+
success(result)
|
|
54
|
+
complete(result)
|
|
55
|
+
startRecord({
|
|
56
|
+
onRecordingError: (res) => {
|
|
57
|
+
clearTimeout(recordTimer)
|
|
58
|
+
timeoutCallback()
|
|
59
|
+
},
|
|
60
|
+
onRecordingFinished: (res) => {
|
|
61
|
+
if (isTimeout) {
|
|
62
|
+
console.log('record timeout, ignore', res)
|
|
63
|
+
}
|
|
64
|
+
clearTimeout(recordTimer)
|
|
65
|
+
console.log('record finished', res)
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
recordTimer = setTimeout(() => { // 超时自动停止
|
|
69
|
+
if (this.camera.stopRecord) {
|
|
70
|
+
this.camera.stopRecord().catch(() => {})
|
|
71
|
+
}
|
|
72
|
+
}, timeout * 1000)
|
|
73
|
+
} else {
|
|
74
|
+
const result = {
|
|
75
|
+
errMsg: 'startRecord:fail to initialize the camera'
|
|
76
|
+
}
|
|
77
|
+
fail(result)
|
|
78
|
+
complete(result)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
stopRecord(options = {}) {
|
|
82
|
+
const { success = noop, fail = noop, complete = noop } = options
|
|
83
|
+
const stopRecord = this.camera.getStopRecord?.()
|
|
84
|
+
if (stopRecord) {
|
|
85
|
+
stopRecord().then((res) => {
|
|
86
|
+
console.log('stopRecord res', res)
|
|
87
|
+
const result = {
|
|
88
|
+
errMsg: 'stopRecord:ok',
|
|
89
|
+
tempVideoPath: res.path,
|
|
90
|
+
duration: res.duration * 1000, // 转成ms
|
|
91
|
+
size: res.fileSize
|
|
92
|
+
}
|
|
93
|
+
success(result)
|
|
94
|
+
complete(result)
|
|
95
|
+
}).catch((e) => {
|
|
96
|
+
console.log('stopRecord error', e)
|
|
97
|
+
const result = {
|
|
98
|
+
errMsg: 'stopRecord:fail'
|
|
99
|
+
}
|
|
100
|
+
fail(result)
|
|
101
|
+
complete(result)
|
|
102
|
+
})
|
|
103
|
+
} else {
|
|
104
|
+
const result = {
|
|
105
|
+
errMsg: 'stopRecord:fail to initialize the camera'
|
|
106
|
+
}
|
|
107
|
+
fail(result)
|
|
108
|
+
complete(result)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
package/src/platform/index.js
CHANGED