@lvce-editor/ipc 11.7.0 → 12.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/dist/browser.js DELETED
@@ -1,867 +0,0 @@
1
- const getData$1 = event => {
2
- return event.data;
3
- };
4
-
5
- const attachEvents = that => {
6
- const handleMessage = (...args) => {
7
- const data = that.getData(...args);
8
- that.dispatchEvent(new MessageEvent('message', {
9
- data
10
- }));
11
- };
12
- that.onMessage(handleMessage);
13
- const handleClose = event => {
14
- that.dispatchEvent(new Event('close'));
15
- };
16
- that.onClose(handleClose);
17
- };
18
-
19
- class Ipc extends EventTarget {
20
- constructor(rawIpc) {
21
- super();
22
- this._rawIpc = rawIpc;
23
- attachEvents(this);
24
- }
25
- }
26
-
27
- const readyMessage = 'ready';
28
-
29
- const walkValue = (value, transferrables, isTransferrable) => {
30
- if (!value) {
31
- return;
32
- }
33
- if (isTransferrable(value)) {
34
- transferrables.push(value);
35
- return;
36
- }
37
- if (Array.isArray(value)) {
38
- for (const item of value) {
39
- walkValue(item, transferrables, isTransferrable);
40
- }
41
- return;
42
- }
43
- if (typeof value === 'object') {
44
- for (const property of Object.values(value)) {
45
- walkValue(property, transferrables, isTransferrable);
46
- }
47
- return;
48
- }
49
- };
50
-
51
- const isMessagePort = value => {
52
- return value && value instanceof MessagePort;
53
- };
54
-
55
- const isMessagePortMain = value => {
56
- return value && value.constructor && value.constructor.name === 'MessagePortMain';
57
- };
58
-
59
- const isOffscreenCanvas = value => {
60
- return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
61
- };
62
-
63
- const isInstanceOf = (value, constructorName) => {
64
- return value?.constructor?.name === constructorName;
65
- };
66
-
67
- const isSocket = value => {
68
- return isInstanceOf(value, 'Socket');
69
- };
70
-
71
- const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
72
-
73
- const isTransferrable = value => {
74
- for (const fn of transferrables) {
75
- if (fn(value)) {
76
- return true;
77
- }
78
- }
79
- return false;
80
- };
81
-
82
- const getTransferrables = value => {
83
- const transferrables = [];
84
- walkValue(value, transferrables, isTransferrable);
85
- return transferrables;
86
- };
87
-
88
- const removeValues = (value, toRemove) => {
89
- if (!value) {
90
- return value;
91
- }
92
- if (Array.isArray(value)) {
93
- const newItems = [];
94
- for (const item of value) {
95
- if (!toRemove.includes(item)) {
96
- newItems.push(removeValues(item, toRemove));
97
- }
98
- }
99
- return newItems;
100
- }
101
- if (typeof value === 'object') {
102
- const newObject = Object.create(null);
103
- for (const [key, property] of Object.entries(value)) {
104
- if (!toRemove.includes(property)) {
105
- newObject[key] = removeValues(property, toRemove);
106
- }
107
- }
108
- return newObject;
109
- }
110
- return value;
111
- };
112
-
113
- // workaround for electron not supporting transferrable objects
114
- // as parameters. If the transferrable object is a parameter, in electron
115
- // only an empty objected is received in the main process
116
- const fixElectronParameters = value => {
117
- const transfer = getTransferrables(value);
118
- const newValue = removeValues(value, transfer);
119
- return {
120
- newValue,
121
- transfer
122
- };
123
- };
124
-
125
- const listen$4 = () => {
126
- return window;
127
- };
128
- const signal$4 = global => {
129
- global.postMessage(readyMessage);
130
- };
131
- class IpcChildWithElectronWindow extends Ipc {
132
- getData(event) {
133
- return getData$1(event);
134
- }
135
- send(message) {
136
- this._rawIpc.postMessage(message);
137
- }
138
- sendAndTransfer(message) {
139
- const {
140
- newValue,
141
- transfer
142
- } = fixElectronParameters(message);
143
- this._rawIpc.postMessage(newValue, location.origin, transfer);
144
- }
145
- dispose() {
146
- // ignore
147
- }
148
- onClose(callback) {
149
- // ignore
150
- }
151
- onMessage(callback) {
152
- const wrapped = event => {
153
- const {
154
- ports
155
- } = event;
156
- if (ports.length) {
157
- return;
158
- }
159
- callback(event);
160
- this._rawIpc.removeEventListener('message', wrapped);
161
- };
162
- this._rawIpc.addEventListener('message', wrapped);
163
- }
164
- }
165
- const wrap$7 = window => {
166
- return new IpcChildWithElectronWindow(window);
167
- };
168
-
169
- const IpcChildWithElectronWindow$1 = {
170
- __proto__: null,
171
- listen: listen$4,
172
- signal: signal$4,
173
- wrap: wrap$7
174
- };
175
-
176
- const listen$3 = ({
177
- port
178
- }) => {
179
- return port;
180
- };
181
- const signal$3 = port => {
182
- port.postMessage(readyMessage);
183
- };
184
- class IpcChildWithMessagePort extends Ipc {
185
- constructor(port) {
186
- super(port);
187
- }
188
- getData(event) {
189
- return getData$1(event);
190
- }
191
- send(message) {
192
- this._rawIpc.postMessage(message);
193
- }
194
- sendAndTransfer(message) {
195
- const transfer = getTransferrables(message);
196
- this._rawIpc.postMessage(message, transfer);
197
- }
198
- dispose() {
199
- // ignore
200
- }
201
- onClose(callback) {
202
- // ignore
203
- }
204
- onMessage(callback) {
205
- this._rawIpc.addEventListener('message', callback);
206
- this._rawIpc.start();
207
- }
208
- }
209
- const wrap$6 = port => {
210
- return new IpcChildWithMessagePort(port);
211
- };
212
-
213
- const IpcChildWithMessagePort$1 = {
214
- __proto__: null,
215
- listen: listen$3,
216
- signal: signal$3,
217
- wrap: wrap$6
218
- };
219
-
220
- const listen$2 = () => {
221
- // @ts-ignore
222
- if (typeof WorkerGlobalScope === 'undefined') {
223
- throw new TypeError('module is not in web worker scope');
224
- }
225
- return globalThis;
226
- };
227
- const signal$2 = global => {
228
- global.postMessage(readyMessage);
229
- };
230
- class IpcChildWithModuleWorker extends Ipc {
231
- getData(event) {
232
- return getData$1(event);
233
- }
234
- send(message) {
235
- // @ts-ignore
236
- this._rawIpc.postMessage(message);
237
- }
238
- sendAndTransfer(message) {
239
- const transfer = getTransferrables(message);
240
- // @ts-ignore
241
- this._rawIpc.postMessage(message, transfer);
242
- }
243
- dispose() {
244
- // ignore
245
- }
246
- onClose(callback) {
247
- // ignore
248
- }
249
- onMessage(callback) {
250
- this._rawIpc.addEventListener('message', callback);
251
- }
252
- }
253
- const wrap$5 = global => {
254
- return new IpcChildWithModuleWorker(global);
255
- };
256
-
257
- const IpcChildWithModuleWorker$1 = {
258
- __proto__: null,
259
- listen: listen$2,
260
- signal: signal$2,
261
- wrap: wrap$5
262
- };
263
-
264
- const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
265
- const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
266
- const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
267
-
268
- const NewLine$1 = '\n';
269
-
270
- const joinLines = lines => {
271
- return lines.join(NewLine$1);
272
- };
273
-
274
- const splitLines = lines => {
275
- return lines.split(NewLine$1);
276
- };
277
-
278
- const isModuleNotFoundMessage = line => {
279
- return line.includes('[ERR_MODULE_NOT_FOUND]');
280
- };
281
- const getModuleNotFoundError = stderr => {
282
- const lines = splitLines(stderr);
283
- const messageIndex = lines.findIndex(isModuleNotFoundMessage);
284
- const message = lines[messageIndex];
285
- return {
286
- message,
287
- code: ERR_MODULE_NOT_FOUND
288
- };
289
- };
290
-
291
- const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
292
- const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
293
- const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
294
- const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
295
- const RE_AT = /^\s+at/;
296
- const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
297
- const isUnhelpfulNativeModuleError = stderr => {
298
- return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
299
- };
300
- const isMessageCodeBlockStartIndex = line => {
301
- return RE_MESSAGE_CODE_BLOCK_START.test(line);
302
- };
303
- const isMessageCodeBlockEndIndex = line => {
304
- return RE_MESSAGE_CODE_BLOCK_END.test(line);
305
- };
306
- const getMessageCodeBlock = stderr => {
307
- const lines = splitLines(stderr);
308
- const startIndex = lines.findIndex(isMessageCodeBlockStartIndex);
309
- const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
310
- const relevantLines = lines.slice(startIndex, endIndex);
311
- const relevantMessage = relevantLines.join(' ').slice('Error: '.length);
312
- return relevantMessage;
313
- };
314
- const getNativeModuleErrorMessage = stderr => {
315
- const message = getMessageCodeBlock(stderr);
316
- return {
317
- message: `Incompatible native node module: ${message}`,
318
- code: E_INCOMPATIBLE_NATIVE_MODULE
319
- };
320
- };
321
- const isModulesSyntaxError = stderr => {
322
- if (!stderr) {
323
- return false;
324
- }
325
- return stderr.includes('SyntaxError: Cannot use import statement outside a module');
326
- };
327
- const getModuleSyntaxError = () => {
328
- return {
329
- message: `ES Modules are not supported in electron`,
330
- code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON
331
- };
332
- };
333
- const isModuleNotFoundError = stderr => {
334
- if (!stderr) {
335
- return false;
336
- }
337
- return stderr.includes('ERR_MODULE_NOT_FOUND');
338
- };
339
- const isNormalStackLine = line => {
340
- return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
341
- };
342
- const getDetails = lines => {
343
- const index = lines.findIndex(isNormalStackLine);
344
- if (index === -1) {
345
- return {
346
- actualMessage: joinLines(lines),
347
- rest: []
348
- };
349
- }
350
- let lastIndex = index - 1;
351
- while (++lastIndex < lines.length) {
352
- if (!isNormalStackLine(lines[lastIndex])) {
353
- break;
354
- }
355
- }
356
- return {
357
- actualMessage: lines[index - 1],
358
- rest: lines.slice(index, lastIndex)
359
- };
360
- };
361
- const getHelpfulChildProcessError = (stdout, stderr) => {
362
- if (isUnhelpfulNativeModuleError(stderr)) {
363
- return getNativeModuleErrorMessage(stderr);
364
- }
365
- if (isModulesSyntaxError(stderr)) {
366
- return getModuleSyntaxError();
367
- }
368
- if (isModuleNotFoundError(stderr)) {
369
- return getModuleNotFoundError(stderr);
370
- }
371
- const lines = splitLines(stderr);
372
- const {
373
- actualMessage,
374
- rest
375
- } = getDetails(lines);
376
- return {
377
- message: `${actualMessage}`,
378
- code: '',
379
- stack: rest
380
- };
381
- };
382
-
383
- const normalizeLine = line => {
384
- if (line.startsWith('Error: ')) {
385
- return line.slice('Error: '.length);
386
- }
387
- if (line.startsWith('VError: ')) {
388
- return line.slice('VError: '.length);
389
- }
390
- return line;
391
- };
392
- const getCombinedMessage = (error, message) => {
393
- const stringifiedError = normalizeLine(`${error}`);
394
- if (message) {
395
- return `${message}: ${stringifiedError}`;
396
- }
397
- return stringifiedError;
398
- };
399
- const NewLine = '\n';
400
- const getNewLineIndex = (string, startIndex = undefined) => {
401
- return string.indexOf(NewLine, startIndex);
402
- };
403
- const mergeStacks = (parent, child) => {
404
- if (!child) {
405
- return parent;
406
- }
407
- const parentNewLineIndex = getNewLineIndex(parent);
408
- const childNewLineIndex = getNewLineIndex(child);
409
- if (childNewLineIndex === -1) {
410
- return parent;
411
- }
412
- const parentFirstLine = parent.slice(0, parentNewLineIndex);
413
- const childRest = child.slice(childNewLineIndex);
414
- const childFirstLine = normalizeLine(child.slice(0, childNewLineIndex));
415
- if (parentFirstLine.includes(childFirstLine)) {
416
- return parentFirstLine + childRest;
417
- }
418
- return child;
419
- };
420
- class VError extends Error {
421
- constructor(error, message) {
422
- const combinedMessage = getCombinedMessage(error, message);
423
- super(combinedMessage);
424
- this.name = 'VError';
425
- if (error instanceof Error) {
426
- this.stack = mergeStacks(this.stack, error.stack);
427
- }
428
- if (error.codeFrame) {
429
- // @ts-ignore
430
- this.codeFrame = error.codeFrame;
431
- }
432
- if (error.code) {
433
- // @ts-ignore
434
- this.code = error.code;
435
- }
436
- }
437
- }
438
-
439
- class IpcError extends VError {
440
- // @ts-ignore
441
- constructor(betterMessage, stdout = '', stderr = '') {
442
- if (stdout || stderr) {
443
- // @ts-ignore
444
- const {
445
- message,
446
- code,
447
- stack
448
- } = getHelpfulChildProcessError(stdout, stderr);
449
- const cause = new Error(message);
450
- // @ts-ignore
451
- cause.code = code;
452
- cause.stack = stack;
453
- super(cause, betterMessage);
454
- } else {
455
- super(betterMessage);
456
- }
457
- // @ts-ignore
458
- this.name = 'IpcError';
459
- // @ts-ignore
460
- this.stdout = stdout;
461
- // @ts-ignore
462
- this.stderr = stderr;
463
- }
464
- }
465
-
466
- const withResolvers = () => {
467
- let _resolve;
468
- const promise = new Promise(resolve => {
469
- _resolve = resolve;
470
- });
471
- return {
472
- resolve: _resolve,
473
- promise
474
- };
475
- };
476
-
477
- const waitForFirstMessage = async port => {
478
- const {
479
- resolve,
480
- promise
481
- } = withResolvers();
482
- port.addEventListener('message', resolve, {
483
- once: true
484
- });
485
- const event = await promise;
486
- // @ts-ignore
487
- return event.data;
488
- };
489
-
490
- const listen$1 = async () => {
491
- const parentIpcRaw = listen$2();
492
- signal$2(parentIpcRaw);
493
- const parentIpc = wrap$5(parentIpcRaw);
494
- const firstMessage = await waitForFirstMessage(parentIpc);
495
- if (firstMessage.method !== 'initialize') {
496
- throw new IpcError('unexpected first message');
497
- }
498
- const type = firstMessage.params[0];
499
- if (type === 'message-port') {
500
- parentIpc.send({
501
- jsonrpc: '2.0',
502
- id: firstMessage.id,
503
- result: null
504
- });
505
- parentIpc.dispose();
506
- const port = firstMessage.params[1];
507
- return port;
508
- }
509
- return globalThis;
510
- };
511
- class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
512
- constructor(port) {
513
- super(port);
514
- }
515
- getData(event) {
516
- return getData$1(event);
517
- }
518
- send(message) {
519
- this._rawIpc.postMessage(message);
520
- }
521
- sendAndTransfer(message) {
522
- const transfer = getTransferrables(message);
523
- this._rawIpc.postMessage(message, transfer);
524
- }
525
- dispose() {
526
- if (this._rawIpc.close) {
527
- this._rawIpc.close();
528
- }
529
- }
530
- onClose(callback) {
531
- // ignore
532
- }
533
- onMessage(callback) {
534
- this._rawIpc.addEventListener('message', callback);
535
- this._rawIpc.start();
536
- }
537
- }
538
- const wrap$4 = port => {
539
- return new IpcChildWithModuleWorkerAndMessagePort(port);
540
- };
541
-
542
- const IpcChildWithModuleWorkerAndMessagePort$1 = {
543
- __proto__: null,
544
- listen: listen$1,
545
- wrap: wrap$4
546
- };
547
-
548
- const listen = () => {
549
- return window;
550
- };
551
- const signal$1 = global => {
552
- global.postMessage(readyMessage);
553
- };
554
- class IpcChildWithWindow extends Ipc {
555
- getData(event) {
556
- return getData$1(event);
557
- }
558
- send(message) {
559
- this._rawIpc.postMessage(message);
560
- }
561
- sendAndTransfer(message) {
562
- const transfer = getTransferrables(message);
563
- this._rawIpc.postMessage(message, location.origin, transfer);
564
- }
565
- dispose() {
566
- // ignore
567
- }
568
- onClose(callback) {
569
- // ignore
570
- }
571
- onMessage(callback) {
572
- const wrapped = event => {
573
- const {
574
- ports
575
- } = event;
576
- if (ports.length) {
577
- return;
578
- }
579
- callback(event);
580
- this._rawIpc.removeEventListener('message', wrapped);
581
- };
582
- this._rawIpc.addEventListener('message', wrapped);
583
- }
584
- }
585
- const wrap$3 = window => {
586
- return new IpcChildWithWindow(window);
587
- };
588
-
589
- const IpcChildWithWindow$1 = {
590
- __proto__: null,
591
- listen,
592
- signal: signal$1,
593
- wrap: wrap$3
594
- };
595
-
596
- const Message$1 = 3;
597
-
598
- const addListener = (emitter, type, callback) => {
599
- if ('addEventListener' in emitter) {
600
- emitter.addEventListener(type, callback);
601
- } else {
602
- emitter.on(type, callback);
603
- }
604
- };
605
- const removeListener = (emitter, type, callback) => {
606
- if ('removeEventListener' in emitter) {
607
- emitter.removeEventListener(type, callback);
608
- } else {
609
- emitter.off(type, callback);
610
- }
611
- };
612
- const getFirstEvent = (eventEmitter, eventMap) => {
613
- const {
614
- resolve,
615
- promise
616
- } = withResolvers();
617
- const listenerMap = Object.create(null);
618
- const cleanup = value => {
619
- for (const event of Object.keys(eventMap)) {
620
- removeListener(eventEmitter, event, listenerMap[event]);
621
- }
622
- resolve(value);
623
- };
624
- for (const [event, type] of Object.entries(eventMap)) {
625
- const listener = event => {
626
- cleanup({
627
- type,
628
- event
629
- });
630
- };
631
- addListener(eventEmitter, event, listener);
632
- listenerMap[event] = listener;
633
- }
634
- return promise;
635
- };
636
-
637
- const create$2 = async ({
638
- messagePort,
639
- isMessagePortOpen
640
- }) => {
641
- if (!isMessagePort(messagePort)) {
642
- throw new IpcError('port must be of type MessagePort');
643
- }
644
- if (isMessagePortOpen) {
645
- return messagePort;
646
- }
647
- const eventPromise = getFirstEvent(messagePort, {
648
- message: Message$1
649
- });
650
- messagePort.start();
651
- const event = await eventPromise;
652
- // @ts-ignore
653
- if (event.data !== readyMessage) {
654
- throw new IpcError('unexpected first message');
655
- }
656
- return messagePort;
657
- };
658
- const signal = messagePort => {
659
- messagePort.start();
660
- };
661
- class IpcParentWithMessagePort extends Ipc {
662
- constructor(port) {
663
- super(port);
664
- }
665
- getData = getData$1;
666
- send(message) {
667
- this._rawIpc.postMessage(message);
668
- }
669
- sendAndTransfer(message) {
670
- throw new Error('not implemented');
671
- }
672
- dispose() {
673
- this._rawIpc.close();
674
- }
675
- onMessage(callback) {
676
- this._rawIpc.addEventListener('message', callback);
677
- }
678
- onClose(callback) {}
679
- }
680
- const wrap$2 = messagePort => {
681
- return new IpcParentWithMessagePort(messagePort);
682
- };
683
-
684
- const IpcParentWithMessagePort$1 = {
685
- __proto__: null,
686
- create: create$2,
687
- signal,
688
- wrap: wrap$2
689
- };
690
-
691
- const Message = 'message';
692
- const Error$1 = 'error';
693
-
694
- const getFirstWorkerEvent = worker => {
695
- return getFirstEvent(worker, {
696
- message: Message,
697
- error: Error$1
698
- });
699
- };
700
-
701
- const isErrorEvent = event => {
702
- return event instanceof ErrorEvent;
703
- };
704
-
705
- const getWorkerDisplayName = name => {
706
- if (!name) {
707
- return '<unknown> worker';
708
- }
709
- if (name.endsWith('Worker') || name.endsWith('worker')) {
710
- return name.toLowerCase();
711
- }
712
- return `${name} Worker`;
713
- };
714
-
715
- const tryToGetActualErrorMessage = async ({
716
- name
717
- }) => {
718
- const displayName = getWorkerDisplayName(name);
719
- return `Failed to start ${displayName}: Worker Launch Error`;
720
- };
721
-
722
- class WorkerError extends Error {
723
- constructor(event) {
724
- super(event.message);
725
- const stackLines = splitLines(this.stack || '');
726
- const relevantLines = stackLines.slice(1);
727
- const relevant = joinLines(relevantLines);
728
- this.stack = `${event.message}
729
- at Module (${event.filename}:${event.lineno}:${event.colno})
730
- ${relevant}`;
731
- }
732
- }
733
-
734
- const Module = 'module';
735
-
736
- const create$1 = async ({
737
- url,
738
- name
739
- }) => {
740
- const worker = new Worker(url, {
741
- type: Module,
742
- name
743
- });
744
- const {
745
- type,
746
- event
747
- } = await getFirstWorkerEvent(worker);
748
- switch (type) {
749
- case Message:
750
- if (event.data !== readyMessage) {
751
- throw new IpcError('unexpected first message from worker');
752
- }
753
- break;
754
- case Error$1:
755
- if (isErrorEvent(event)) {
756
- throw new WorkerError(event);
757
- }
758
- const actualErrorMessage = await tryToGetActualErrorMessage({
759
- name
760
- });
761
- throw new Error(actualErrorMessage);
762
- }
763
- return worker;
764
- };
765
- const getData = event => {
766
- // TODO why are some events not instance of message event?
767
- if (event instanceof MessageEvent) {
768
- return event.data;
769
- }
770
- return event;
771
- };
772
- class IpcParentWithModuleWorker extends Ipc {
773
- getData(event) {
774
- return getData(event);
775
- }
776
- send(message) {
777
- this._rawIpc.postMessage(message);
778
- }
779
- sendAndTransfer(message) {
780
- const transfer = getTransferrables(message);
781
- this._rawIpc.postMessage(message, transfer);
782
- }
783
- dispose() {
784
- // ignore
785
- }
786
- onClose(callback) {
787
- // ignore
788
- }
789
- onMessage(callback) {
790
- this._rawIpc.addEventListener('message', callback);
791
- }
792
- }
793
- const wrap$1 = worker => {
794
- return new IpcParentWithModuleWorker(worker);
795
- };
796
-
797
- const IpcParentWithModuleWorker$1 = {
798
- __proto__: null,
799
- create: create$1,
800
- wrap: wrap$1
801
- };
802
-
803
- const Open = 1;
804
- const Close = 2;
805
-
806
- const stringifyCompact = value => {
807
- return JSON.stringify(value);
808
- };
809
- const parse = content => {
810
- if (content === 'undefined') {
811
- return null;
812
- }
813
- try {
814
- return JSON.parse(content);
815
- } catch (error) {
816
- throw new VError(error, 'failed to parse json');
817
- }
818
- };
819
-
820
- const waitForWebSocketToBeOpen = webSocket => {
821
- return getFirstEvent(webSocket, {
822
- open: Open,
823
- close: Close
824
- });
825
- };
826
-
827
- const create = async ({
828
- webSocket
829
- }) => {
830
- const firstWebSocketEvent = await waitForWebSocketToBeOpen(webSocket);
831
- // @ts-ignore
832
- if (firstWebSocketEvent.type === Close) {
833
- throw new IpcError('Websocket connection was immediately closed');
834
- }
835
- return webSocket;
836
- };
837
- class IpcParentWithWebSocket extends Ipc {
838
- getData(event) {
839
- return parse(event.data);
840
- }
841
- send(message) {
842
- this._rawIpc.send(stringifyCompact(message));
843
- }
844
- sendAndTransfer(message) {
845
- throw new Error('sendAndTransfer not supported');
846
- }
847
- dispose() {
848
- this._rawIpc.close();
849
- }
850
- onClose(callback) {
851
- this._rawIpc.addEventListener('close', callback);
852
- }
853
- onMessage(callback) {
854
- this._rawIpc.addEventListener('message', callback);
855
- }
856
- }
857
- const wrap = webSocket => {
858
- return new IpcParentWithWebSocket(webSocket);
859
- };
860
-
861
- const IpcParentWithWebSocket$1 = {
862
- __proto__: null,
863
- create,
864
- wrap
865
- };
866
-
867
- export { IpcChildWithElectronWindow$1 as IpcChildWithElectronWindow, IpcChildWithMessagePort$1 as IpcChildWithMessagePort, IpcChildWithModuleWorker$1 as IpcChildWithModuleWorker, IpcChildWithModuleWorkerAndMessagePort$1 as IpcChildWithModuleWorkerAndMessagePort, IpcChildWithWindow$1 as IpcChildWithWindow, IpcParentWithMessagePort$1 as IpcParentWithMessagePort, IpcParentWithModuleWorker$1 as IpcParentWithModuleWorker, IpcParentWithWebSocket$1 as IpcParentWithWebSocket };