@lvce-editor/ipc 10.2.1 → 11.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/browser.js CHANGED
@@ -365,6 +365,11 @@ const listen$3 = async () => {
365
365
  }
366
366
  const type = firstMessage.params[0];
367
367
  if (type === 'message-port') {
368
+ parentIpc.send({
369
+ jsonrpc: '2.0',
370
+ id: firstMessage.id,
371
+ result: null
372
+ });
368
373
  parentIpc.dispose();
369
374
  const port = firstMessage.params[1];
370
375
  return port;
package/dist/electron.js CHANGED
@@ -540,10 +540,10 @@ class ChildProcessError extends Error {
540
540
  // workaround for node not supporting transferrable objects
541
541
  // as parameters. If the transferrable object is a parameter,
542
542
  // it is received as a plain object is received in the receiving process
543
- const fixNodeParameters = value => {
543
+ const fixNodeChildProcessParameters = value => {
544
544
  const transfer = getTransferrables(value);
545
545
  if (transfer.length === 0) {
546
- throw new Error('no transferrables found');
546
+ throw new IpcError('no transferrables found');
547
547
  }
548
548
  const newValue = removeValues(value, transfer);
549
549
  return {
@@ -680,7 +680,7 @@ class IpcParentWithNodeForkedProcess extends Ipc {
680
680
  const {
681
681
  newValue,
682
682
  transfer
683
- } = fixNodeParameters(message);
683
+ } = fixNodeChildProcessParameters(message);
684
684
  this._rawIpc.send(newValue, transfer);
685
685
  }
686
686
  dispose() {
@@ -703,6 +703,17 @@ const IpcParentWithNodeForkedProcess$1 = {
703
703
  wrap: wrap$2
704
704
  };
705
705
 
706
+ const fixNodeWorkerParameters = value => {
707
+ const transfer = getTransferrables(value);
708
+ if (transfer.length === 0) {
709
+ throw new IpcError('no transferrables found');
710
+ }
711
+ return {
712
+ newValue: value,
713
+ transfer: transfer
714
+ };
715
+ };
716
+
706
717
  const addListener = (emitter, type, callback) => {
707
718
  if ('addEventListener' in emitter) {
708
719
  emitter.addEventListener(type, callback);
@@ -790,41 +801,38 @@ const create$1 = async ({
790
801
  }
791
802
  return worker;
792
803
  };
793
-
794
- // @ts-ignore
804
+ class IpcParentWithNodeWorker extends Ipc {
805
+ constructor(worker) {
806
+ super(worker);
807
+ }
808
+ getData(message) {
809
+ return message;
810
+ }
811
+ send(message) {
812
+ this._rawIpc.postMessage(message);
813
+ }
814
+ sendAndTransfer(message) {
815
+ const {
816
+ newValue,
817
+ transfer
818
+ } = fixNodeWorkerParameters(message);
819
+ this._rawIpc.postMessage(newValue, transfer);
820
+ }
821
+ dispose() {
822
+ this._rawIpc.terminate();
823
+ }
824
+ onClose(callback) {
825
+ this._rawIpc.on('exit', callback);
826
+ }
827
+ onMessage(callback) {
828
+ this._rawIpc.on('message', callback);
829
+ }
830
+ }
795
831
  const wrap$1 = worker => {
796
- return {
797
- worker,
798
- // @ts-ignore
799
- on(event, listener) {
800
- const wrappedListener = message => {
801
- const syntheticEvent = {
802
- data: message,
803
- target: this
804
- };
805
- listener(syntheticEvent);
806
- };
807
- this.worker.on(event, wrappedListener);
808
- },
809
- // @ts-ignore
810
- send(message) {
811
- this.worker.postMessage(message);
812
- },
813
- // @ts-ignore
814
- sendAndTransfer(message) {
815
- const {
816
- newValue,
817
- transfer
818
- } = fixNodeParameters(message);
819
- this.worker.postMessage(newValue, transfer);
820
- },
821
- dispose() {
822
- this.worker.terminate();
823
- }
824
- };
832
+ return new IpcParentWithNodeWorker(worker);
825
833
  };
826
834
 
827
- const IpcParentWithNodeWorker = {
835
+ const IpcParentWithNodeWorker$1 = {
828
836
  __proto__: null,
829
837
  create: create$1,
830
838
  wrap: wrap$1
@@ -891,4 +899,4 @@ const IpcParentWithElectronMessagePort$1 = {
891
899
  wrap
892
900
  };
893
901
 
894
- export { IpcParentWithElectronMessagePort$1 as IpcParentWithElectronMessagePort, IpcParentWithElectronUtilityProcess$1 as IpcParentWithElectronUtilityProcess, IpcParentWithNodeForkedProcess$1 as IpcParentWithNodeForkedProcess, IpcParentWithNodeWorker };
902
+ export { IpcParentWithElectronMessagePort$1 as IpcParentWithElectronMessagePort, IpcParentWithElectronUtilityProcess$1 as IpcParentWithElectronUtilityProcess, IpcParentWithNodeForkedProcess$1 as IpcParentWithNodeForkedProcess, IpcParentWithNodeWorker$1 as IpcParentWithNodeWorker };
package/dist/index.js CHANGED
@@ -473,6 +473,11 @@ const listen$5 = async () => {
473
473
  }
474
474
  const type = firstMessage.params[0];
475
475
  if (type === 'message-port') {
476
+ parentIpc.send({
477
+ jsonrpc: '2.0',
478
+ id: firstMessage.id,
479
+ result: null
480
+ });
476
481
  parentIpc.dispose();
477
482
  const port = firstMessage.params[1];
478
483
  return port;
@@ -636,32 +641,35 @@ const listen$2 = async () => {
636
641
  const signal$2 = parentPort => {
637
642
  parentPort.postMessage(readyMessage);
638
643
  };
644
+ class IpcChildWithNodeWorker extends Ipc {
645
+ constructor(port) {
646
+ super(port);
647
+ }
648
+ getData(data) {
649
+ return data;
650
+ }
651
+ onClose(callback) {
652
+ this._rawIpc.on('close', callback);
653
+ }
654
+ send(message) {
655
+ this._rawIpc.postMessage(message);
656
+ }
657
+ onMessage(callback) {
658
+ this._rawIpc.on('message', callback);
659
+ }
660
+ sendAndTransfer(message) {
661
+ const transfer = getTransferrablesNode(message);
662
+ this._rawIpc.postMessage(message, transfer);
663
+ }
664
+ dispose() {
665
+ this._rawIpc.close();
666
+ }
667
+ }
639
668
  const wrap$6 = parentPort => {
640
- return {
641
- parentPort,
642
- on(event, listener) {
643
- const wrappedListener = (message, handle) => {
644
- const event = {
645
- data: getActualData(message, handle),
646
- target: this
647
- };
648
- listener(event);
649
- };
650
- this.parentPort.on(event, wrappedListener);
651
- },
652
- off(event, listener) {
653
- this.parentPort.off(event, listener);
654
- },
655
- send(message) {
656
- this.parentPort.postMessage(message);
657
- },
658
- dispose() {
659
- this.parentPort.close();
660
- }
661
- };
669
+ return new IpcChildWithNodeWorker(parentPort);
662
670
  };
663
671
 
664
- const IpcChildWithNodeWorker = {
672
+ const IpcChildWithNodeWorker$1 = {
665
673
  __proto__: null,
666
674
  listen: listen$2,
667
675
  signal: signal$2,
@@ -1116,10 +1124,10 @@ class ChildProcessError extends Error {
1116
1124
  // workaround for node not supporting transferrable objects
1117
1125
  // as parameters. If the transferrable object is a parameter,
1118
1126
  // it is received as a plain object is received in the receiving process
1119
- const fixNodeParameters = value => {
1127
+ const fixNodeChildProcessParameters = value => {
1120
1128
  const transfer = getTransferrables(value);
1121
1129
  if (transfer.length === 0) {
1122
- throw new Error('no transferrables found');
1130
+ throw new IpcError('no transferrables found');
1123
1131
  }
1124
1132
  const newValue = removeValues(value, transfer);
1125
1133
  return {
@@ -1256,7 +1264,7 @@ class IpcParentWithNodeForkedProcess extends Ipc {
1256
1264
  const {
1257
1265
  newValue,
1258
1266
  transfer
1259
- } = fixNodeParameters(message);
1267
+ } = fixNodeChildProcessParameters(message);
1260
1268
  this._rawIpc.send(newValue, transfer);
1261
1269
  }
1262
1270
  dispose() {
@@ -1279,6 +1287,17 @@ const IpcParentWithNodeForkedProcess$1 = {
1279
1287
  wrap: wrap$1
1280
1288
  };
1281
1289
 
1290
+ const fixNodeWorkerParameters = value => {
1291
+ const transfer = getTransferrables(value);
1292
+ if (transfer.length === 0) {
1293
+ throw new IpcError('no transferrables found');
1294
+ }
1295
+ return {
1296
+ newValue: value,
1297
+ transfer: transfer
1298
+ };
1299
+ };
1300
+
1282
1301
  const getFirstNodeWorkerEvent = worker => {
1283
1302
  return getFirstEvent(worker, {
1284
1303
  message: Message,
@@ -1325,44 +1344,41 @@ const create = async ({
1325
1344
  }
1326
1345
  return worker;
1327
1346
  };
1328
-
1329
- // @ts-ignore
1347
+ class IpcParentWithNodeWorker extends Ipc {
1348
+ constructor(worker) {
1349
+ super(worker);
1350
+ }
1351
+ getData(message) {
1352
+ return message;
1353
+ }
1354
+ send(message) {
1355
+ this._rawIpc.postMessage(message);
1356
+ }
1357
+ sendAndTransfer(message) {
1358
+ const {
1359
+ newValue,
1360
+ transfer
1361
+ } = fixNodeWorkerParameters(message);
1362
+ this._rawIpc.postMessage(newValue, transfer);
1363
+ }
1364
+ dispose() {
1365
+ this._rawIpc.terminate();
1366
+ }
1367
+ onClose(callback) {
1368
+ this._rawIpc.on('exit', callback);
1369
+ }
1370
+ onMessage(callback) {
1371
+ this._rawIpc.on('message', callback);
1372
+ }
1373
+ }
1330
1374
  const wrap = worker => {
1331
- return {
1332
- worker,
1333
- // @ts-ignore
1334
- on(event, listener) {
1335
- const wrappedListener = message => {
1336
- const syntheticEvent = {
1337
- data: message,
1338
- target: this
1339
- };
1340
- listener(syntheticEvent);
1341
- };
1342
- this.worker.on(event, wrappedListener);
1343
- },
1344
- // @ts-ignore
1345
- send(message) {
1346
- this.worker.postMessage(message);
1347
- },
1348
- // @ts-ignore
1349
- sendAndTransfer(message) {
1350
- const {
1351
- newValue,
1352
- transfer
1353
- } = fixNodeParameters(message);
1354
- this.worker.postMessage(newValue, transfer);
1355
- },
1356
- dispose() {
1357
- this.worker.terminate();
1358
- }
1359
- };
1375
+ return new IpcParentWithNodeWorker(worker);
1360
1376
  };
1361
1377
 
1362
- const IpcParentWithNodeWorker = {
1378
+ const IpcParentWithNodeWorker$1 = {
1363
1379
  __proto__: null,
1364
1380
  create,
1365
1381
  wrap
1366
1382
  };
1367
1383
 
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 };
1384
+ export { IpcChildWithElectronMessagePort$1 as IpcChildWithElectronMessagePort, IpcChildWithElectronUtilityProcess$1 as IpcChildWithElectronUtilityProcess, IpcChildWithModuleWorker$1 as IpcChildWithModuleWorker, IpcChildWithModuleWorkerAndMessagePort$1 as IpcChildWithModuleWorkerAndMessagePort, IpcChildWithNodeForkedProcess$1 as IpcChildWithNodeForkedProcess, IpcChildWithNodeMessagePort, IpcChildWithNodeWorker$1 as IpcChildWithNodeWorker, IpcChildWithRendererProcess2$1 as IpcChildWithRendererProcess2, IpcChildWithWebSocket, IpcParentWithElectronMessagePort$1 as IpcParentWithElectronMessagePort, IpcParentWithElectronUtilityProcess$1 as IpcParentWithElectronUtilityProcess, IpcParentWithNodeForkedProcess$1 as IpcParentWithNodeForkedProcess, IpcParentWithNodeWorker$1 as IpcParentWithNodeWorker };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/ipc",
3
- "version": "10.2.1",
3
+ "version": "11.0.1",
4
4
  "description": "Inter Process Communication for Lvce Editor",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",