@lvce-editor/ipc 3.3.0 → 3.4.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/dist/browser.js +59 -853
- package/dist/index.d.ts +0 -2
- package/dist/index.js +61 -22
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -1,3 +1,57 @@
|
|
|
1
|
+
const getData = event => {
|
|
2
|
+
return event.data;
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
const listen$1 = () => {
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
if (typeof WorkerGlobalScope === 'undefined') {
|
|
8
|
+
throw new TypeError('module is not in web worker scope');
|
|
9
|
+
}
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
globalThis.postMessage('ready');
|
|
12
|
+
return globalThis;
|
|
13
|
+
};
|
|
14
|
+
const signal = global => {
|
|
15
|
+
global.postMessage('ready');
|
|
16
|
+
};
|
|
17
|
+
const wrap$1 = global => {
|
|
18
|
+
return {
|
|
19
|
+
global,
|
|
20
|
+
/**
|
|
21
|
+
* @type {any}
|
|
22
|
+
*/
|
|
23
|
+
listener: undefined,
|
|
24
|
+
send(message) {
|
|
25
|
+
this.global.postMessage(message);
|
|
26
|
+
},
|
|
27
|
+
sendAndTransfer(message, transferables) {
|
|
28
|
+
this.global.postMessage(message, transferables);
|
|
29
|
+
},
|
|
30
|
+
get onmessage() {
|
|
31
|
+
return this.listener;
|
|
32
|
+
},
|
|
33
|
+
set onmessage(listener) {
|
|
34
|
+
const wrappedListener = event => {
|
|
35
|
+
const data = getData(event);
|
|
36
|
+
// @ts-expect-error
|
|
37
|
+
listener({
|
|
38
|
+
data,
|
|
39
|
+
target: this
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
this.listener = listener;
|
|
43
|
+
this.global.onmessage = wrappedListener;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const IpcChildWithModuleWorker = {
|
|
49
|
+
__proto__: null,
|
|
50
|
+
listen: listen$1,
|
|
51
|
+
signal,
|
|
52
|
+
wrap: wrap$1
|
|
53
|
+
};
|
|
54
|
+
|
|
1
55
|
const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
|
2
56
|
const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
|
|
3
57
|
const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
|
|
@@ -199,206 +253,6 @@ class IpcError extends VError {
|
|
|
199
253
|
}
|
|
200
254
|
}
|
|
201
255
|
|
|
202
|
-
const isMessagePortMain = value => {
|
|
203
|
-
return value && value.constructor && value.constructor.name === 'MessagePortMain';
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
// @ts-ignore
|
|
207
|
-
const listen$5 = ({
|
|
208
|
-
messagePort
|
|
209
|
-
}) => {
|
|
210
|
-
if (!isMessagePortMain(messagePort)) {
|
|
211
|
-
throw new IpcError('port must be of type MessagePortMain');
|
|
212
|
-
}
|
|
213
|
-
return messagePort;
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
// @ts-ignore
|
|
217
|
-
const getActualData$1 = event => {
|
|
218
|
-
const {
|
|
219
|
-
data,
|
|
220
|
-
ports
|
|
221
|
-
} = event;
|
|
222
|
-
if (ports.length === 0) {
|
|
223
|
-
return data;
|
|
224
|
-
}
|
|
225
|
-
return {
|
|
226
|
-
...data,
|
|
227
|
-
params: [...ports, ...data.params]
|
|
228
|
-
};
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
// @ts-ignore
|
|
232
|
-
const wrap$8 = messagePort => {
|
|
233
|
-
return {
|
|
234
|
-
messagePort,
|
|
235
|
-
// @ts-ignore
|
|
236
|
-
on(event, listener) {
|
|
237
|
-
if (event === 'message') {
|
|
238
|
-
// @ts-ignore
|
|
239
|
-
const wrappedListener = event => {
|
|
240
|
-
const actualData = getActualData$1(event);
|
|
241
|
-
listener(actualData);
|
|
242
|
-
};
|
|
243
|
-
this.messagePort.on(event, wrappedListener);
|
|
244
|
-
} else if (event === 'close') {
|
|
245
|
-
this.messagePort.on('close', listener);
|
|
246
|
-
} else {
|
|
247
|
-
throw new Error('unsupported event type');
|
|
248
|
-
}
|
|
249
|
-
},
|
|
250
|
-
// @ts-ignore
|
|
251
|
-
off(event, listener) {
|
|
252
|
-
this.messagePort.off(event, listener);
|
|
253
|
-
},
|
|
254
|
-
// @ts-ignore
|
|
255
|
-
send(message) {
|
|
256
|
-
this.messagePort.postMessage(message);
|
|
257
|
-
},
|
|
258
|
-
dispose() {
|
|
259
|
-
this.messagePort.close();
|
|
260
|
-
},
|
|
261
|
-
start() {
|
|
262
|
-
this.messagePort.start();
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
const IpcChildWithElectronMessagePort = {
|
|
268
|
-
__proto__: null,
|
|
269
|
-
listen: listen$5,
|
|
270
|
-
wrap: wrap$8
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
// @ts-ignore
|
|
274
|
-
const getUtilityProcessPortData = event => {
|
|
275
|
-
const {
|
|
276
|
-
data,
|
|
277
|
-
ports
|
|
278
|
-
} = event;
|
|
279
|
-
if (ports.length === 0) {
|
|
280
|
-
return data;
|
|
281
|
-
}
|
|
282
|
-
return {
|
|
283
|
-
...data,
|
|
284
|
-
params: [...ports, ...data.params]
|
|
285
|
-
};
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
const listen$4 = () => {
|
|
289
|
-
// @ts-ignore
|
|
290
|
-
const {
|
|
291
|
-
parentPort
|
|
292
|
-
} = process;
|
|
293
|
-
if (!parentPort) {
|
|
294
|
-
throw new Error('parent port must be defined');
|
|
295
|
-
}
|
|
296
|
-
return parentPort;
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
// @ts-ignore
|
|
300
|
-
const signal$2 = parentPort => {
|
|
301
|
-
parentPort.postMessage('ready');
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
// @ts-ignore
|
|
305
|
-
const wrap$7 = parentPort => {
|
|
306
|
-
return {
|
|
307
|
-
parentPort,
|
|
308
|
-
// @ts-ignore
|
|
309
|
-
on(event, listener) {
|
|
310
|
-
if (event === 'message') {
|
|
311
|
-
// @ts-ignore
|
|
312
|
-
const wrappedListener = event => {
|
|
313
|
-
const actualData = getUtilityProcessPortData(event);
|
|
314
|
-
listener(actualData);
|
|
315
|
-
};
|
|
316
|
-
this.parentPort.on(event, wrappedListener);
|
|
317
|
-
} else if (event === 'close') {
|
|
318
|
-
this.parentPort.on('close', listener);
|
|
319
|
-
} else {
|
|
320
|
-
throw new Error('unsupported event type');
|
|
321
|
-
}
|
|
322
|
-
},
|
|
323
|
-
// @ts-ignore
|
|
324
|
-
off(event, listener) {
|
|
325
|
-
this.parentPort.off(event, listener);
|
|
326
|
-
},
|
|
327
|
-
// @ts-ignore
|
|
328
|
-
send(message) {
|
|
329
|
-
this.parentPort.postMessage(message);
|
|
330
|
-
},
|
|
331
|
-
// @ts-ignore
|
|
332
|
-
sendAndTransfer(message, transfer) {
|
|
333
|
-
this.parentPort.postMessage(message, transfer);
|
|
334
|
-
},
|
|
335
|
-
dispose() {
|
|
336
|
-
this.parentPort.close();
|
|
337
|
-
}
|
|
338
|
-
};
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
const IpcChildWithElectronUtilityProcess = {
|
|
342
|
-
__proto__: null,
|
|
343
|
-
listen: listen$4,
|
|
344
|
-
signal: signal$2,
|
|
345
|
-
wrap: wrap$7
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
const getData = event => {
|
|
349
|
-
return event.data;
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
const listen$3 = () => {
|
|
353
|
-
// @ts-ignore
|
|
354
|
-
if (typeof WorkerGlobalScope === 'undefined') {
|
|
355
|
-
throw new TypeError('module is not in web worker scope');
|
|
356
|
-
}
|
|
357
|
-
// @ts-ignore
|
|
358
|
-
globalThis.postMessage('ready');
|
|
359
|
-
return globalThis;
|
|
360
|
-
};
|
|
361
|
-
const signal$1 = global => {
|
|
362
|
-
global.postMessage('ready');
|
|
363
|
-
};
|
|
364
|
-
const wrap$6 = global => {
|
|
365
|
-
return {
|
|
366
|
-
global,
|
|
367
|
-
/**
|
|
368
|
-
* @type {any}
|
|
369
|
-
*/
|
|
370
|
-
listener: undefined,
|
|
371
|
-
send(message) {
|
|
372
|
-
this.global.postMessage(message);
|
|
373
|
-
},
|
|
374
|
-
sendAndTransfer(message, transferables) {
|
|
375
|
-
this.global.postMessage(message, transferables);
|
|
376
|
-
},
|
|
377
|
-
get onmessage() {
|
|
378
|
-
return this.listener;
|
|
379
|
-
},
|
|
380
|
-
set onmessage(listener) {
|
|
381
|
-
const wrappedListener = event => {
|
|
382
|
-
const data = getData(event);
|
|
383
|
-
// @ts-expect-error
|
|
384
|
-
listener({
|
|
385
|
-
data,
|
|
386
|
-
target: this
|
|
387
|
-
});
|
|
388
|
-
};
|
|
389
|
-
this.listener = listener;
|
|
390
|
-
this.global.onmessage = wrappedListener;
|
|
391
|
-
}
|
|
392
|
-
};
|
|
393
|
-
};
|
|
394
|
-
|
|
395
|
-
const IpcChildWithModuleWorker = {
|
|
396
|
-
__proto__: null,
|
|
397
|
-
listen: listen$3,
|
|
398
|
-
signal: signal$1,
|
|
399
|
-
wrap: wrap$6
|
|
400
|
-
};
|
|
401
|
-
|
|
402
256
|
const withResolvers = () => {
|
|
403
257
|
let _resolve;
|
|
404
258
|
const promise = new Promise(resolve => {
|
|
@@ -428,9 +282,9 @@ const waitForFirstMessage = async port => {
|
|
|
428
282
|
return event.data;
|
|
429
283
|
};
|
|
430
284
|
|
|
431
|
-
const listen
|
|
432
|
-
const parentIpcRaw = listen$
|
|
433
|
-
const parentIpc = wrap$
|
|
285
|
+
const listen = async () => {
|
|
286
|
+
const parentIpcRaw = listen$1();
|
|
287
|
+
const parentIpc = wrap$1(parentIpcRaw);
|
|
434
288
|
const firstMessage = await waitForFirstMessage(parentIpc);
|
|
435
289
|
if (firstMessage.method !== 'initialize') {
|
|
436
290
|
throw new IpcError('unexpected first message');
|
|
@@ -442,7 +296,7 @@ const listen$2 = async () => {
|
|
|
442
296
|
}
|
|
443
297
|
return globalThis;
|
|
444
298
|
};
|
|
445
|
-
const wrap
|
|
299
|
+
const wrap = port => {
|
|
446
300
|
return {
|
|
447
301
|
port,
|
|
448
302
|
/**
|
|
@@ -478,657 +332,9 @@ const wrap$5 = port => {
|
|
|
478
332
|
};
|
|
479
333
|
|
|
480
334
|
const IpcChildWithModuleWorkerAndMessagePort = {
|
|
481
|
-
__proto__: null,
|
|
482
|
-
listen: listen$2,
|
|
483
|
-
wrap: wrap$5
|
|
484
|
-
};
|
|
485
|
-
|
|
486
|
-
const listen$1 = async () => {
|
|
487
|
-
if (!process.send) {
|
|
488
|
-
throw new Error('process.send must be defined');
|
|
489
|
-
}
|
|
490
|
-
return process;
|
|
491
|
-
};
|
|
492
|
-
|
|
493
|
-
// @ts-ignore
|
|
494
|
-
const signal = process => {
|
|
495
|
-
process.send('ready');
|
|
496
|
-
};
|
|
497
|
-
|
|
498
|
-
// @ts-ignore
|
|
499
|
-
const getActualData = (message, handle) => {
|
|
500
|
-
if (handle) {
|
|
501
|
-
return {
|
|
502
|
-
...message,
|
|
503
|
-
params: [...message.params, handle]
|
|
504
|
-
};
|
|
505
|
-
}
|
|
506
|
-
return message;
|
|
507
|
-
};
|
|
508
|
-
|
|
509
|
-
// @ts-ignore
|
|
510
|
-
const wrap$4 = process => {
|
|
511
|
-
return {
|
|
512
|
-
process,
|
|
513
|
-
// @ts-ignore
|
|
514
|
-
on(event, listener) {
|
|
515
|
-
if (event === 'message') {
|
|
516
|
-
// @ts-ignore
|
|
517
|
-
const wrappedListener = (event, handle) => {
|
|
518
|
-
const actualData = getActualData(event, handle);
|
|
519
|
-
listener(actualData);
|
|
520
|
-
};
|
|
521
|
-
this.process.on(event, wrappedListener);
|
|
522
|
-
} else if (event === 'close') {
|
|
523
|
-
this.process.on('close', listener);
|
|
524
|
-
} else {
|
|
525
|
-
throw new Error('unsupported event type');
|
|
526
|
-
}
|
|
527
|
-
},
|
|
528
|
-
// @ts-ignore
|
|
529
|
-
off(event, listener) {
|
|
530
|
-
this.process.off(event, listener);
|
|
531
|
-
},
|
|
532
|
-
// @ts-ignore
|
|
533
|
-
send(message) {
|
|
534
|
-
this.process.send(message);
|
|
535
|
-
},
|
|
536
|
-
dispose() {}
|
|
537
|
-
};
|
|
538
|
-
};
|
|
539
|
-
|
|
540
|
-
const IpcChildWithNodeForkedProcess = {
|
|
541
|
-
__proto__: null,
|
|
542
|
-
listen: listen$1,
|
|
543
|
-
signal,
|
|
544
|
-
wrap: wrap$4
|
|
545
|
-
};
|
|
546
|
-
|
|
547
|
-
const Open = 1;
|
|
548
|
-
const Close = 2;
|
|
549
|
-
|
|
550
|
-
// @ts-ignore
|
|
551
|
-
const getFirstEvent = (eventEmitter, eventMap) => {
|
|
552
|
-
const {
|
|
553
|
-
resolve,
|
|
554
|
-
promise
|
|
555
|
-
} = withResolvers();
|
|
556
|
-
const listenerMap = Object.create(null);
|
|
557
|
-
// @ts-ignore
|
|
558
|
-
const cleanup = value => {
|
|
559
|
-
for (const event of Object.keys(eventMap)) {
|
|
560
|
-
eventEmitter.off(event, listenerMap[event]);
|
|
561
|
-
}
|
|
562
|
-
// @ts-ignore
|
|
563
|
-
resolve(value);
|
|
564
|
-
};
|
|
565
|
-
for (const [event, type] of Object.entries(eventMap)) {
|
|
566
|
-
// @ts-ignore
|
|
567
|
-
const listener = event => {
|
|
568
|
-
cleanup({
|
|
569
|
-
type,
|
|
570
|
-
event
|
|
571
|
-
});
|
|
572
|
-
};
|
|
573
|
-
eventEmitter.on(event, listener);
|
|
574
|
-
listenerMap[event] = listener;
|
|
575
|
-
}
|
|
576
|
-
return promise;
|
|
577
|
-
};
|
|
578
|
-
|
|
579
|
-
// @ts-ignore
|
|
580
|
-
const getFirstWebSocketEvent = async webSocket => {
|
|
581
|
-
// @ts-ignore
|
|
582
|
-
const {
|
|
583
|
-
WebSocket
|
|
584
|
-
} = await import('ws');
|
|
585
|
-
switch (webSocket.readyState) {
|
|
586
|
-
case WebSocket.OPEN:
|
|
587
|
-
return {
|
|
588
|
-
type: Open,
|
|
589
|
-
event: undefined
|
|
590
|
-
};
|
|
591
|
-
case WebSocket.CLOSED:
|
|
592
|
-
return {
|
|
593
|
-
type: Close,
|
|
594
|
-
event: undefined
|
|
595
|
-
};
|
|
596
|
-
}
|
|
597
|
-
// @ts-ignore
|
|
598
|
-
const {
|
|
599
|
-
type,
|
|
600
|
-
event
|
|
601
|
-
} = await getFirstEvent(webSocket, {
|
|
602
|
-
open: Open,
|
|
603
|
-
close: Close
|
|
604
|
-
});
|
|
605
|
-
return {
|
|
606
|
-
type,
|
|
607
|
-
event
|
|
608
|
-
};
|
|
609
|
-
};
|
|
610
|
-
|
|
611
|
-
// @ts-ignore
|
|
612
|
-
const isWebSocketOpen = async webSocket => {
|
|
613
|
-
// @ts-ignore
|
|
614
|
-
const {
|
|
615
|
-
WebSocket
|
|
616
|
-
} = await import('ws');
|
|
617
|
-
return webSocket.readyState === WebSocket.OPEN;
|
|
618
|
-
};
|
|
619
|
-
|
|
620
|
-
// @ts-ignore
|
|
621
|
-
const serialize = message => {
|
|
622
|
-
return JSON.stringify(message);
|
|
623
|
-
};
|
|
624
|
-
|
|
625
|
-
// @ts-ignore
|
|
626
|
-
const deserialize = message => {
|
|
627
|
-
return JSON.parse(message.toString());
|
|
628
|
-
};
|
|
629
|
-
|
|
630
|
-
// @ts-ignore
|
|
631
|
-
const handleUpgrade = async (...args) => {
|
|
632
|
-
const module = await import('@lvce-editor/web-socket-server');
|
|
633
|
-
// @ts-ignore
|
|
634
|
-
return module.handleUpgrade(...args);
|
|
635
|
-
};
|
|
636
|
-
|
|
637
|
-
// @ts-ignore
|
|
638
|
-
const listen = async ({
|
|
639
|
-
request,
|
|
640
|
-
handle
|
|
641
|
-
}) => {
|
|
642
|
-
if (!request) {
|
|
643
|
-
throw new IpcError('request must be defined');
|
|
644
|
-
}
|
|
645
|
-
if (!handle) {
|
|
646
|
-
throw new IpcError('handle must be defined');
|
|
647
|
-
}
|
|
648
|
-
const webSocket = await handleUpgrade(request, handle);
|
|
649
|
-
webSocket.pause();
|
|
650
|
-
if (!(await isWebSocketOpen(webSocket))) {
|
|
651
|
-
await getFirstWebSocketEvent(webSocket);
|
|
652
|
-
}
|
|
653
|
-
return webSocket;
|
|
654
|
-
};
|
|
655
|
-
|
|
656
|
-
// @ts-ignore
|
|
657
|
-
const wrap$3 = webSocket => {
|
|
658
|
-
return {
|
|
659
|
-
webSocket,
|
|
660
|
-
/**
|
|
661
|
-
* @type {any}
|
|
662
|
-
*/
|
|
663
|
-
wrappedListener: undefined,
|
|
664
|
-
// @ts-ignore
|
|
665
|
-
on(event, listener) {
|
|
666
|
-
switch (event) {
|
|
667
|
-
case 'message':
|
|
668
|
-
// @ts-ignore
|
|
669
|
-
const wrappedListener = message => {
|
|
670
|
-
const data = deserialize(message);
|
|
671
|
-
listener(data);
|
|
672
|
-
};
|
|
673
|
-
webSocket.on('message', wrappedListener);
|
|
674
|
-
break;
|
|
675
|
-
case 'close':
|
|
676
|
-
webSocket.on('close', listener);
|
|
677
|
-
break;
|
|
678
|
-
default:
|
|
679
|
-
throw new Error('unknown event listener type');
|
|
680
|
-
}
|
|
681
|
-
},
|
|
682
|
-
// @ts-ignore
|
|
683
|
-
off(event, listener) {
|
|
684
|
-
this.webSocket.off(event, listener);
|
|
685
|
-
},
|
|
686
|
-
// @ts-ignore
|
|
687
|
-
send(message) {
|
|
688
|
-
const stringifiedMessage = serialize(message);
|
|
689
|
-
this.webSocket.send(stringifiedMessage);
|
|
690
|
-
},
|
|
691
|
-
dispose() {
|
|
692
|
-
this.webSocket.close();
|
|
693
|
-
},
|
|
694
|
-
start() {
|
|
695
|
-
this.webSocket.resume();
|
|
696
|
-
}
|
|
697
|
-
};
|
|
698
|
-
};
|
|
699
|
-
|
|
700
|
-
const IpcChildWithWebSocket = {
|
|
701
335
|
__proto__: null,
|
|
702
336
|
listen,
|
|
703
|
-
wrap: wrap$3
|
|
704
|
-
};
|
|
705
|
-
|
|
706
|
-
class AssertionError extends Error {
|
|
707
|
-
constructor(message) {
|
|
708
|
-
super(message);
|
|
709
|
-
this.name = 'AssertionError';
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
const getType = value => {
|
|
713
|
-
switch (typeof value) {
|
|
714
|
-
case 'number':
|
|
715
|
-
return 'number';
|
|
716
|
-
case 'function':
|
|
717
|
-
return 'function';
|
|
718
|
-
case 'string':
|
|
719
|
-
return 'string';
|
|
720
|
-
case 'object':
|
|
721
|
-
if (value === null) {
|
|
722
|
-
return 'null';
|
|
723
|
-
}
|
|
724
|
-
if (Array.isArray(value)) {
|
|
725
|
-
return 'array';
|
|
726
|
-
}
|
|
727
|
-
return 'object';
|
|
728
|
-
case 'boolean':
|
|
729
|
-
return 'boolean';
|
|
730
|
-
default:
|
|
731
|
-
return 'unknown';
|
|
732
|
-
}
|
|
733
|
-
};
|
|
734
|
-
const array = value => {
|
|
735
|
-
const type = getType(value);
|
|
736
|
-
if (type !== 'array') {
|
|
737
|
-
throw new AssertionError('expected value to be of type array');
|
|
738
|
-
}
|
|
739
|
-
};
|
|
740
|
-
const string = value => {
|
|
741
|
-
const type = getType(value);
|
|
742
|
-
if (type !== 'string') {
|
|
743
|
-
throw new AssertionError('expected value to be of type string');
|
|
744
|
-
}
|
|
745
|
-
};
|
|
746
|
-
|
|
747
|
-
const Exit = 1;
|
|
748
|
-
const Error$1 = 2;
|
|
749
|
-
const Message = 3;
|
|
750
|
-
|
|
751
|
-
/**
|
|
752
|
-
*
|
|
753
|
-
* @param {any} utilityProcess
|
|
754
|
-
* @returns
|
|
755
|
-
*/
|
|
756
|
-
// @ts-ignore
|
|
757
|
-
const getFirstUtilityProcessEvent = async utilityProcess => {
|
|
758
|
-
const {
|
|
759
|
-
resolve,
|
|
760
|
-
promise
|
|
761
|
-
} = withResolvers();
|
|
762
|
-
let stdout = '';
|
|
763
|
-
let stderr = '';
|
|
764
|
-
// @ts-ignore
|
|
765
|
-
const cleanup = value => {
|
|
766
|
-
// @ts-ignore
|
|
767
|
-
utilityProcess.stderr.off('data', handleStdErrData);
|
|
768
|
-
// @ts-ignore
|
|
769
|
-
utilityProcess.stdout.off('data', handleStdoutData);
|
|
770
|
-
utilityProcess.off('message', handleMessage);
|
|
771
|
-
utilityProcess.off('exit', handleExit);
|
|
772
|
-
// @ts-ignore
|
|
773
|
-
resolve(value);
|
|
774
|
-
};
|
|
775
|
-
// @ts-ignore
|
|
776
|
-
const handleStdErrData = data => {
|
|
777
|
-
stderr += data;
|
|
778
|
-
};
|
|
779
|
-
// @ts-ignore
|
|
780
|
-
const handleStdoutData = data => {
|
|
781
|
-
stdout += data;
|
|
782
|
-
};
|
|
783
|
-
// @ts-ignore
|
|
784
|
-
const handleMessage = event => {
|
|
785
|
-
cleanup({
|
|
786
|
-
type: Message,
|
|
787
|
-
event,
|
|
788
|
-
stdout,
|
|
789
|
-
stderr
|
|
790
|
-
});
|
|
791
|
-
};
|
|
792
|
-
// @ts-ignore
|
|
793
|
-
const handleExit = event => {
|
|
794
|
-
cleanup({
|
|
795
|
-
type: Exit,
|
|
796
|
-
event,
|
|
797
|
-
stdout,
|
|
798
|
-
stderr
|
|
799
|
-
});
|
|
800
|
-
};
|
|
801
|
-
// @ts-ignore
|
|
802
|
-
utilityProcess.stderr.on('data', handleStdErrData);
|
|
803
|
-
// @ts-ignore
|
|
804
|
-
utilityProcess.stdout.on('data', handleStdoutData);
|
|
805
|
-
utilityProcess.on('message', handleMessage);
|
|
806
|
-
utilityProcess.on('exit', handleExit);
|
|
807
|
-
// @ts-ignore
|
|
808
|
-
const {
|
|
809
|
-
type,
|
|
810
|
-
event
|
|
811
|
-
} = await promise;
|
|
812
|
-
return {
|
|
813
|
-
type,
|
|
814
|
-
event,
|
|
815
|
-
stdout,
|
|
816
|
-
stderr
|
|
817
|
-
};
|
|
818
|
-
};
|
|
819
|
-
|
|
820
|
-
// @ts-ignore
|
|
821
|
-
const create$2 = async ({
|
|
822
|
-
path,
|
|
823
|
-
argv = [],
|
|
824
|
-
execArgv = [],
|
|
825
|
-
name
|
|
826
|
-
}) => {
|
|
827
|
-
string(path);
|
|
828
|
-
const actualArgv = ['--ipc-type=electron-utility-process', ...argv];
|
|
829
|
-
// @ts-ignore
|
|
830
|
-
const {
|
|
831
|
-
utilityProcess
|
|
832
|
-
} = await import('electron');
|
|
833
|
-
const childProcess = utilityProcess.fork(path, actualArgv, {
|
|
834
|
-
execArgv,
|
|
835
|
-
stdio: 'pipe',
|
|
836
|
-
serviceName: name
|
|
837
|
-
});
|
|
838
|
-
// @ts-ignore
|
|
839
|
-
childProcess.stdout.pipe(process.stdout);
|
|
840
|
-
const {
|
|
841
|
-
type,
|
|
842
|
-
event,
|
|
843
|
-
stdout,
|
|
844
|
-
stderr
|
|
845
|
-
} = await getFirstUtilityProcessEvent(childProcess);
|
|
846
|
-
if (type === Exit) {
|
|
847
|
-
throw new IpcError(`Utility process exited before ipc connection was established`, stdout, stderr);
|
|
848
|
-
}
|
|
849
|
-
// @ts-ignore
|
|
850
|
-
childProcess.stderr.pipe(process.stderr);
|
|
851
|
-
return childProcess;
|
|
852
|
-
};
|
|
853
|
-
|
|
854
|
-
// @ts-ignore
|
|
855
|
-
const wrap$2 = process => {
|
|
856
|
-
return {
|
|
857
|
-
process,
|
|
858
|
-
// @ts-ignore
|
|
859
|
-
on(event, listener) {
|
|
860
|
-
this.process.on(event, listener);
|
|
861
|
-
},
|
|
862
|
-
// @ts-ignore
|
|
863
|
-
send(message) {
|
|
864
|
-
this.process.postMessage(message);
|
|
865
|
-
},
|
|
866
|
-
// @ts-ignore
|
|
867
|
-
sendAndTransfer(message, transfer) {
|
|
868
|
-
array(transfer);
|
|
869
|
-
this.process.postMessage(message, transfer);
|
|
870
|
-
},
|
|
871
|
-
dispose() {
|
|
872
|
-
this.process.kill();
|
|
873
|
-
}
|
|
874
|
-
};
|
|
875
|
-
};
|
|
876
|
-
|
|
877
|
-
const IpcParentWithElectronUtilityProcess = {
|
|
878
|
-
__proto__: null,
|
|
879
|
-
create: create$2,
|
|
880
|
-
wrap: wrap$2
|
|
881
|
-
};
|
|
882
|
-
|
|
883
|
-
class ChildProcessError extends Error {
|
|
884
|
-
// @ts-ignore
|
|
885
|
-
constructor(stderr) {
|
|
886
|
-
// @ts-ignore
|
|
887
|
-
const {
|
|
888
|
-
message,
|
|
889
|
-
code,
|
|
890
|
-
stack
|
|
891
|
-
} = getHelpfulChildProcessError('', stderr);
|
|
892
|
-
super(message || 'child process error');
|
|
893
|
-
this.name = 'ChildProcessError';
|
|
894
|
-
if (code) {
|
|
895
|
-
// @ts-ignore
|
|
896
|
-
this.code = code;
|
|
897
|
-
}
|
|
898
|
-
if (stack) {
|
|
899
|
-
// @ts-ignore
|
|
900
|
-
const lines = splitLines(this.stack);
|
|
901
|
-
const [firstLine, ...stackLines] = lines;
|
|
902
|
-
const newStackLines = [firstLine, ...stack, ...stackLines];
|
|
903
|
-
const newStack = joinLines(newStackLines);
|
|
904
|
-
this.stack = newStack;
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
|
|
909
|
-
// @ts-ignore
|
|
910
|
-
const getFirstNodeChildProcessEvent = async childProcess => {
|
|
911
|
-
// @ts-ignore
|
|
912
|
-
const {
|
|
913
|
-
type,
|
|
914
|
-
event,
|
|
915
|
-
stdout,
|
|
916
|
-
stderr
|
|
917
|
-
} = await new Promise((resolve, reject) => {
|
|
918
|
-
let stderr = '';
|
|
919
|
-
let stdout = '';
|
|
920
|
-
// @ts-ignore
|
|
921
|
-
const cleanup = value => {
|
|
922
|
-
if (childProcess.stdout && childProcess.stderr) {
|
|
923
|
-
childProcess.stderr.off('data', handleStdErrData);
|
|
924
|
-
childProcess.stdout.off('data', handleStdoutData);
|
|
925
|
-
}
|
|
926
|
-
childProcess.off('message', handleMessage);
|
|
927
|
-
childProcess.off('exit', handleExit);
|
|
928
|
-
childProcess.off('error', handleError);
|
|
929
|
-
resolve(value);
|
|
930
|
-
};
|
|
931
|
-
// @ts-ignore
|
|
932
|
-
const handleStdErrData = data => {
|
|
933
|
-
stderr += data;
|
|
934
|
-
};
|
|
935
|
-
// @ts-ignore
|
|
936
|
-
const handleStdoutData = data => {
|
|
937
|
-
stdout += data;
|
|
938
|
-
};
|
|
939
|
-
// @ts-ignore
|
|
940
|
-
const handleMessage = event => {
|
|
941
|
-
cleanup({
|
|
942
|
-
type: Message,
|
|
943
|
-
event,
|
|
944
|
-
stdout,
|
|
945
|
-
stderr
|
|
946
|
-
});
|
|
947
|
-
};
|
|
948
|
-
// @ts-ignore
|
|
949
|
-
const handleExit = event => {
|
|
950
|
-
cleanup({
|
|
951
|
-
type: Exit,
|
|
952
|
-
event,
|
|
953
|
-
stdout,
|
|
954
|
-
stderr
|
|
955
|
-
});
|
|
956
|
-
};
|
|
957
|
-
// @ts-ignore
|
|
958
|
-
const handleError = event => {
|
|
959
|
-
cleanup({
|
|
960
|
-
type: Error$1,
|
|
961
|
-
event,
|
|
962
|
-
stdout,
|
|
963
|
-
stderr
|
|
964
|
-
});
|
|
965
|
-
};
|
|
966
|
-
if (childProcess.stdout && childProcess.stderr) {
|
|
967
|
-
childProcess.stderr.on('data', handleStdErrData);
|
|
968
|
-
childProcess.stdout.on('data', handleStdoutData);
|
|
969
|
-
}
|
|
970
|
-
childProcess.on('message', handleMessage);
|
|
971
|
-
childProcess.on('exit', handleExit);
|
|
972
|
-
childProcess.on('error', handleError);
|
|
973
|
-
});
|
|
974
|
-
return {
|
|
975
|
-
type,
|
|
976
|
-
event,
|
|
977
|
-
stdout,
|
|
978
|
-
stderr
|
|
979
|
-
};
|
|
980
|
-
};
|
|
981
|
-
|
|
982
|
-
// @ts-ignore
|
|
983
|
-
const create$1 = async ({
|
|
984
|
-
path,
|
|
985
|
-
argv = [],
|
|
986
|
-
env,
|
|
987
|
-
execArgv = [],
|
|
988
|
-
stdio = 'inherit',
|
|
989
|
-
name = 'child process'
|
|
990
|
-
}) => {
|
|
991
|
-
// @ts-ignore
|
|
992
|
-
try {
|
|
993
|
-
string(path);
|
|
994
|
-
const actualArgv = ['--ipc-type=node-forked-process', ...argv];
|
|
995
|
-
const {
|
|
996
|
-
fork
|
|
997
|
-
} = await import('node:child_process');
|
|
998
|
-
const childProcess = fork(path, actualArgv, {
|
|
999
|
-
env,
|
|
1000
|
-
execArgv,
|
|
1001
|
-
stdio: 'pipe'
|
|
1002
|
-
});
|
|
1003
|
-
const {
|
|
1004
|
-
type,
|
|
1005
|
-
event,
|
|
1006
|
-
stdout,
|
|
1007
|
-
stderr
|
|
1008
|
-
} = await getFirstNodeChildProcessEvent(childProcess);
|
|
1009
|
-
if (type === Exit) {
|
|
1010
|
-
throw new ChildProcessError(stderr);
|
|
1011
|
-
}
|
|
1012
|
-
if (type === Error$1) {
|
|
1013
|
-
throw new Error(`child process had an error ${event}`);
|
|
1014
|
-
}
|
|
1015
|
-
if (stdio === 'inherit' && childProcess.stdout && childProcess.stderr) {
|
|
1016
|
-
childProcess.stdout.pipe(process.stdout);
|
|
1017
|
-
childProcess.stderr.pipe(process.stderr);
|
|
1018
|
-
}
|
|
1019
|
-
return childProcess;
|
|
1020
|
-
} catch (error) {
|
|
1021
|
-
throw new VError(error, `Failed to launch ${name}`);
|
|
1022
|
-
}
|
|
1023
|
-
};
|
|
1024
|
-
|
|
1025
|
-
// @ts-ignore
|
|
1026
|
-
const wrap$1 = childProcess => {
|
|
1027
|
-
return {
|
|
1028
|
-
childProcess,
|
|
1029
|
-
// @ts-ignore
|
|
1030
|
-
on(event, listener) {
|
|
1031
|
-
this.childProcess.on(event, listener);
|
|
1032
|
-
},
|
|
1033
|
-
// @ts-ignore
|
|
1034
|
-
off(event, listener) {
|
|
1035
|
-
this.childProcess.off(event, listener);
|
|
1036
|
-
},
|
|
1037
|
-
// @ts-ignore
|
|
1038
|
-
send(message) {
|
|
1039
|
-
this.childProcess.send(message);
|
|
1040
|
-
},
|
|
1041
|
-
// @ts-ignore
|
|
1042
|
-
sendAndTransfer(message, handle) {
|
|
1043
|
-
this.childProcess.send(message, handle);
|
|
1044
|
-
},
|
|
1045
|
-
dispose() {
|
|
1046
|
-
this.childProcess.kill();
|
|
1047
|
-
},
|
|
1048
|
-
pid: childProcess.pid
|
|
1049
|
-
};
|
|
1050
|
-
};
|
|
1051
|
-
|
|
1052
|
-
const IpcParentWithNodeForkedProcess = {
|
|
1053
|
-
__proto__: null,
|
|
1054
|
-
create: create$1,
|
|
1055
|
-
wrap: wrap$1
|
|
1056
|
-
};
|
|
1057
|
-
|
|
1058
|
-
// @ts-ignore
|
|
1059
|
-
const getFirstNodeWorkerEvent = worker => {
|
|
1060
|
-
return getFirstEvent(worker, {
|
|
1061
|
-
exit: Exit,
|
|
1062
|
-
error: Error$1
|
|
1063
|
-
});
|
|
1064
|
-
};
|
|
1065
|
-
|
|
1066
|
-
// @ts-ignore
|
|
1067
|
-
const create = async ({
|
|
1068
|
-
path,
|
|
1069
|
-
argv = [],
|
|
1070
|
-
env = process.env,
|
|
1071
|
-
execArgv = []
|
|
1072
|
-
}) => {
|
|
1073
|
-
// @ts-ignore
|
|
1074
|
-
string(path);
|
|
1075
|
-
const actualArgv = ['--ipc-type=node-worker', ...argv];
|
|
1076
|
-
const actualEnv = {
|
|
1077
|
-
...env,
|
|
1078
|
-
ELECTRON_RUN_AS_NODE: '1'
|
|
1079
|
-
};
|
|
1080
|
-
const {
|
|
1081
|
-
Worker
|
|
1082
|
-
} = await import('node:worker_threads');
|
|
1083
|
-
const worker = new Worker(path, {
|
|
1084
|
-
argv: actualArgv,
|
|
1085
|
-
env: actualEnv,
|
|
1086
|
-
execArgv
|
|
1087
|
-
});
|
|
1088
|
-
// @ts-ignore
|
|
1089
|
-
const {
|
|
1090
|
-
type,
|
|
1091
|
-
event
|
|
1092
|
-
} = await getFirstNodeWorkerEvent(worker);
|
|
1093
|
-
if (type === Exit) {
|
|
1094
|
-
throw new IpcError(`Worker exited before ipc connection was established`);
|
|
1095
|
-
}
|
|
1096
|
-
if (type === Error$1) {
|
|
1097
|
-
throw new IpcError(`Worker threw an error before ipc connection was established: ${event}`);
|
|
1098
|
-
}
|
|
1099
|
-
if (event !== 'ready') {
|
|
1100
|
-
throw new IpcError('unexpected first message from worker');
|
|
1101
|
-
}
|
|
1102
|
-
return worker;
|
|
1103
|
-
};
|
|
1104
|
-
|
|
1105
|
-
// @ts-ignore
|
|
1106
|
-
const wrap = worker => {
|
|
1107
|
-
return {
|
|
1108
|
-
worker,
|
|
1109
|
-
// @ts-ignore
|
|
1110
|
-
on(event, listener) {
|
|
1111
|
-
this.worker.on(event, listener);
|
|
1112
|
-
},
|
|
1113
|
-
// @ts-ignore
|
|
1114
|
-
send(message) {
|
|
1115
|
-
this.worker.postMessage(message);
|
|
1116
|
-
},
|
|
1117
|
-
// @ts-ignore
|
|
1118
|
-
sendAndTransfer(message, transfer) {
|
|
1119
|
-
array(transfer);
|
|
1120
|
-
this.worker.postMessage(message, transfer);
|
|
1121
|
-
},
|
|
1122
|
-
dispose() {
|
|
1123
|
-
this.worker.terminate();
|
|
1124
|
-
}
|
|
1125
|
-
};
|
|
1126
|
-
};
|
|
1127
|
-
|
|
1128
|
-
const IpcParentWithNodeWorker = {
|
|
1129
|
-
__proto__: null,
|
|
1130
|
-
create,
|
|
1131
337
|
wrap
|
|
1132
338
|
};
|
|
1133
339
|
|
|
1134
|
-
export {
|
|
340
|
+
export { IpcChildWithModuleWorker, IpcChildWithModuleWorkerAndMessagePort };
|
package/dist/index.d.ts
CHANGED
|
@@ -7,8 +7,6 @@ export const IpcChildWithElectronMessagePort: IpcChild
|
|
|
7
7
|
export const IpcChildWithElectronUtilityProcess: IpcChild
|
|
8
8
|
export const IpcChildWithNodeForkedProcess: IpcChild
|
|
9
9
|
export const IpcChildWithWebSocket: IpcChild
|
|
10
|
-
export const IpcChildWithModuleWorkerAndMessagePort: IpcChild
|
|
11
|
-
export const IpcChildWithModuleWorker: IpcChild
|
|
12
10
|
|
|
13
11
|
interface IpcParent {
|
|
14
12
|
readonly create: any
|
package/dist/index.js
CHANGED
|
@@ -151,7 +151,7 @@ const isMessagePortMain = value => {
|
|
|
151
151
|
};
|
|
152
152
|
|
|
153
153
|
// @ts-ignore
|
|
154
|
-
const listen$
|
|
154
|
+
const listen$6 = ({
|
|
155
155
|
messagePort
|
|
156
156
|
}) => {
|
|
157
157
|
if (!isMessagePortMain(messagePort)) {
|
|
@@ -176,7 +176,7 @@ const getActualData$1 = event => {
|
|
|
176
176
|
};
|
|
177
177
|
|
|
178
178
|
// @ts-ignore
|
|
179
|
-
const wrap$
|
|
179
|
+
const wrap$9 = messagePort => {
|
|
180
180
|
return {
|
|
181
181
|
messagePort,
|
|
182
182
|
// @ts-ignore
|
|
@@ -213,8 +213,8 @@ const wrap$8 = messagePort => {
|
|
|
213
213
|
|
|
214
214
|
const IpcChildWithElectronMessagePort = {
|
|
215
215
|
__proto__: null,
|
|
216
|
-
listen: listen$
|
|
217
|
-
wrap: wrap$
|
|
216
|
+
listen: listen$6,
|
|
217
|
+
wrap: wrap$9
|
|
218
218
|
};
|
|
219
219
|
|
|
220
220
|
// @ts-ignore
|
|
@@ -232,7 +232,7 @@ const getUtilityProcessPortData = event => {
|
|
|
232
232
|
};
|
|
233
233
|
};
|
|
234
234
|
|
|
235
|
-
const listen$
|
|
235
|
+
const listen$5 = () => {
|
|
236
236
|
// @ts-ignore
|
|
237
237
|
const {
|
|
238
238
|
parentPort
|
|
@@ -249,7 +249,7 @@ const signal$2 = parentPort => {
|
|
|
249
249
|
};
|
|
250
250
|
|
|
251
251
|
// @ts-ignore
|
|
252
|
-
const wrap$
|
|
252
|
+
const wrap$8 = parentPort => {
|
|
253
253
|
return {
|
|
254
254
|
parentPort,
|
|
255
255
|
// @ts-ignore
|
|
@@ -287,16 +287,16 @@ const wrap$7 = parentPort => {
|
|
|
287
287
|
|
|
288
288
|
const IpcChildWithElectronUtilityProcess = {
|
|
289
289
|
__proto__: null,
|
|
290
|
-
listen: listen$
|
|
290
|
+
listen: listen$5,
|
|
291
291
|
signal: signal$2,
|
|
292
|
-
wrap: wrap$
|
|
292
|
+
wrap: wrap$8
|
|
293
293
|
};
|
|
294
294
|
|
|
295
295
|
const getData = event => {
|
|
296
296
|
return event.data;
|
|
297
297
|
};
|
|
298
298
|
|
|
299
|
-
const listen$
|
|
299
|
+
const listen$4 = () => {
|
|
300
300
|
// @ts-ignore
|
|
301
301
|
if (typeof WorkerGlobalScope === 'undefined') {
|
|
302
302
|
throw new TypeError('module is not in web worker scope');
|
|
@@ -308,7 +308,7 @@ const listen$3 = () => {
|
|
|
308
308
|
const signal$1 = global => {
|
|
309
309
|
global.postMessage('ready');
|
|
310
310
|
};
|
|
311
|
-
const wrap$
|
|
311
|
+
const wrap$7 = global => {
|
|
312
312
|
return {
|
|
313
313
|
global,
|
|
314
314
|
/**
|
|
@@ -341,9 +341,9 @@ const wrap$6 = global => {
|
|
|
341
341
|
|
|
342
342
|
const IpcChildWithModuleWorker = {
|
|
343
343
|
__proto__: null,
|
|
344
|
-
listen: listen$
|
|
344
|
+
listen: listen$4,
|
|
345
345
|
signal: signal$1,
|
|
346
|
-
wrap: wrap$
|
|
346
|
+
wrap: wrap$7
|
|
347
347
|
};
|
|
348
348
|
|
|
349
349
|
const withResolvers = () => {
|
|
@@ -375,9 +375,9 @@ const waitForFirstMessage = async port => {
|
|
|
375
375
|
return event.data;
|
|
376
376
|
};
|
|
377
377
|
|
|
378
|
-
const listen$
|
|
379
|
-
const parentIpcRaw = listen$
|
|
380
|
-
const parentIpc = wrap$
|
|
378
|
+
const listen$3 = async () => {
|
|
379
|
+
const parentIpcRaw = listen$4();
|
|
380
|
+
const parentIpc = wrap$7(parentIpcRaw);
|
|
381
381
|
const firstMessage = await waitForFirstMessage(parentIpc);
|
|
382
382
|
if (firstMessage.method !== 'initialize') {
|
|
383
383
|
throw new IpcError('unexpected first message');
|
|
@@ -389,7 +389,7 @@ const listen$2 = async () => {
|
|
|
389
389
|
}
|
|
390
390
|
return globalThis;
|
|
391
391
|
};
|
|
392
|
-
const wrap$
|
|
392
|
+
const wrap$6 = port => {
|
|
393
393
|
return {
|
|
394
394
|
port,
|
|
395
395
|
/**
|
|
@@ -426,11 +426,11 @@ const wrap$5 = port => {
|
|
|
426
426
|
|
|
427
427
|
const IpcChildWithModuleWorkerAndMessagePort = {
|
|
428
428
|
__proto__: null,
|
|
429
|
-
listen: listen$
|
|
430
|
-
wrap: wrap$
|
|
429
|
+
listen: listen$3,
|
|
430
|
+
wrap: wrap$6
|
|
431
431
|
};
|
|
432
432
|
|
|
433
|
-
const listen$
|
|
433
|
+
const listen$2 = async () => {
|
|
434
434
|
if (!process.send) {
|
|
435
435
|
throw new Error('process.send must be defined');
|
|
436
436
|
}
|
|
@@ -454,7 +454,7 @@ const getActualData = (message, handle) => {
|
|
|
454
454
|
};
|
|
455
455
|
|
|
456
456
|
// @ts-ignore
|
|
457
|
-
const wrap$
|
|
457
|
+
const wrap$5 = process => {
|
|
458
458
|
return {
|
|
459
459
|
process,
|
|
460
460
|
// @ts-ignore
|
|
@@ -486,8 +486,47 @@ const wrap$4 = process => {
|
|
|
486
486
|
|
|
487
487
|
const IpcChildWithNodeForkedProcess = {
|
|
488
488
|
__proto__: null,
|
|
489
|
-
listen: listen$
|
|
489
|
+
listen: listen$2,
|
|
490
490
|
signal,
|
|
491
|
+
wrap: wrap$5
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
const isMessagePort = value => {
|
|
495
|
+
return value && value instanceof MessagePort;
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
const listen$1 = async ({
|
|
499
|
+
messagePort
|
|
500
|
+
}) => {
|
|
501
|
+
if (!isMessagePort(messagePort)) {
|
|
502
|
+
throw new IpcError(`port must be of type MessagePort`);
|
|
503
|
+
}
|
|
504
|
+
return messagePort;
|
|
505
|
+
};
|
|
506
|
+
const wrap$4 = port => {
|
|
507
|
+
return {
|
|
508
|
+
port,
|
|
509
|
+
on(event, listener) {
|
|
510
|
+
this.port.on(event, listener);
|
|
511
|
+
},
|
|
512
|
+
off(event, listener) {
|
|
513
|
+
this.port.off(event, listener);
|
|
514
|
+
},
|
|
515
|
+
send(message) {
|
|
516
|
+
this.port.postMessage(message);
|
|
517
|
+
},
|
|
518
|
+
dispose() {
|
|
519
|
+
this.port.close();
|
|
520
|
+
},
|
|
521
|
+
start() {
|
|
522
|
+
this.port.start();
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
const IpcChildWithNodeMessagePort = {
|
|
528
|
+
__proto__: null,
|
|
529
|
+
listen: listen$1,
|
|
491
530
|
wrap: wrap$4
|
|
492
531
|
};
|
|
493
532
|
|
|
@@ -1037,4 +1076,4 @@ const IpcParentWithNodeWorker = {
|
|
|
1037
1076
|
wrap
|
|
1038
1077
|
};
|
|
1039
1078
|
|
|
1040
|
-
export { IpcChildWithElectronMessagePort, IpcChildWithElectronUtilityProcess, IpcChildWithModuleWorker, IpcChildWithModuleWorkerAndMessagePort, IpcChildWithNodeForkedProcess, IpcChildWithWebSocket, IpcParentWithElectronUtilityProcess, IpcParentWithNodeForkedProcess, IpcParentWithNodeWorker };
|
|
1079
|
+
export { IpcChildWithElectronMessagePort, IpcChildWithElectronUtilityProcess, IpcChildWithModuleWorker, IpcChildWithModuleWorkerAndMessagePort, IpcChildWithNodeForkedProcess, IpcChildWithNodeMessagePort, IpcChildWithWebSocket, IpcParentWithElectronUtilityProcess, IpcParentWithNodeForkedProcess, IpcParentWithNodeWorker };
|