@lvce-editor/iframe-worker 5.26.0 → 5.28.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/iframeWorkerMain.js +92 -9
- package/package.json +1 -1
package/dist/iframeWorkerMain.js
CHANGED
|
@@ -489,7 +489,7 @@ const set$2 = (id, fn) => {
|
|
|
489
489
|
const get$2 = id => {
|
|
490
490
|
return callbacks[id];
|
|
491
491
|
};
|
|
492
|
-
const remove = id => {
|
|
492
|
+
const remove$1 = id => {
|
|
493
493
|
delete callbacks[id];
|
|
494
494
|
};
|
|
495
495
|
let id = 0;
|
|
@@ -666,7 +666,7 @@ const resolve = (id, response) => {
|
|
|
666
666
|
return;
|
|
667
667
|
}
|
|
668
668
|
fn(response);
|
|
669
|
-
remove(id);
|
|
669
|
+
remove$1(id);
|
|
670
670
|
};
|
|
671
671
|
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
672
672
|
const getErrorType = prettyError => {
|
|
@@ -1467,6 +1467,23 @@ const createWebViewConnection = async (uid, origin) => {
|
|
|
1467
1467
|
return rpc;
|
|
1468
1468
|
};
|
|
1469
1469
|
|
|
1470
|
+
const getPortQuadruple = () => {
|
|
1471
|
+
const {
|
|
1472
|
+
port1,
|
|
1473
|
+
port2
|
|
1474
|
+
} = new MessageChannel();
|
|
1475
|
+
const {
|
|
1476
|
+
port1: port3,
|
|
1477
|
+
port2: port4
|
|
1478
|
+
} = new MessageChannel();
|
|
1479
|
+
return {
|
|
1480
|
+
port1,
|
|
1481
|
+
port2,
|
|
1482
|
+
port3,
|
|
1483
|
+
port4
|
|
1484
|
+
};
|
|
1485
|
+
};
|
|
1486
|
+
|
|
1470
1487
|
const readFile = uri => {
|
|
1471
1488
|
return invoke('FileSystem.readFile', uri);
|
|
1472
1489
|
};
|
|
@@ -1487,7 +1504,7 @@ const set = (id, rpc) => {
|
|
|
1487
1504
|
const get = id => {
|
|
1488
1505
|
return rpcs[id];
|
|
1489
1506
|
};
|
|
1490
|
-
const getAll = () => {
|
|
1507
|
+
const getAll$1 = () => {
|
|
1491
1508
|
return rpcs;
|
|
1492
1509
|
};
|
|
1493
1510
|
|
|
@@ -1577,6 +1594,47 @@ const getWebViewWorkerRpc2 = async rpcInfo => {
|
|
|
1577
1594
|
// through the iframe worker. However that could introduce some overhead / latency
|
|
1578
1595
|
// compared to direct connections
|
|
1579
1596
|
|
|
1597
|
+
const interceptors = Object.create(null);
|
|
1598
|
+
|
|
1599
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
1600
|
+
const add = (id, port) => {
|
|
1601
|
+
interceptors[id] = port;
|
|
1602
|
+
};
|
|
1603
|
+
const remove = id => {
|
|
1604
|
+
delete interceptors[id];
|
|
1605
|
+
};
|
|
1606
|
+
const getAll = () => {
|
|
1607
|
+
return Object.values(interceptors);
|
|
1608
|
+
};
|
|
1609
|
+
const isEmpty = () => {
|
|
1610
|
+
return Object.keys(interceptors).length === 0;
|
|
1611
|
+
};
|
|
1612
|
+
|
|
1613
|
+
const notifyInterceptors = message => {
|
|
1614
|
+
if (isEmpty()) {
|
|
1615
|
+
return;
|
|
1616
|
+
}
|
|
1617
|
+
const ports = getAll();
|
|
1618
|
+
// TODO use rpc.invoke
|
|
1619
|
+
for (const port of ports) {
|
|
1620
|
+
port.postMessage({
|
|
1621
|
+
jsonrpc: '2.0',
|
|
1622
|
+
method: 'handleMessageCalled',
|
|
1623
|
+
params: [message]
|
|
1624
|
+
});
|
|
1625
|
+
}
|
|
1626
|
+
};
|
|
1627
|
+
|
|
1628
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
1629
|
+
const proxyPorts = (port1, port2) => {
|
|
1630
|
+
port1.addEventListener('message', event => {
|
|
1631
|
+
port2.postMessage(event.data);
|
|
1632
|
+
});
|
|
1633
|
+
port2.addEventListener('message', event => {
|
|
1634
|
+
port1.postMessage(event.data);
|
|
1635
|
+
});
|
|
1636
|
+
};
|
|
1637
|
+
|
|
1580
1638
|
const createWebWorkerRpc2 = async (rpcInfo, webView, savedState, uri, portId, webViewUid, origin) => {
|
|
1581
1639
|
const rpc = await getWebViewWorkerRpc2(rpcInfo);
|
|
1582
1640
|
const webViewInfo = {
|
|
@@ -1592,10 +1650,25 @@ const createWebWorkerRpc2 = async (rpcInfo, webView, savedState, uri, portId, we
|
|
|
1592
1650
|
await createWebViewConnection(webViewUid, origin);
|
|
1593
1651
|
const {
|
|
1594
1652
|
port1,
|
|
1595
|
-
port2
|
|
1596
|
-
|
|
1653
|
+
port2,
|
|
1654
|
+
port3,
|
|
1655
|
+
port4
|
|
1656
|
+
} = getPortQuadruple();
|
|
1597
1657
|
await createSecondaryWebViewConnection(webViewUid, origin, port1);
|
|
1598
|
-
|
|
1658
|
+
|
|
1659
|
+
// TODO remove message listeners on dispose
|
|
1660
|
+
port2.addEventListener('message', event => {
|
|
1661
|
+
notifyInterceptors(event.data);
|
|
1662
|
+
});
|
|
1663
|
+
port3.addEventListener('message', event => {
|
|
1664
|
+
notifyInterceptors(event.data);
|
|
1665
|
+
});
|
|
1666
|
+
proxyPorts(port2, port3);
|
|
1667
|
+
port1.start();
|
|
1668
|
+
port2.start();
|
|
1669
|
+
port3.start();
|
|
1670
|
+
port4.start();
|
|
1671
|
+
await rpc.invokeAndTransfer('_WebView.setPort', portId, port4);
|
|
1599
1672
|
await rpc.invoke('_WebView.create', {
|
|
1600
1673
|
id: portId,
|
|
1601
1674
|
savedState,
|
|
@@ -1779,7 +1852,7 @@ const getSecret = async key => {
|
|
|
1779
1852
|
};
|
|
1780
1853
|
|
|
1781
1854
|
const getWebViewInfo = webViewId => {
|
|
1782
|
-
const rpcs = getAll();
|
|
1855
|
+
const rpcs = getAll$1();
|
|
1783
1856
|
for (const value of Object.values(rpcs)) {
|
|
1784
1857
|
if (value.webViewId === webViewId) {
|
|
1785
1858
|
return {
|
|
@@ -1792,7 +1865,7 @@ const getWebViewInfo = webViewId => {
|
|
|
1792
1865
|
};
|
|
1793
1866
|
|
|
1794
1867
|
const saveState = async () => {
|
|
1795
|
-
const all = getAll();
|
|
1868
|
+
const all = getAll$1();
|
|
1796
1869
|
const serialized = [];
|
|
1797
1870
|
for (const value of Object.values(all)) {
|
|
1798
1871
|
try {
|
|
@@ -1810,12 +1883,22 @@ const saveState = async () => {
|
|
|
1810
1883
|
return serialized;
|
|
1811
1884
|
};
|
|
1812
1885
|
|
|
1886
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
1887
|
+
const registerInterceptor = async (id, port) => {
|
|
1888
|
+
add(id, port);
|
|
1889
|
+
};
|
|
1890
|
+
const unregisterInterceptor = async id => {
|
|
1891
|
+
remove(id);
|
|
1892
|
+
};
|
|
1893
|
+
|
|
1813
1894
|
const commandMap = {
|
|
1814
1895
|
'WebView.create2': create2,
|
|
1815
1896
|
'WebView.create3': create3,
|
|
1816
1897
|
'WebView.saveState': saveState,
|
|
1817
1898
|
'WebView.getSecret': getSecret,
|
|
1818
|
-
'WebView.getWebViewInfo': getWebViewInfo
|
|
1899
|
+
'WebView.getWebViewInfo': getWebViewInfo,
|
|
1900
|
+
'WebView.registerInterceptor': registerInterceptor,
|
|
1901
|
+
'WebView.unregisterInterceptor': unregisterInterceptor
|
|
1819
1902
|
};
|
|
1820
1903
|
|
|
1821
1904
|
const listen = async () => {
|