@lvce-editor/embeds-worker 2.5.0 → 4.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/README.md +16 -1
- package/dist/embedsWorkerMain.js +277 -173
- package/package.json +9 -6
package/README.md
CHANGED
|
@@ -1 +1,16 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Embeds Worker
|
|
2
|
+
|
|
3
|
+
Web Worker for the embeds functionality in LVCE Editor.
|
|
4
|
+
|
|
5
|
+
## Contributing
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
git clone git@github.com:lvce-editor/embeds-worker.git &&
|
|
9
|
+
cd embeds-worker &&
|
|
10
|
+
npm ci &&
|
|
11
|
+
npm test
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Gitpod
|
|
15
|
+
|
|
16
|
+
[](https://gitpod.io/#https://github.com/lvce-editor/embeds)
|
package/dist/embedsWorkerMain.js
CHANGED
|
@@ -368,6 +368,100 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
|
368
368
|
listen: listen$6,
|
|
369
369
|
wrap: wrap$e
|
|
370
370
|
};
|
|
371
|
+
const addListener = (emitter, type, callback) => {
|
|
372
|
+
if ('addEventListener' in emitter) {
|
|
373
|
+
emitter.addEventListener(type, callback);
|
|
374
|
+
} else {
|
|
375
|
+
emitter.on(type, callback);
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
const removeListener = (emitter, type, callback) => {
|
|
379
|
+
if ('removeEventListener' in emitter) {
|
|
380
|
+
emitter.removeEventListener(type, callback);
|
|
381
|
+
} else {
|
|
382
|
+
emitter.off(type, callback);
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
const getFirstEvent = (eventEmitter, eventMap) => {
|
|
386
|
+
const {
|
|
387
|
+
resolve,
|
|
388
|
+
promise
|
|
389
|
+
} = Promise.withResolvers();
|
|
390
|
+
const listenerMap = Object.create(null);
|
|
391
|
+
const cleanup = value => {
|
|
392
|
+
for (const event of Object.keys(eventMap)) {
|
|
393
|
+
removeListener(eventEmitter, event, listenerMap[event]);
|
|
394
|
+
}
|
|
395
|
+
resolve(value);
|
|
396
|
+
};
|
|
397
|
+
for (const [event, type] of Object.entries(eventMap)) {
|
|
398
|
+
const listener = event => {
|
|
399
|
+
cleanup({
|
|
400
|
+
type,
|
|
401
|
+
event
|
|
402
|
+
});
|
|
403
|
+
};
|
|
404
|
+
addListener(eventEmitter, event, listener);
|
|
405
|
+
listenerMap[event] = listener;
|
|
406
|
+
}
|
|
407
|
+
return promise;
|
|
408
|
+
};
|
|
409
|
+
const Message$1 = 3;
|
|
410
|
+
const create$5$1 = async ({
|
|
411
|
+
messagePort,
|
|
412
|
+
isMessagePortOpen
|
|
413
|
+
}) => {
|
|
414
|
+
if (!isMessagePort(messagePort)) {
|
|
415
|
+
throw new IpcError('port must be of type MessagePort');
|
|
416
|
+
}
|
|
417
|
+
if (isMessagePortOpen) {
|
|
418
|
+
return messagePort;
|
|
419
|
+
}
|
|
420
|
+
const eventPromise = getFirstEvent(messagePort, {
|
|
421
|
+
message: Message$1
|
|
422
|
+
});
|
|
423
|
+
messagePort.start();
|
|
424
|
+
const {
|
|
425
|
+
type,
|
|
426
|
+
event
|
|
427
|
+
} = await eventPromise;
|
|
428
|
+
if (type !== Message$1) {
|
|
429
|
+
throw new IpcError('Failed to wait for ipc message');
|
|
430
|
+
}
|
|
431
|
+
if (event.data !== readyMessage) {
|
|
432
|
+
throw new IpcError('unexpected first message');
|
|
433
|
+
}
|
|
434
|
+
return messagePort;
|
|
435
|
+
};
|
|
436
|
+
const signal$1 = messagePort => {
|
|
437
|
+
messagePort.start();
|
|
438
|
+
};
|
|
439
|
+
class IpcParentWithMessagePort extends Ipc {
|
|
440
|
+
getData = getData$2;
|
|
441
|
+
send(message) {
|
|
442
|
+
this._rawIpc.postMessage(message);
|
|
443
|
+
}
|
|
444
|
+
sendAndTransfer(message) {
|
|
445
|
+
const transfer = getTransferrables(message);
|
|
446
|
+
this._rawIpc.postMessage(message, transfer);
|
|
447
|
+
}
|
|
448
|
+
dispose() {
|
|
449
|
+
this._rawIpc.close();
|
|
450
|
+
}
|
|
451
|
+
onMessage(callback) {
|
|
452
|
+
this._rawIpc.addEventListener('message', callback);
|
|
453
|
+
}
|
|
454
|
+
onClose(callback) {}
|
|
455
|
+
}
|
|
456
|
+
const wrap$5 = messagePort => {
|
|
457
|
+
return new IpcParentWithMessagePort(messagePort);
|
|
458
|
+
};
|
|
459
|
+
const IpcParentWithMessagePort$1 = {
|
|
460
|
+
__proto__: null,
|
|
461
|
+
create: create$5$1,
|
|
462
|
+
signal: signal$1,
|
|
463
|
+
wrap: wrap$5
|
|
464
|
+
};
|
|
371
465
|
|
|
372
466
|
const Two = '2.0';
|
|
373
467
|
const create$4 = (method, params) => {
|
|
@@ -378,10 +472,10 @@ const create$4 = (method, params) => {
|
|
|
378
472
|
};
|
|
379
473
|
};
|
|
380
474
|
const callbacks = Object.create(null);
|
|
381
|
-
const set = (id, fn) => {
|
|
475
|
+
const set$2 = (id, fn) => {
|
|
382
476
|
callbacks[id] = fn;
|
|
383
477
|
};
|
|
384
|
-
const get = id => {
|
|
478
|
+
const get$1 = id => {
|
|
385
479
|
return callbacks[id];
|
|
386
480
|
};
|
|
387
481
|
const remove = id => {
|
|
@@ -397,13 +491,13 @@ const registerPromise = () => {
|
|
|
397
491
|
resolve,
|
|
398
492
|
promise
|
|
399
493
|
} = Promise.withResolvers();
|
|
400
|
-
set(id, resolve);
|
|
494
|
+
set$2(id, resolve);
|
|
401
495
|
return {
|
|
402
496
|
id,
|
|
403
497
|
promise
|
|
404
498
|
};
|
|
405
499
|
};
|
|
406
|
-
const create$2
|
|
500
|
+
const create$2 = (method, params) => {
|
|
407
501
|
const {
|
|
408
502
|
id,
|
|
409
503
|
promise
|
|
@@ -554,7 +648,7 @@ const warn = (...args) => {
|
|
|
554
648
|
console.warn(...args);
|
|
555
649
|
};
|
|
556
650
|
const resolve = (id, response) => {
|
|
557
|
-
const fn = get(id);
|
|
651
|
+
const fn = get$1(id);
|
|
558
652
|
if (!fn) {
|
|
559
653
|
console.log(response);
|
|
560
654
|
warn(`callback ${id} may already be disposed`);
|
|
@@ -573,6 +667,17 @@ const getErrorType = prettyError => {
|
|
|
573
667
|
}
|
|
574
668
|
return undefined;
|
|
575
669
|
};
|
|
670
|
+
const isAlreadyStack = line => {
|
|
671
|
+
return line.trim().startsWith('at ');
|
|
672
|
+
};
|
|
673
|
+
const getStack = prettyError => {
|
|
674
|
+
const stackString = prettyError.stack || '';
|
|
675
|
+
const newLineIndex = stackString.indexOf('\n');
|
|
676
|
+
if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
|
|
677
|
+
return stackString.slice(newLineIndex + 1);
|
|
678
|
+
}
|
|
679
|
+
return stackString;
|
|
680
|
+
};
|
|
576
681
|
const getErrorProperty = (error, prettyError) => {
|
|
577
682
|
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
578
683
|
return {
|
|
@@ -585,7 +690,7 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
585
690
|
code: Custom,
|
|
586
691
|
message: prettyError.message,
|
|
587
692
|
data: {
|
|
588
|
-
stack: prettyError
|
|
693
|
+
stack: getStack(prettyError),
|
|
589
694
|
codeFrame: prettyError.codeFrame,
|
|
590
695
|
type: getErrorType(prettyError),
|
|
591
696
|
code: prettyError.code,
|
|
@@ -695,7 +800,7 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
695
800
|
const {
|
|
696
801
|
message,
|
|
697
802
|
promise
|
|
698
|
-
} = create$2
|
|
803
|
+
} = create$2(method, params);
|
|
699
804
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
700
805
|
ipc.sendAndTransfer(message);
|
|
701
806
|
} else {
|
|
@@ -704,11 +809,11 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
704
809
|
const responseMessage = await promise;
|
|
705
810
|
return unwrapJsonRpcResult(responseMessage);
|
|
706
811
|
};
|
|
707
|
-
const send
|
|
812
|
+
const send = (transport, method, ...params) => {
|
|
708
813
|
const message = create$4(method, params);
|
|
709
814
|
transport.send(message);
|
|
710
815
|
};
|
|
711
|
-
const invoke$
|
|
816
|
+
const invoke$2 = (ipc, method, ...params) => {
|
|
712
817
|
return invokeHelper(ipc, method, params, false);
|
|
713
818
|
};
|
|
714
819
|
const invokeAndTransfer$1 = (ipc, method, ...params) => {
|
|
@@ -719,11 +824,11 @@ const commands = Object.create(null);
|
|
|
719
824
|
const register = commandMap => {
|
|
720
825
|
Object.assign(commands, commandMap);
|
|
721
826
|
};
|
|
722
|
-
const getCommand
|
|
827
|
+
const getCommand = key => {
|
|
723
828
|
return commands[key];
|
|
724
829
|
};
|
|
725
|
-
const execute
|
|
726
|
-
const fn = getCommand
|
|
830
|
+
const execute = (command, ...args) => {
|
|
831
|
+
const fn = getCommand(command);
|
|
727
832
|
if (!fn) {
|
|
728
833
|
throw new Error(`command not found ${command}`);
|
|
729
834
|
}
|
|
@@ -738,10 +843,10 @@ const createRpc = ipc => {
|
|
|
738
843
|
* @deprecated
|
|
739
844
|
*/
|
|
740
845
|
send(method, ...params) {
|
|
741
|
-
send
|
|
846
|
+
send(ipc, method, ...params);
|
|
742
847
|
},
|
|
743
848
|
invoke(method, ...params) {
|
|
744
|
-
return invoke$
|
|
849
|
+
return invoke$2(ipc, method, ...params);
|
|
745
850
|
},
|
|
746
851
|
invokeAndTransfer(method, ...params) {
|
|
747
852
|
return invokeAndTransfer$1(ipc, method, ...params);
|
|
@@ -752,26 +857,26 @@ const createRpc = ipc => {
|
|
|
752
857
|
};
|
|
753
858
|
return rpc;
|
|
754
859
|
};
|
|
755
|
-
const requiresSocket
|
|
860
|
+
const requiresSocket = () => {
|
|
756
861
|
return false;
|
|
757
862
|
};
|
|
758
|
-
const preparePrettyError
|
|
863
|
+
const preparePrettyError = error => {
|
|
759
864
|
return error;
|
|
760
865
|
};
|
|
761
|
-
const logError
|
|
866
|
+
const logError = () => {
|
|
762
867
|
// handled by renderer worker
|
|
763
868
|
};
|
|
764
|
-
const handleMessage
|
|
765
|
-
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket
|
|
766
|
-
const actualExecute = event?.target?.execute || execute
|
|
767
|
-
return handleJsonRpcMessage(event.target, event.data, actualExecute, resolve, preparePrettyError
|
|
869
|
+
const handleMessage = event => {
|
|
870
|
+
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
871
|
+
const actualExecute = event?.target?.execute || execute;
|
|
872
|
+
return handleJsonRpcMessage(event.target, event.data, actualExecute, resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
768
873
|
};
|
|
769
|
-
const handleIpc
|
|
874
|
+
const handleIpc = ipc => {
|
|
770
875
|
if ('addEventListener' in ipc) {
|
|
771
|
-
ipc.addEventListener('message', handleMessage
|
|
876
|
+
ipc.addEventListener('message', handleMessage);
|
|
772
877
|
} else if ('on' in ipc) {
|
|
773
878
|
// deprecated
|
|
774
|
-
ipc.on('message', handleMessage
|
|
879
|
+
ipc.on('message', handleMessage);
|
|
775
880
|
}
|
|
776
881
|
};
|
|
777
882
|
const listen$1 = async (module, options) => {
|
|
@@ -782,187 +887,140 @@ const listen$1 = async (module, options) => {
|
|
|
782
887
|
const ipc = module.wrap(rawIpc);
|
|
783
888
|
return ipc;
|
|
784
889
|
};
|
|
785
|
-
const create$
|
|
890
|
+
const create$9 = async ({
|
|
891
|
+
commandMap,
|
|
892
|
+
messagePort,
|
|
893
|
+
isMessagePortOpen
|
|
894
|
+
}) => {
|
|
895
|
+
// TODO create a commandMap per rpc instance
|
|
896
|
+
register(commandMap);
|
|
897
|
+
const rawIpc = await IpcParentWithMessagePort$1.create({
|
|
898
|
+
messagePort,
|
|
899
|
+
isMessagePortOpen
|
|
900
|
+
});
|
|
901
|
+
const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
|
|
902
|
+
handleIpc(ipc);
|
|
903
|
+
const rpc = createRpc(ipc);
|
|
904
|
+
return rpc;
|
|
905
|
+
};
|
|
906
|
+
const MessagePortRpcParent = {
|
|
907
|
+
__proto__: null,
|
|
908
|
+
create: create$9
|
|
909
|
+
};
|
|
910
|
+
const create$1 = async ({
|
|
786
911
|
commandMap
|
|
787
912
|
}) => {
|
|
788
913
|
// TODO create a commandMap per rpc instance
|
|
789
914
|
register(commandMap);
|
|
790
915
|
const ipc = await listen$1(IpcChildWithModuleWorkerAndMessagePort$1);
|
|
791
|
-
handleIpc
|
|
916
|
+
handleIpc(ipc);
|
|
792
917
|
const rpc = createRpc(ipc);
|
|
793
918
|
return rpc;
|
|
794
919
|
};
|
|
795
920
|
const WebWorkerRpcClient = {
|
|
796
921
|
__proto__: null,
|
|
797
|
-
create: create$
|
|
798
|
-
};
|
|
799
|
-
|
|
800
|
-
const state$2 = {
|
|
801
|
-
commands: Object.create(null)
|
|
802
|
-
};
|
|
803
|
-
const getCommand = key => {
|
|
804
|
-
return state$2.commands[key];
|
|
805
|
-
};
|
|
806
|
-
|
|
807
|
-
const processName = 'embeds-worker';
|
|
808
|
-
|
|
809
|
-
const execute = (command, ...args) => {
|
|
810
|
-
const fn = getCommand(command);
|
|
811
|
-
if (!fn) {
|
|
812
|
-
throw new Error(`[${processName}] command not found ${command}`);
|
|
813
|
-
}
|
|
814
|
-
return fn(...args);
|
|
922
|
+
create: create$1
|
|
815
923
|
};
|
|
816
924
|
|
|
817
|
-
const
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
const preparePrettyError = error => {
|
|
821
|
-
return error;
|
|
822
|
-
};
|
|
823
|
-
const logError = error => {
|
|
824
|
-
console.error(error);
|
|
825
|
-
};
|
|
826
|
-
const handleMessage = event => {
|
|
827
|
-
return handleJsonRpcMessage(event.target, event.data, execute, resolve, preparePrettyError, logError, requiresSocket);
|
|
828
|
-
};
|
|
829
|
-
const handleIpc = ipc => {
|
|
830
|
-
ipc.onmessage = handleMessage;
|
|
925
|
+
const rpcs = Object.create(null);
|
|
926
|
+
const set$a = (id, rpc) => {
|
|
927
|
+
rpcs[id] = rpc;
|
|
831
928
|
};
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
const {
|
|
835
|
-
port1,
|
|
836
|
-
port2
|
|
837
|
-
} = new MessageChannel();
|
|
838
|
-
return {
|
|
839
|
-
port1,
|
|
840
|
-
port2
|
|
841
|
-
};
|
|
929
|
+
const get = id => {
|
|
930
|
+
return rpcs[id];
|
|
842
931
|
};
|
|
843
932
|
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
const state$1 = {
|
|
847
|
-
rpc: undefined
|
|
848
|
-
};
|
|
849
|
-
const send = (method, ...params) => {
|
|
850
|
-
const rpc = state$1.rpc;
|
|
851
|
-
// @ts-ignore
|
|
852
|
-
return rpc.send(method, ...params);
|
|
853
|
-
};
|
|
854
|
-
const invokeAndTransfer = (method, ...params) => {
|
|
855
|
-
const rpc = state$1.rpc;
|
|
856
|
-
// @ts-ignore
|
|
857
|
-
return rpc.invokeAndTransfer(method, ...params);
|
|
858
|
-
};
|
|
859
|
-
const setRpc = rpc => {
|
|
860
|
-
state$1.rpc = rpc;
|
|
861
|
-
};
|
|
933
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
862
934
|
|
|
863
|
-
const create
|
|
864
|
-
initialCommand
|
|
865
|
-
}) => {
|
|
866
|
-
const {
|
|
867
|
-
port1,
|
|
868
|
-
port2
|
|
869
|
-
} = getPortTuple();
|
|
870
|
-
// TODO call sendMessagePortToSharedProcess function instead
|
|
871
|
-
await invokeAndTransfer('IpcParent.create', {
|
|
872
|
-
method: 8,
|
|
873
|
-
type: 1,
|
|
874
|
-
initialCommand,
|
|
875
|
-
port: port1,
|
|
876
|
-
raw: true,
|
|
877
|
-
ipcId: EmbedsWorker
|
|
878
|
-
});
|
|
879
|
-
return port2;
|
|
880
|
-
};
|
|
881
|
-
const wrap = port => {
|
|
935
|
+
const create = rpcId => {
|
|
882
936
|
return {
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
937
|
+
// @ts-ignore
|
|
938
|
+
invoke(method, ...params) {
|
|
939
|
+
const rpc = get(rpcId);
|
|
940
|
+
// @ts-ignore
|
|
941
|
+
return rpc.invoke(method, ...params);
|
|
886
942
|
},
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
};
|
|
893
|
-
listener(syntheticEvent);
|
|
894
|
-
};
|
|
895
|
-
this.port.onmessage = wrappedListener;
|
|
943
|
+
// @ts-ignore
|
|
944
|
+
invokeAndTransfer(method, ...params) {
|
|
945
|
+
const rpc = get(rpcId);
|
|
946
|
+
// @ts-ignore
|
|
947
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
896
948
|
},
|
|
897
|
-
|
|
949
|
+
set(rpc) {
|
|
950
|
+
set$a(rpcId, rpc);
|
|
898
951
|
}
|
|
899
952
|
};
|
|
900
953
|
};
|
|
901
|
-
|
|
902
|
-
const
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
};
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
954
|
+
const RendererWorker$1 = 1;
|
|
955
|
+
const EmbedsProcess$1 = 207;
|
|
956
|
+
const {
|
|
957
|
+
invoke: invoke$8,
|
|
958
|
+
set: set$8
|
|
959
|
+
} = create(EmbedsProcess$1);
|
|
960
|
+
const EmbedsProcess = {
|
|
961
|
+
__proto__: null,
|
|
962
|
+
invoke: invoke$8,
|
|
963
|
+
set: set$8
|
|
964
|
+
};
|
|
965
|
+
const {
|
|
966
|
+
invoke: invoke$5,
|
|
967
|
+
invokeAndTransfer: invokeAndTransfer$5,
|
|
968
|
+
set: set$5
|
|
969
|
+
} = create(RendererWorker$1);
|
|
970
|
+
const RendererWorker = {
|
|
971
|
+
__proto__: null,
|
|
972
|
+
invoke: invoke$5,
|
|
973
|
+
invokeAndTransfer: invokeAndTransfer$5,
|
|
974
|
+
set: set$5
|
|
918
975
|
};
|
|
919
976
|
|
|
920
|
-
const
|
|
921
|
-
|
|
922
|
-
};
|
|
923
|
-
const getOrCreate = () => {
|
|
924
|
-
state.workerPromise ||= launchEmbedsProcessIpc();
|
|
925
|
-
return state.workerPromise;
|
|
926
|
-
};
|
|
927
|
-
const invoke = async (method, ...params) => {
|
|
928
|
-
const ipc = await getOrCreate();
|
|
929
|
-
return invoke$1(ipc, method, ...params);
|
|
930
|
-
};
|
|
977
|
+
const {
|
|
978
|
+
set: set$1,
|
|
979
|
+
invoke: invoke$1} = EmbedsProcess;
|
|
931
980
|
|
|
932
981
|
const ERR_ABORTED = 'ERR_ABORTED';
|
|
933
982
|
const ERR_FAILED = 'ERR_FAILED';
|
|
934
983
|
|
|
984
|
+
const {
|
|
985
|
+
invoke,
|
|
986
|
+
set,
|
|
987
|
+
invokeAndTransfer
|
|
988
|
+
} = RendererWorker;
|
|
989
|
+
|
|
935
990
|
const createWebContentsView = async (restoreId, fallThroughKeyBindings) => {
|
|
936
|
-
|
|
991
|
+
// @ts-ignore
|
|
992
|
+
const id = await invoke$1('ElectronWebContentsView.createWebContentsView', restoreId, fallThroughKeyBindings);
|
|
937
993
|
return id;
|
|
938
994
|
};
|
|
939
995
|
const disposeWebContentsView = id => {
|
|
940
|
-
return invoke('ElectronWebContentsView.disposeWebContentsView', id);
|
|
996
|
+
return invoke$1('ElectronWebContentsView.disposeWebContentsView', id);
|
|
941
997
|
};
|
|
942
998
|
const resizeWebContentsView = (id, x, y, width, height) => {
|
|
943
|
-
return invoke('ElectronWebContentsView.resizeBrowserView', id, x, y, width, height);
|
|
999
|
+
return invoke$1('ElectronWebContentsView.resizeBrowserView', id, x, y, width, height);
|
|
944
1000
|
};
|
|
945
1001
|
const setIframeSrcFallback = async (id, error) => {
|
|
946
1002
|
const {
|
|
947
1003
|
code,
|
|
948
1004
|
message
|
|
949
1005
|
} = error;
|
|
950
|
-
await invoke('ElectronWebContentsView.setIframeSrcFallback', id, code, message);
|
|
1006
|
+
await invoke$1('ElectronWebContentsView.setIframeSrcFallback', id, code, message);
|
|
951
1007
|
};
|
|
952
1008
|
const setIframeSrc = async (id, iframeSrc) => {
|
|
953
1009
|
try {
|
|
954
|
-
await invoke('ElectronWebContentsView.setIframeSrc', id, iframeSrc);
|
|
1010
|
+
await invoke$1('ElectronWebContentsView.setIframeSrc', id, iframeSrc);
|
|
955
1011
|
} catch (error) {
|
|
956
1012
|
console.log({
|
|
957
1013
|
error
|
|
958
1014
|
});
|
|
959
1015
|
// TODO send error back to embeds worker,
|
|
960
1016
|
// embeds worker decides how to handle error
|
|
1017
|
+
|
|
961
1018
|
// @ts-ignore
|
|
962
1019
|
if (error && error.code === ERR_ABORTED) {
|
|
963
1020
|
console.info(`[embeds worker] navigation to ${iframeSrc} aborted`);
|
|
964
1021
|
return;
|
|
965
1022
|
}
|
|
1023
|
+
|
|
966
1024
|
// @ts-ignore
|
|
967
1025
|
if (error && error.code === ERR_FAILED) {
|
|
968
1026
|
console.info(`[embeds worker] navigation to ${iframeSrc} canceled`);
|
|
@@ -977,53 +1035,53 @@ const setIframeSrc = async (id, iframeSrc) => {
|
|
|
977
1035
|
}
|
|
978
1036
|
};
|
|
979
1037
|
const focus = id => {
|
|
980
|
-
return invoke('ElectronWebContentsView.focus', id);
|
|
1038
|
+
return invoke$1('ElectronWebContentsView.focus', id);
|
|
981
1039
|
};
|
|
982
1040
|
const openDevtools = id => {
|
|
983
|
-
return invoke('ElectronWebContentsView.openDevtools', id);
|
|
1041
|
+
return invoke$1('ElectronWebContentsView.openDevtools', id);
|
|
984
1042
|
};
|
|
985
1043
|
const reload = id => {
|
|
986
|
-
return invoke('ElectronWebContentsView.reload', id);
|
|
1044
|
+
return invoke$1('ElectronWebContentsView.reload', id);
|
|
987
1045
|
};
|
|
988
1046
|
const show = id => {
|
|
989
|
-
return invoke('ElectronWebContentsView.show', id);
|
|
1047
|
+
return invoke$1('ElectronWebContentsView.show', id);
|
|
990
1048
|
};
|
|
991
1049
|
const hide = id => {
|
|
992
|
-
return invoke('ElectronWebContentsView.hide', id);
|
|
1050
|
+
return invoke$1('ElectronWebContentsView.hide', id);
|
|
993
1051
|
};
|
|
994
1052
|
const forward = id => {
|
|
995
|
-
return invoke('ElectronWebContentsView.forward', id);
|
|
1053
|
+
return invoke$1('ElectronWebContentsView.forward', id);
|
|
996
1054
|
};
|
|
997
1055
|
const backward = id => {
|
|
998
|
-
return invoke('ElectronWebContentsView.backward', id);
|
|
1056
|
+
return invoke$1('ElectronWebContentsView.backward', id);
|
|
999
1057
|
};
|
|
1000
1058
|
const getDomTree = id => {
|
|
1001
|
-
return invoke('ElectronWebContentsView.getDomTree', id);
|
|
1059
|
+
return invoke$1('ElectronWebContentsView.getDomTree', id);
|
|
1002
1060
|
};
|
|
1003
1061
|
const insertCss = (id, css) => {
|
|
1004
|
-
return invoke('ElectronWebContentsView.insertCss', id, css);
|
|
1062
|
+
return invoke$1('ElectronWebContentsView.insertCss', id, css);
|
|
1005
1063
|
};
|
|
1006
1064
|
const insertJavaScript = (id, code) => {
|
|
1007
|
-
return invoke('ElectronWebContentsView.insertJavaScript', id, code);
|
|
1065
|
+
return invoke$1('ElectronWebContentsView.insertJavaScript', id, code);
|
|
1008
1066
|
};
|
|
1009
1067
|
const cancelNavigation = id => {
|
|
1010
|
-
return invoke('ElectronWebContentsView.cancelNavigation', id);
|
|
1068
|
+
return invoke$1('ElectronWebContentsView.cancelNavigation', id);
|
|
1011
1069
|
};
|
|
1012
1070
|
const inspectElement = (id, x, y) => {
|
|
1013
|
-
return invoke('ElectronWebContentsView.inspectElement', id, x, y);
|
|
1071
|
+
return invoke$1('ElectronWebContentsView.inspectElement', id, x, y);
|
|
1014
1072
|
};
|
|
1015
1073
|
const copyImageAt = (id, x, y) => {
|
|
1016
|
-
return invoke('ElectronWebContentsView.copyImageAt', id, x, y);
|
|
1074
|
+
return invoke$1('ElectronWebContentsView.copyImageAt', id, x, y);
|
|
1017
1075
|
};
|
|
1018
|
-
const setFallthroughKeyBindings = (id, fallthroughKeybindings) => {
|
|
1076
|
+
const setFallthroughKeyBindings = async (id, fallthroughKeybindings) => {
|
|
1019
1077
|
// TODO
|
|
1020
1078
|
// return EmbedsProcess.invoke('ElectronWebContentsView.setFallthroughKeyBindings', id, fallthroughKeybindings)
|
|
1021
1079
|
};
|
|
1022
1080
|
const getStats = (id, fallthroughKeybindings) => {
|
|
1023
|
-
return invoke('ElectronWebContentsView.getStats', id, fallthroughKeybindings);
|
|
1081
|
+
return invoke$1('ElectronWebContentsView.getStats', id, fallthroughKeybindings);
|
|
1024
1082
|
};
|
|
1025
1083
|
const forwardEvent = key => (id, ...args) => {
|
|
1026
|
-
|
|
1084
|
+
return invoke(key, ...args);
|
|
1027
1085
|
};
|
|
1028
1086
|
const handleDidNavigate = forwardEvent('ElectronBrowserView.handleDidNavigate');
|
|
1029
1087
|
const handleTitleUpdated = forwardEvent('ElectronBrowserView.handleTitleUpdated');
|
|
@@ -1031,7 +1089,52 @@ const handleWillNavigate = forwardEvent('ElectronBrowserView.handleWillNavigate'
|
|
|
1031
1089
|
const handleContextMenu = forwardEvent('ElectronBrowserView.handleContextMenu');
|
|
1032
1090
|
|
|
1033
1091
|
const exit = () => {
|
|
1034
|
-
|
|
1092
|
+
globalThis.close();
|
|
1093
|
+
};
|
|
1094
|
+
|
|
1095
|
+
const getPortTuple = () => {
|
|
1096
|
+
const {
|
|
1097
|
+
port1,
|
|
1098
|
+
port2
|
|
1099
|
+
} = new MessageChannel();
|
|
1100
|
+
return {
|
|
1101
|
+
port1,
|
|
1102
|
+
port2
|
|
1103
|
+
};
|
|
1104
|
+
};
|
|
1105
|
+
|
|
1106
|
+
const EmbedsWorker = 208;
|
|
1107
|
+
|
|
1108
|
+
const sendMessagePortToEmbedsProcess = async port => {
|
|
1109
|
+
const outerCommand = 'HandleMessagePortForEmbedsProcess.handleMessagePortForEmbedsProcess';
|
|
1110
|
+
// TODO
|
|
1111
|
+
// @ts-ignore
|
|
1112
|
+
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToSharedProcess', port, outerCommand, EmbedsWorker);
|
|
1113
|
+
};
|
|
1114
|
+
|
|
1115
|
+
const createEmbedsProcessRpc = async () => {
|
|
1116
|
+
try {
|
|
1117
|
+
const {
|
|
1118
|
+
port1,
|
|
1119
|
+
port2
|
|
1120
|
+
} = getPortTuple();
|
|
1121
|
+
await sendMessagePortToEmbedsProcess(port2);
|
|
1122
|
+
port1.start();
|
|
1123
|
+
const rpc = await MessagePortRpcParent.create({
|
|
1124
|
+
commandMap: {},
|
|
1125
|
+
messagePort: port1,
|
|
1126
|
+
isMessagePortOpen: true
|
|
1127
|
+
});
|
|
1128
|
+
// TODO createMessageportRpcParent should call port start
|
|
1129
|
+
return rpc;
|
|
1130
|
+
} catch (error) {
|
|
1131
|
+
throw new VError(error, `Failed to create embeds process rpc`);
|
|
1132
|
+
}
|
|
1133
|
+
};
|
|
1134
|
+
|
|
1135
|
+
const initialize = async () => {
|
|
1136
|
+
const rpc = await createEmbedsProcessRpc();
|
|
1137
|
+
set$1(rpc);
|
|
1035
1138
|
};
|
|
1036
1139
|
|
|
1037
1140
|
const commandMap = {
|
|
@@ -1042,15 +1145,15 @@ const commandMap = {
|
|
|
1042
1145
|
'ElectronWebContentsView.disposeWebContentsView': disposeWebContentsView,
|
|
1043
1146
|
'ElectronWebContentsView.focus': focus,
|
|
1044
1147
|
'ElectronWebContentsView.forward': forward,
|
|
1148
|
+
'ElectronWebContentsView.getDomTree': getDomTree,
|
|
1045
1149
|
'ElectronWebContentsView.getStats': getStats,
|
|
1046
1150
|
'ElectronWebContentsView.handleContextMenu': handleContextMenu,
|
|
1047
1151
|
'ElectronWebContentsView.handleDidNavigate': handleDidNavigate,
|
|
1048
1152
|
'ElectronWebContentsView.handleTitleUpdated': handleTitleUpdated,
|
|
1049
|
-
'ElectronWebContentsView.getDomTree': getDomTree,
|
|
1050
|
-
'ElectronWebContentsView.insertCss': insertCss,
|
|
1051
|
-
'ElectronWebContentsView.insertJavaScript': insertJavaScript,
|
|
1052
1153
|
'ElectronWebContentsView.handleWillNavigate': handleWillNavigate,
|
|
1053
1154
|
'ElectronWebContentsView.hide': hide,
|
|
1155
|
+
'ElectronWebContentsView.insertCss': insertCss,
|
|
1156
|
+
'ElectronWebContentsView.insertJavaScript': insertJavaScript,
|
|
1054
1157
|
'ElectronWebContentsView.inspectElement': inspectElement,
|
|
1055
1158
|
'ElectronWebContentsView.openDevtools': openDevtools,
|
|
1056
1159
|
'ElectronWebContentsView.reload': reload,
|
|
@@ -1058,14 +1161,15 @@ const commandMap = {
|
|
|
1058
1161
|
'ElectronWebContentsView.setFallthroughKeyBindings': setFallthroughKeyBindings,
|
|
1059
1162
|
'ElectronWebContentsView.setIframeSrc': setIframeSrc,
|
|
1060
1163
|
'ElectronWebContentsView.show': show,
|
|
1061
|
-
'Exit.exit': exit
|
|
1164
|
+
'Exit.exit': exit,
|
|
1165
|
+
'Initialize.initialize': initialize
|
|
1062
1166
|
};
|
|
1063
1167
|
|
|
1064
1168
|
const listen = async () => {
|
|
1065
1169
|
const rpc = await WebWorkerRpcClient.create({
|
|
1066
1170
|
commandMap: commandMap
|
|
1067
1171
|
});
|
|
1068
|
-
|
|
1172
|
+
set(rpc);
|
|
1069
1173
|
};
|
|
1070
1174
|
|
|
1071
1175
|
const main = async () => {
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/embeds-worker",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "",
|
|
5
|
-
"
|
|
3
|
+
"version": "4.0.0",
|
|
4
|
+
"description": "Web Worker to manage electron webcontent views in Lvce Editor",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git@github.com:lvce-editor/embeds-worker.git"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"author": "Lvce Editor",
|
|
6
11
|
"type": "module",
|
|
7
|
-
"
|
|
8
|
-
"author": "",
|
|
9
|
-
"license": "MIT"
|
|
12
|
+
"main": "dist/embedsWorkerMain.js"
|
|
10
13
|
}
|