@novasamatech/product-sdk 0.5.4-2 → 0.5.4-4
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/sandboxTransport.js +21 -21
- package/package.json +2 -2
package/dist/sandboxTransport.js
CHANGED
|
@@ -24,43 +24,43 @@ function isWebview() {
|
|
|
24
24
|
return false;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
async function* pollWebviewPort(cooldown) {
|
|
28
|
-
while (true) {
|
|
29
|
-
yield window['__HOST_API_PORT__'];
|
|
30
|
-
await delay(cooldown);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
27
|
async function getWebviewPort() {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return port;
|
|
37
|
-
}
|
|
28
|
+
if (window['__HOST_API_PORT__']) {
|
|
29
|
+
return window['__HOST_API_PORT__'];
|
|
38
30
|
}
|
|
39
|
-
|
|
31
|
+
await delay(100);
|
|
32
|
+
return getWebviewPort();
|
|
40
33
|
}
|
|
41
|
-
function
|
|
34
|
+
function isValidIframeMessage(event, sourceEnv, currentEnv) {
|
|
42
35
|
return (event.source !== currentEnv &&
|
|
43
36
|
event.source === sourceEnv &&
|
|
44
37
|
event.data &&
|
|
45
38
|
event.data.constructor.name === 'Uint8Array');
|
|
46
39
|
}
|
|
40
|
+
function isValidWebviewMessage(event) {
|
|
41
|
+
return event.data && event.data.constructor.name === 'Uint8Array';
|
|
42
|
+
}
|
|
47
43
|
function createDefaultSdkProvider() {
|
|
48
44
|
const subscribers = new Set();
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
45
|
+
const handleIframeMessage = (event) => {
|
|
46
|
+
if (!isValidIframeMessage(event, getParentWindow(), window))
|
|
47
|
+
return;
|
|
48
|
+
for (const subscriber of subscribers) {
|
|
49
|
+
subscriber(event.data);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const handleWebviewMessage = (event) => {
|
|
53
|
+
if (!isValidWebviewMessage(event))
|
|
54
54
|
return;
|
|
55
55
|
for (const subscriber of subscribers) {
|
|
56
56
|
subscriber(event.data);
|
|
57
57
|
}
|
|
58
58
|
};
|
|
59
59
|
if (isIframe()) {
|
|
60
|
-
window.addEventListener('message',
|
|
60
|
+
window.addEventListener('message', handleIframeMessage);
|
|
61
61
|
}
|
|
62
62
|
else if (isWebview()) {
|
|
63
|
-
getWebviewPort().then(port => port.addEventListener('message',
|
|
63
|
+
getWebviewPort().then(port => port.addEventListener('message', handleWebviewMessage));
|
|
64
64
|
}
|
|
65
65
|
return {
|
|
66
66
|
logger: createDefaultLogger(),
|
|
@@ -84,10 +84,10 @@ function createDefaultSdkProvider() {
|
|
|
84
84
|
dispose() {
|
|
85
85
|
subscribers.clear();
|
|
86
86
|
if (isIframe()) {
|
|
87
|
-
window.removeEventListener('message',
|
|
87
|
+
window.removeEventListener('message', handleIframeMessage);
|
|
88
88
|
}
|
|
89
89
|
if (isWebview()) {
|
|
90
|
-
getWebviewPort().then(port => port.removeEventListener('message',
|
|
90
|
+
getWebviewPort().then(port => port.removeEventListener('message', handleWebviewMessage));
|
|
91
91
|
}
|
|
92
92
|
},
|
|
93
93
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@novasamatech/product-sdk",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.5.4-
|
|
4
|
+
"version": "0.5.4-4",
|
|
5
5
|
"description": "Polkadot product SDK: integrate and run your product inside Polkadot browser.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@polkadot-api/substrate-bindings": "^0.16.5",
|
|
31
31
|
"@polkadot-api/json-rpc-provider": "^0.0.4",
|
|
32
32
|
"@polkadot-api/json-rpc-provider-proxy": "^0.2.7",
|
|
33
|
-
"@novasamatech/host-api": "0.5.4-
|
|
33
|
+
"@novasamatech/host-api": "0.5.4-4"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|