bare-media 1.1.0 → 1.2.0
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/README.md +3 -3
- package/client.js +56 -0
- package/package.json +4 -3
- package/shared/codecs.js +1 -0
- package/client/cross-spawn/bare-kit.js +0 -16
- package/client/cross-spawn/index.js +0 -9
- package/client/cross-spawn/pear.js +0 -11
- package/client/index.js +0 -51
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# bare-media
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A set of media apis for Bare
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -27,7 +27,7 @@ const worker = new WorkerClient()
|
|
|
27
27
|
const data = await worker.createPreview({ path, maxWidth, maxHeight })
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
> NOTE: A worker spawns when an operation is requested and it stays running until the parent process is killed.
|
|
30
|
+
> NOTE: A worker spawns when an operation is requested and it stays running until the parent process is killed.
|
|
31
31
|
|
|
32
32
|
Handle close event:
|
|
33
33
|
|
|
@@ -40,7 +40,7 @@ worker.onClose = () => {
|
|
|
40
40
|
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
Call the methods directly without a worker:
|
|
44
44
|
|
|
45
45
|
```js
|
|
46
46
|
import { createPreview } from 'bare-media/worker/media.js'
|
package/client.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { spawn } from 'cross-worker/client'
|
|
2
|
+
import ReadyResource from 'ready-resource'
|
|
3
|
+
|
|
4
|
+
import HRPC from './shared/spec/hrpc/index.js'
|
|
5
|
+
import { isCodecSupported } from './shared/codecs.js'
|
|
6
|
+
|
|
7
|
+
export class WorkerClient extends ReadyResource {
|
|
8
|
+
worker = null
|
|
9
|
+
rpc = null
|
|
10
|
+
opts = null
|
|
11
|
+
|
|
12
|
+
constructor (opts) {
|
|
13
|
+
super()
|
|
14
|
+
this.initialize(opts)
|
|
15
|
+
this.#attachMethods()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
initialize ({ filename = 'node_modules/bare-media/worker/index.js', requireSource, args } = {}) {
|
|
19
|
+
this.opts = { filename, requireSource, args }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
#attachMethods () {
|
|
23
|
+
const methods = [
|
|
24
|
+
'createPreview',
|
|
25
|
+
'decodeImage'
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
for (const method of methods) {
|
|
29
|
+
this[method] = async (...args) => {
|
|
30
|
+
await this.ready()
|
|
31
|
+
return this.rpc[method](...args)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async _open () {
|
|
37
|
+
await this.#run()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async #run () {
|
|
41
|
+
const { filename, requireSource, args } = this.opts
|
|
42
|
+
const source = requireSource?.()
|
|
43
|
+
this.worker = await spawn(filename, source, args)
|
|
44
|
+
|
|
45
|
+
const ipc = this.worker.IPC
|
|
46
|
+
|
|
47
|
+
ipc.on('end', () => ipc.end())
|
|
48
|
+
ipc.on('close', () => this.onClose?.())
|
|
49
|
+
|
|
50
|
+
this.rpc = new HRPC(ipc)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
isCodecSupported (mimetype) {
|
|
54
|
+
return isCodecSupported(mimetype)
|
|
55
|
+
}
|
|
56
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bare-media",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -23,10 +23,11 @@
|
|
|
23
23
|
"bare-png": "^1.0.2",
|
|
24
24
|
"bare-tiff": "^1.0.1",
|
|
25
25
|
"bare-webp": "^1.0.3",
|
|
26
|
-
"cross-worker": "^1.
|
|
26
|
+
"cross-worker": "^1.1.0",
|
|
27
27
|
"get-mime-type": "^2.0.1",
|
|
28
28
|
"hrpc": "^4.0.0",
|
|
29
29
|
"hyperschema": "^1.12.3",
|
|
30
|
+
"ready-resource": "^1.2.0",
|
|
30
31
|
"uncaughts": "^1.1.1"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
@@ -38,9 +39,9 @@
|
|
|
38
39
|
"test-tmp": "^1.4.0"
|
|
39
40
|
},
|
|
40
41
|
"files": [
|
|
41
|
-
"client",
|
|
42
42
|
"shared",
|
|
43
43
|
"worker",
|
|
44
|
+
"client.js",
|
|
44
45
|
"index.js"
|
|
45
46
|
],
|
|
46
47
|
"standard": {
|
package/shared/codecs.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const codecs = {
|
|
2
2
|
'image/jpeg': () => import('bare-jpeg'),
|
|
3
3
|
'image/jpg': () => import('bare-jpeg'),
|
|
4
|
+
'image/avif': () => import('bare-heif'),
|
|
4
5
|
'image/heic': () => import('bare-heif'),
|
|
5
6
|
'image/heif': () => import('bare-heif'),
|
|
6
7
|
'image/webp': () => import('bare-webp'),
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
const { Worklet } = require('react-native-bare-kit')
|
|
2
|
-
|
|
3
|
-
export const spawn = async ({ requireSource, storagePath, buildVariant, deviceId, devMode }) => {
|
|
4
|
-
const source = requireSource()
|
|
5
|
-
|
|
6
|
-
const worklet = new Worklet()
|
|
7
|
-
|
|
8
|
-
await worklet.start('keet:/main.bundle', source, [
|
|
9
|
-
storagePath,
|
|
10
|
-
buildVariant,
|
|
11
|
-
deviceId,
|
|
12
|
-
devMode
|
|
13
|
-
])
|
|
14
|
-
|
|
15
|
-
return worklet
|
|
16
|
-
}
|
package/client/index.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import HRPC from '../shared/spec/hrpc/index.js'
|
|
2
|
-
import { isCodecSupported } from '../shared/codecs.js'
|
|
3
|
-
import { spawn } from './cross-spawn/index.js'
|
|
4
|
-
|
|
5
|
-
export class WorkerClient {
|
|
6
|
-
worker = null
|
|
7
|
-
rpc = null
|
|
8
|
-
opts = null
|
|
9
|
-
|
|
10
|
-
constructor (opts) {
|
|
11
|
-
this.initialize(opts)
|
|
12
|
-
this.#attachMethods()
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
initialize (opts) {
|
|
16
|
-
const sourcePath = 'node_modules/bare-media/worker/index.js'
|
|
17
|
-
this.opts = { sourcePath, ...opts }
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
#attachMethods () {
|
|
21
|
-
const methods = [
|
|
22
|
-
'createPreview',
|
|
23
|
-
'decodeImage'
|
|
24
|
-
]
|
|
25
|
-
|
|
26
|
-
for (const method of methods) {
|
|
27
|
-
this[method] = async (...args) => {
|
|
28
|
-
await this.run()
|
|
29
|
-
return this.rpc[method](...args)
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async run () {
|
|
35
|
-
if (this.worker !== null) {
|
|
36
|
-
return
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
this.worker = await spawn(this.opts)
|
|
40
|
-
const ipc = this.worker.IPC
|
|
41
|
-
|
|
42
|
-
ipc.on('end', () => ipc.end())
|
|
43
|
-
ipc.on('close', () => this.onClose?.())
|
|
44
|
-
|
|
45
|
-
this.rpc = new HRPC(ipc)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
isCodecSupported (mimetype) {
|
|
49
|
-
return isCodecSupported(mimetype)
|
|
50
|
-
}
|
|
51
|
-
}
|