@lvce-editor/ipc 1.0.1 → 2.0.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 CHANGED
@@ -5,13 +5,14 @@ Inter Process Communiction for use in Lvce Editor.
5
5
  ### Usage
6
6
 
7
7
  ```js
8
- import { IpcParent, IpcParentType } from '@lvce-editor/ipc'
8
+ import * as IpcParentWithElectronUtilityProcess from '@lvce-editor/ipc/dist/parts/IpcParentWithElectronUtilityProcess/IpcParentWithElectronUtilityProcess.js'
9
9
 
10
- const ipc = await IpcParent.create({
11
- method: IpcParentType.NodeWorker,
12
- path: '/test/worker.js',
10
+ const rawIpc = await IpcParentWithElectronUtilityProcess.create({
11
+ path: '/test/utility-process.js',
13
12
  })
14
13
 
14
+ const ipc = IpcParentWithElectronUtilityProcess.wrap(rawIpc)
15
+
15
16
  ipc.send({
16
17
  jsonrpc: '2.0',
17
18
  method: 'readFile',
package/dist/index.js CHANGED
@@ -1,4 +1,7 @@
1
- export * as IpcChild from './parts/IpcChild/IpcChild.js'
2
- export * as IpcChildType from './parts/IpcChildType/IpcChildType.js'
3
- export * as IpcParent from './parts/IpcParent/IpcParent.js'
4
- export * as IpcParentType from './parts/IpcParentType/IpcParentType.js'
1
+ export * as IpcChildWithElectronMessagePort from './parts/IpcChildWithElectronMessagePort/IpcChildWithElectronMessagePort.js'
2
+ export * as IpcChildWithElectronUtilityProcess from './parts/IpcChildWithElectronUtilityProcess/IpcChildWithElectronUtilityProcess.js'
3
+ export * as IpcChildWithNodeForkedProcess from './parts/IpcChildWithNodeForkedProcess/IpcChildWithNodeForkedProcess.js'
4
+ export * as IpcChildWithWebSocket from './parts/IpcChildWithWebSocket/IpcChildWithWebSocket.js'
5
+ export * as IpcParentWithElectronUtilityProcess from './parts/IpcParentWithElectronUtilityProcess/IpcParentWithElectronUtilityProcess.js'
6
+ export * as IpcParentWithNodeForkedProcess from './parts/IpcParentWithNodeForkedProcess/IpcParentWithNodeForkedProcess.js'
7
+ export * as IpcParentWithNodeWorker from './parts/IpcParentWithNodeWorker/IpcParentWithNodeWorker.js'
@@ -0,0 +1,10 @@
1
+ export const getUtilityProcessPortData = (event) => {
2
+ const { data, ports } = event
3
+ if (ports.length === 0) {
4
+ return data
5
+ }
6
+ return {
7
+ ...data,
8
+ params: [...ports, ...data.params],
9
+ }
10
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/ipc",
3
- "version": "1.0.1",
3
+ "version": "2.0.0",
4
4
  "description": "Inter Process Communication for Lvce Editor",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -1,9 +0,0 @@
1
- import * as IpcChildModule from '../IpcChildModule/IpcChildModule.js'
2
-
3
- export const listen = async ({ method, ...params }) => {
4
- const module = await IpcChildModule.getModule(method)
5
- // @ts-ignore
6
- const rawIpc = await module.listen(params)
7
- const ipc = module.wrap(rawIpc)
8
- return ipc
9
- }
@@ -1,10 +0,0 @@
1
- import * as IpcChildType from '../IpcChildType/IpcChildType.js'
2
-
3
- export const getModule = (method) => {
4
- switch (method) {
5
- case IpcChildType.ElectronMessagePort:
6
- return import('../IpcChildWithElectronMessagePort/IpcChildWithElectronMessagePort.js')
7
- default:
8
- throw new Error('unexpected ipc type')
9
- }
10
- }
@@ -1,5 +0,0 @@
1
- export const NodeWorker = 1
2
- export const NodeForkedProcess = 2
3
- export const WebSocket = 3
4
- export const ElectronUtilityProcess = 4
5
- export const ElectronMessagePort = 5
@@ -1,25 +0,0 @@
1
- import * as IpcParentModule from '../IpcParentModule/IpcParentModule.js'
2
-
3
- /**
4
- *
5
- * @param {*} param0
6
- * @returns {Promise<any>}
7
- */
8
- export const create = async ({ method, ...options }) => {
9
- const module = await IpcParentModule.getModule(method)
10
- // @ts-ignore
11
- const rawIpc = await module.create(options)
12
- // @ts-ignore
13
- if (module.effects) {
14
- // @ts-ignore
15
- module.effects({
16
- rawIpc,
17
- ...options,
18
- })
19
- }
20
- if (options.noReturn) {
21
- return undefined
22
- }
23
- const ipc = module.wrap(rawIpc)
24
- return ipc
25
- }
@@ -1,14 +0,0 @@
1
- import * as IpcParentType from '../IpcParentType/IpcParentType.js'
2
-
3
- export const getModule = (method) => {
4
- switch (method) {
5
- case IpcParentType.NodeWorker:
6
- return import('../IpcParentWithNodeWorker/IpcParentWithNodeWorker.js')
7
- case IpcParentType.NodeForkedProcess:
8
- return import('../IpcParentWithNodeForkedProcess/IpcParentWithNodeForkedProcess.js')
9
- case IpcParentType.ElectronUtilityProcess:
10
- return import('../IpcParentWithElectronUtilityProcess/IpcParentWithElectronUtilityProcess.js')
11
- default:
12
- throw new Error(`unexpected ipc type ${method}`)
13
- }
14
- }
@@ -1,3 +0,0 @@
1
- export const NodeWorker = 1
2
- export const NodeForkedProcess = 2
3
- export const ElectronUtilityProcess = 3