@lvce-editor/ipc 10.1.0 → 10.2.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/electron.js CHANGED
@@ -438,7 +438,7 @@ class IpcError extends VError {
438
438
  }
439
439
 
440
440
  // @ts-ignore
441
- const create$2 = async ({
441
+ const create$3 = async ({
442
442
  path,
443
443
  argv = [],
444
444
  execArgv = [],
@@ -501,14 +501,14 @@ class IpcParentWithElectronUtilityProcess extends Ipc {
501
501
  this._rawIpc.on('message', callback);
502
502
  }
503
503
  }
504
- const wrap$2 = process => {
504
+ const wrap$3 = process => {
505
505
  return new IpcParentWithElectronUtilityProcess(process);
506
506
  };
507
507
 
508
508
  const IpcParentWithElectronUtilityProcess$1 = {
509
509
  __proto__: null,
510
- create: create$2,
511
- wrap: wrap$2
510
+ create: create$3,
511
+ wrap: wrap$3
512
512
  };
513
513
 
514
514
  class ChildProcessError extends Error {
@@ -626,7 +626,7 @@ const getFirstNodeChildProcessEvent = async childProcess => {
626
626
  };
627
627
 
628
628
  // @ts-ignore
629
- const create$1 = async ({
629
+ const create$2 = async ({
630
630
  path,
631
631
  argv = [],
632
632
  env,
@@ -693,14 +693,14 @@ class IpcParentWithNodeForkedProcess extends Ipc {
693
693
  this._rawIpc.on('message', callback);
694
694
  }
695
695
  }
696
- const wrap$1 = childProcess => {
696
+ const wrap$2 = childProcess => {
697
697
  return new IpcParentWithNodeForkedProcess(childProcess);
698
698
  };
699
699
 
700
700
  const IpcParentWithNodeForkedProcess$1 = {
701
701
  __proto__: null,
702
- create: create$1,
703
- wrap: wrap$1
702
+ create: create$2,
703
+ wrap: wrap$2
704
704
  };
705
705
 
706
706
  const addListener = (emitter, type, callback) => {
@@ -753,7 +753,7 @@ const getFirstNodeWorkerEvent = worker => {
753
753
  const readyMessage = 'ready';
754
754
 
755
755
  // @ts-ignore
756
- const create = async ({
756
+ const create$1 = async ({
757
757
  path,
758
758
  argv = [],
759
759
  env = process.env,
@@ -792,7 +792,7 @@ const create = async ({
792
792
  };
793
793
 
794
794
  // @ts-ignore
795
- const wrap = worker => {
795
+ const wrap$1 = worker => {
796
796
  return {
797
797
  worker,
798
798
  // @ts-ignore
@@ -825,9 +825,70 @@ const wrap = worker => {
825
825
  };
826
826
 
827
827
  const IpcParentWithNodeWorker = {
828
+ __proto__: null,
829
+ create: create$1,
830
+ wrap: wrap$1
831
+ };
832
+
833
+ const getActualDataElectron = event => {
834
+ const {
835
+ data,
836
+ ports
837
+ } = event;
838
+ if (ports.length === 0) {
839
+ return data;
840
+ }
841
+ return {
842
+ ...data,
843
+ params: [...ports, ...data.params]
844
+ };
845
+ };
846
+
847
+ const create = ({
848
+ messagePort
849
+ }) => {
850
+ if (!isMessagePortMain(messagePort)) {
851
+ throw new IpcError('port must be of type MessagePortMain');
852
+ }
853
+ return messagePort;
854
+ };
855
+ const signal = messagePort => {
856
+ messagePort.start();
857
+ };
858
+ class IpcParentWithElectronMessagePort extends Ipc {
859
+ constructor(port) {
860
+ super(port);
861
+ }
862
+ getData = getActualDataElectron;
863
+ send(message) {
864
+ this._rawIpc.postMessage(message);
865
+ }
866
+ sendAndTransfer(message) {
867
+ const {
868
+ newValue,
869
+ transfer
870
+ } = fixElectronParameters(message);
871
+ this._rawIpc.postMessage(newValue, transfer);
872
+ }
873
+ dispose() {
874
+ this._rawIpc.close();
875
+ }
876
+ onMessage(callback) {
877
+ this._rawIpc.on('message', callback);
878
+ }
879
+ onClose(callback) {
880
+ this._rawIpc.on('close', callback);
881
+ }
882
+ }
883
+ const wrap = messagePort => {
884
+ return new IpcParentWithElectronMessagePort(messagePort);
885
+ };
886
+
887
+ const IpcParentWithElectronMessagePort$1 = {
828
888
  __proto__: null,
829
889
  create,
890
+ signal,
830
891
  wrap
831
892
  };
832
893
 
833
- export { IpcParentWithElectronUtilityProcess$1 as IpcParentWithElectronUtilityProcess, IpcParentWithNodeForkedProcess$1 as IpcParentWithNodeForkedProcess, IpcParentWithNodeWorker };
894
+ export { IpcParentWithElectronMessagePort$1 as IpcParentWithElectronMessagePort, IpcParentWithElectronUtilityProcess$1 as IpcParentWithElectronUtilityProcess, IpcParentWithNodeForkedProcess$1 as IpcParentWithNodeForkedProcess, IpcParentWithNodeWorker };
package/dist/index.d.ts CHANGED
@@ -25,3 +25,4 @@ interface IpcParent {
25
25
  export const IpcParentWithElectronUtilityProcess: IpcParent
26
26
  export const IpcParentWithNodeForkedProcess: IpcParent
27
27
  export const IpcParentWithNodeWorker: IpcParent
28
+ export const IpcParentWithElectronMessagePort: IpcParent
package/dist/index.js CHANGED
@@ -97,6 +97,20 @@ const fixElectronParameters = value => {
97
97
  };
98
98
  };
99
99
 
100
+ const getActualDataElectron = event => {
101
+ const {
102
+ data,
103
+ ports
104
+ } = event;
105
+ if (ports.length === 0) {
106
+ return data;
107
+ }
108
+ return {
109
+ ...data,
110
+ params: [...ports, ...data.params]
111
+ };
112
+ };
113
+
100
114
  const attachEvents = that => {
101
115
  const handleMessage = (...args) => {
102
116
  const data = that.getData(...args);
@@ -273,29 +287,14 @@ const listen$8 = ({
273
287
  }
274
288
  return messagePort;
275
289
  };
276
- const signal$6 = messagePort => {
290
+ const signal$7 = messagePort => {
277
291
  messagePort.start();
278
292
  };
279
- const getActualData$1 = event => {
280
- const {
281
- data,
282
- ports
283
- } = event;
284
- if (ports.length === 0) {
285
- return data;
286
- }
287
- return {
288
- ...data,
289
- params: [...ports, ...data.params]
290
- };
291
- };
292
293
  class IpcChildWithElectronMessagePort extends Ipc {
293
294
  constructor(port) {
294
295
  super(port);
295
296
  }
296
- getData(event) {
297
- return getActualData$1(event);
298
- }
297
+ getData = getActualDataElectron;
299
298
  send(message) {
300
299
  this._rawIpc.postMessage(message);
301
300
  }
@@ -316,15 +315,15 @@ class IpcChildWithElectronMessagePort extends Ipc {
316
315
  this._rawIpc.on('close', callback);
317
316
  }
318
317
  }
319
- const wrap$b = messagePort => {
318
+ const wrap$c = messagePort => {
320
319
  return new IpcChildWithElectronMessagePort(messagePort);
321
320
  };
322
321
 
323
322
  const IpcChildWithElectronMessagePort$1 = {
324
323
  __proto__: null,
325
324
  listen: listen$8,
326
- signal: signal$6,
327
- wrap: wrap$b
325
+ signal: signal$7,
326
+ wrap: wrap$c
328
327
  };
329
328
 
330
329
  // @ts-ignore
@@ -354,7 +353,7 @@ const listen$7 = () => {
354
353
  }
355
354
  return parentPort;
356
355
  };
357
- const signal$5 = parentPort => {
356
+ const signal$6 = parentPort => {
358
357
  parentPort.postMessage(readyMessage);
359
358
  };
360
359
  class IpcChildWithElectronUtilityProcess extends Ipc {
@@ -381,15 +380,15 @@ class IpcChildWithElectronUtilityProcess extends Ipc {
381
380
  this._rawIpc.on('message', callback);
382
381
  }
383
382
  }
384
- const wrap$a = parentPort => {
383
+ const wrap$b = parentPort => {
385
384
  return new IpcChildWithElectronUtilityProcess(parentPort);
386
385
  };
387
386
 
388
387
  const IpcChildWithElectronUtilityProcess$1 = {
389
388
  __proto__: null,
390
389
  listen: listen$7,
391
- signal: signal$5,
392
- wrap: wrap$a
390
+ signal: signal$6,
391
+ wrap: wrap$b
393
392
  };
394
393
 
395
394
  const getData$1 = event => {
@@ -403,7 +402,7 @@ const listen$6 = () => {
403
402
  }
404
403
  return globalThis;
405
404
  };
406
- const signal$4 = global => {
405
+ const signal$5 = global => {
407
406
  global.postMessage(readyMessage);
408
407
  };
409
408
  class IpcChildWithModuleWorker extends Ipc {
@@ -429,15 +428,15 @@ class IpcChildWithModuleWorker extends Ipc {
429
428
  this._rawIpc.addEventListener('message', callback);
430
429
  }
431
430
  }
432
- const wrap$9 = global => {
431
+ const wrap$a = global => {
433
432
  return new IpcChildWithModuleWorker(global);
434
433
  };
435
434
 
436
435
  const IpcChildWithModuleWorker$1 = {
437
436
  __proto__: null,
438
437
  listen: listen$6,
439
- signal: signal$4,
440
- wrap: wrap$9
438
+ signal: signal$5,
439
+ wrap: wrap$a
441
440
  };
442
441
 
443
442
  const withResolvers = () => {
@@ -466,8 +465,8 @@ const waitForFirstMessage = async port => {
466
465
 
467
466
  const listen$5 = async () => {
468
467
  const parentIpcRaw = listen$6();
469
- signal$4(parentIpcRaw);
470
- const parentIpc = wrap$9(parentIpcRaw);
468
+ signal$5(parentIpcRaw);
469
+ const parentIpc = wrap$a(parentIpcRaw);
471
470
  const firstMessage = await waitForFirstMessage(parentIpc);
472
471
  if (firstMessage.method !== 'initialize') {
473
472
  throw new IpcError('unexpected first message');
@@ -507,14 +506,14 @@ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
507
506
  this._rawIpc.start();
508
507
  }
509
508
  }
510
- const wrap$8 = port => {
509
+ const wrap$9 = port => {
511
510
  return new IpcChildWithModuleWorkerAndMessagePort(port);
512
511
  };
513
512
 
514
513
  const IpcChildWithModuleWorkerAndMessagePort$1 = {
515
514
  __proto__: null,
516
515
  listen: listen$5,
517
- wrap: wrap$8
516
+ wrap: wrap$9
518
517
  };
519
518
 
520
519
  const getTransferrablesNode = value => {
@@ -541,7 +540,7 @@ const listen$4 = async () => {
541
540
  }
542
541
  return process;
543
542
  };
544
- const signal$3 = process => {
543
+ const signal$4 = process => {
545
544
  process.send(readyMessage);
546
545
  };
547
546
  class IpcChildWithNodeForkedProcess extends Ipc {
@@ -568,15 +567,15 @@ class IpcChildWithNodeForkedProcess extends Ipc {
568
567
  // ignore
569
568
  }
570
569
  }
571
- const wrap$7 = process => {
570
+ const wrap$8 = process => {
572
571
  return new IpcChildWithNodeForkedProcess(process);
573
572
  };
574
573
 
575
574
  const IpcChildWithNodeForkedProcess$1 = {
576
575
  __proto__: null,
577
576
  listen: listen$4,
578
- signal: signal$3,
579
- wrap: wrap$7
577
+ signal: signal$4,
578
+ wrap: wrap$8
580
579
  };
581
580
 
582
581
  const listen$3 = async ({
@@ -587,10 +586,10 @@ const listen$3 = async ({
587
586
  }
588
587
  return messagePort;
589
588
  };
590
- const signal$2 = messagePort => {
589
+ const signal$3 = messagePort => {
591
590
  messagePort.start();
592
591
  };
593
- const wrap$6 = port => {
592
+ const wrap$7 = port => {
594
593
  return {
595
594
  port,
596
595
  on(event, listener) {
@@ -621,8 +620,8 @@ const wrap$6 = port => {
621
620
  const IpcChildWithNodeMessagePort = {
622
621
  __proto__: null,
623
622
  listen: listen$3,
624
- signal: signal$2,
625
- wrap: wrap$6
623
+ signal: signal$3,
624
+ wrap: wrap$7
626
625
  };
627
626
 
628
627
  const listen$2 = async () => {
@@ -634,10 +633,10 @@ const listen$2 = async () => {
634
633
  }
635
634
  return parentPort;
636
635
  };
637
- const signal$1 = parentPort => {
636
+ const signal$2 = parentPort => {
638
637
  parentPort.postMessage(readyMessage);
639
638
  };
640
- const wrap$5 = parentPort => {
639
+ const wrap$6 = parentPort => {
641
640
  return {
642
641
  parentPort,
643
642
  on(event, listener) {
@@ -665,8 +664,8 @@ const wrap$5 = parentPort => {
665
664
  const IpcChildWithNodeWorker = {
666
665
  __proto__: null,
667
666
  listen: listen$2,
668
- signal: signal$1,
669
- wrap: wrap$5
667
+ signal: signal$2,
668
+ wrap: wrap$6
670
669
  };
671
670
 
672
671
  const preloadChannelType = 'port';
@@ -707,14 +706,14 @@ class IpcChildWithRendererProcess2 extends Ipc {
707
706
  this._rawIpc.on('destroyed', callback);
708
707
  }
709
708
  }
710
- const wrap$4 = webContents => {
709
+ const wrap$5 = webContents => {
711
710
  return new IpcChildWithRendererProcess2(webContents);
712
711
  };
713
712
 
714
713
  const IpcChildWithRendererProcess2$1 = {
715
714
  __proto__: null,
716
715
  listen: listen$1,
717
- wrap: wrap$4
716
+ wrap: wrap$5
718
717
  };
719
718
 
720
719
  const Open = 1;
@@ -835,12 +834,12 @@ const listen = async ({
835
834
  }
836
835
  return webSocket;
837
836
  };
838
- const signal = webSocket => {
837
+ const signal$1 = webSocket => {
839
838
  webSocket.resume();
840
839
  };
841
840
 
842
841
  // @ts-ignore
843
- const wrap$3 = webSocket => {
842
+ const wrap$4 = webSocket => {
844
843
  return {
845
844
  webSocket,
846
845
  /**
@@ -890,6 +889,53 @@ const wrap$3 = webSocket => {
890
889
  const IpcChildWithWebSocket = {
891
890
  __proto__: null,
892
891
  listen,
892
+ signal: signal$1,
893
+ wrap: wrap$4
894
+ };
895
+
896
+ const create$3 = ({
897
+ messagePort
898
+ }) => {
899
+ if (!isMessagePortMain(messagePort)) {
900
+ throw new IpcError('port must be of type MessagePortMain');
901
+ }
902
+ return messagePort;
903
+ };
904
+ const signal = messagePort => {
905
+ messagePort.start();
906
+ };
907
+ class IpcParentWithElectronMessagePort extends Ipc {
908
+ constructor(port) {
909
+ super(port);
910
+ }
911
+ getData = getActualDataElectron;
912
+ send(message) {
913
+ this._rawIpc.postMessage(message);
914
+ }
915
+ sendAndTransfer(message) {
916
+ const {
917
+ newValue,
918
+ transfer
919
+ } = fixElectronParameters(message);
920
+ this._rawIpc.postMessage(newValue, transfer);
921
+ }
922
+ dispose() {
923
+ this._rawIpc.close();
924
+ }
925
+ onMessage(callback) {
926
+ this._rawIpc.on('message', callback);
927
+ }
928
+ onClose(callback) {
929
+ this._rawIpc.on('close', callback);
930
+ }
931
+ }
932
+ const wrap$3 = messagePort => {
933
+ return new IpcParentWithElectronMessagePort(messagePort);
934
+ };
935
+
936
+ const IpcParentWithElectronMessagePort$1 = {
937
+ __proto__: null,
938
+ create: create$3,
893
939
  signal,
894
940
  wrap: wrap$3
895
941
  };
@@ -1319,4 +1365,4 @@ const IpcParentWithNodeWorker = {
1319
1365
  wrap
1320
1366
  };
1321
1367
 
1322
- export { IpcChildWithElectronMessagePort$1 as IpcChildWithElectronMessagePort, IpcChildWithElectronUtilityProcess$1 as IpcChildWithElectronUtilityProcess, IpcChildWithModuleWorker$1 as IpcChildWithModuleWorker, IpcChildWithModuleWorkerAndMessagePort$1 as IpcChildWithModuleWorkerAndMessagePort, IpcChildWithNodeForkedProcess$1 as IpcChildWithNodeForkedProcess, IpcChildWithNodeMessagePort, IpcChildWithNodeWorker, IpcChildWithRendererProcess2$1 as IpcChildWithRendererProcess2, IpcChildWithWebSocket, IpcParentWithElectronUtilityProcess$1 as IpcParentWithElectronUtilityProcess, IpcParentWithNodeForkedProcess$1 as IpcParentWithNodeForkedProcess, IpcParentWithNodeWorker };
1368
+ export { IpcChildWithElectronMessagePort$1 as IpcChildWithElectronMessagePort, IpcChildWithElectronUtilityProcess$1 as IpcChildWithElectronUtilityProcess, IpcChildWithModuleWorker$1 as IpcChildWithModuleWorker, IpcChildWithModuleWorkerAndMessagePort$1 as IpcChildWithModuleWorkerAndMessagePort, IpcChildWithNodeForkedProcess$1 as IpcChildWithNodeForkedProcess, IpcChildWithNodeMessagePort, IpcChildWithNodeWorker, IpcChildWithRendererProcess2$1 as IpcChildWithRendererProcess2, IpcChildWithWebSocket, IpcParentWithElectronMessagePort$1 as IpcParentWithElectronMessagePort, IpcParentWithElectronUtilityProcess$1 as IpcParentWithElectronUtilityProcess, IpcParentWithNodeForkedProcess$1 as IpcParentWithNodeForkedProcess, IpcParentWithNodeWorker };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/ipc",
3
- "version": "10.1.0",
3
+ "version": "10.2.1",
4
4
  "description": "Inter Process Communication for Lvce Editor",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",