@lvce-editor/ipc 3.7.1 → 4.0.1

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/dist/index.d.ts CHANGED
@@ -1,6 +1,15 @@
1
+ interface Ipc {
2
+ readonly send: (message: any) => void
3
+ readonly sendAndTransfer: (message: any, transfer: any) => void
4
+ readonly on: any
5
+ readonly onmessage: any
6
+ readonly dispose: () => void
7
+ readonly isDisposed: () => void
8
+ }
9
+
1
10
  interface IpcChild {
2
11
  readonly listen: any
3
- readonly wrap: any
12
+ readonly wrap: (rawIpc: any) => Ipc
4
13
  }
5
14
 
6
15
  export const IpcChildWithElectronMessagePort: IpcChild
@@ -11,7 +20,7 @@ export const IpcChildWithNodeWorker: IpcChild
11
20
 
12
21
  interface IpcParent {
13
22
  readonly create: any
14
- readonly wrap: any
23
+ readonly wrap: (rawIpc: any) => Ipc
15
24
  }
16
25
 
17
26
  export const IpcParentWithElectronUtilityProcess: IpcParent
package/dist/index.js CHANGED
@@ -185,7 +185,11 @@ const wrap$a = messagePort => {
185
185
  // @ts-ignore
186
186
  const wrappedListener = event => {
187
187
  const actualData = getActualData$1(event);
188
- listener(actualData);
188
+ const syntheticEvent = {
189
+ data: actualData,
190
+ target: this
191
+ };
192
+ listener(syntheticEvent);
189
193
  };
190
194
  this.messagePort.on(event, wrappedListener);
191
195
  } else if (event === 'close') {
@@ -260,7 +264,11 @@ const wrap$9 = parentPort => {
260
264
  // @ts-ignore
261
265
  const wrappedListener = event => {
262
266
  const actualData = getUtilityProcessPortData(event);
263
- listener(actualData);
267
+ const syntheticEvent = {
268
+ data: actualData,
269
+ target: this
270
+ };
271
+ listener(syntheticEvent);
264
272
  };
265
273
  this.parentPort.on(event, wrappedListener);
266
274
  } else if (event === 'close') {
@@ -470,7 +478,11 @@ const wrap$6 = process => {
470
478
  // @ts-ignore
471
479
  const wrappedListener = (event, handle) => {
472
480
  const actualData = getActualData(event, handle);
473
- listener(actualData);
481
+ const syntheticEvent = {
482
+ data: actualData,
483
+ target: this
484
+ };
485
+ listener(syntheticEvent);
474
486
  };
475
487
  this.process.on(event, wrappedListener);
476
488
  } else if (event === 'close') {
@@ -514,7 +526,14 @@ const wrap$5 = port => {
514
526
  return {
515
527
  port,
516
528
  on(event, listener) {
517
- this.port.on(event, listener);
529
+ const wrappedListener = message => {
530
+ const event = {
531
+ data: message,
532
+ target: this
533
+ };
534
+ listener(event);
535
+ };
536
+ this.port.on(event, wrappedListener);
518
537
  },
519
538
  off(event, listener) {
520
539
  this.port.off(event, listener);
@@ -553,7 +572,14 @@ const wrap$4 = parentPort => {
553
572
  return {
554
573
  parentPort,
555
574
  on(event, listener) {
556
- this.parentPort.on(event, listener);
575
+ const wrappedListener = message => {
576
+ const event = {
577
+ data: message,
578
+ target: this
579
+ };
580
+ listener(event);
581
+ };
582
+ this.parentPort.on(event, wrappedListener);
557
583
  },
558
584
  off(event, listener) {
559
585
  this.parentPort.off(event, listener);
@@ -697,7 +723,11 @@ const wrap$3 = webSocket => {
697
723
  // @ts-ignore
698
724
  const wrappedListener = message => {
699
725
  const data = deserialize(message);
700
- listener(data);
726
+ const event = {
727
+ data,
728
+ target: this
729
+ };
730
+ listener(event);
701
731
  };
702
732
  webSocket.on('message', wrappedListener);
703
733
  break;
@@ -829,7 +859,6 @@ const create$2 = async ({
829
859
  childProcess.stdout.pipe(process.stdout);
830
860
  const {
831
861
  type,
832
- event,
833
862
  stdout,
834
863
  stderr
835
864
  } = await getFirstUtilityProcessEvent(childProcess);
@@ -847,7 +876,14 @@ const wrap$2 = process => {
847
876
  process,
848
877
  // @ts-ignore
849
878
  on(event, listener) {
850
- this.process.on(event, listener);
879
+ const wrappedListener = message => {
880
+ const syntheticEvent = {
881
+ data: message,
882
+ target: this
883
+ };
884
+ listener(syntheticEvent);
885
+ };
886
+ this.process.on(event, wrappedListener);
851
887
  },
852
888
  // @ts-ignore
853
889
  send(message) {
@@ -993,7 +1029,6 @@ const create$1 = async ({
993
1029
  const {
994
1030
  type,
995
1031
  event,
996
- stdout,
997
1032
  stderr
998
1033
  } = await getFirstNodeChildProcessEvent(childProcess);
999
1034
  if (type === Exit) {
@@ -1018,7 +1053,14 @@ const wrap$1 = childProcess => {
1018
1053
  childProcess,
1019
1054
  // @ts-ignore
1020
1055
  on(event, listener) {
1021
- this.childProcess.on(event, listener);
1056
+ const wrappedListener = message => {
1057
+ const syntheticEvent = {
1058
+ data: message,
1059
+ target: this
1060
+ };
1061
+ listener(syntheticEvent);
1062
+ };
1063
+ this.childProcess.on(event, wrappedListener);
1022
1064
  },
1023
1065
  // @ts-ignore
1024
1066
  off(event, listener) {
@@ -1098,7 +1140,14 @@ const wrap = worker => {
1098
1140
  worker,
1099
1141
  // @ts-ignore
1100
1142
  on(event, listener) {
1101
- this.worker.on(event, listener);
1143
+ const wrappedListener = message => {
1144
+ const syntheticEvent = {
1145
+ data: message,
1146
+ target: this
1147
+ };
1148
+ listener(syntheticEvent);
1149
+ };
1150
+ this.worker.on(event, wrappedListener);
1102
1151
  },
1103
1152
  // @ts-ignore
1104
1153
  send(message) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/ipc",
3
- "version": "3.7.1",
3
+ "version": "4.0.1",
4
4
  "description": "Inter Process Communication for Lvce Editor",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",