@onekeyfe/extension-bridge-hosted 0.0.1 → 0.0.2
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.
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { IOptionsWithDebugLogger } from '@onekeyfe/cross-inpage-provider-types';
|
|
1
2
|
declare function inject(filename: string): void;
|
|
2
|
-
declare function setupMessagePort(): void;
|
|
3
|
+
declare function setupMessagePort(options?: IOptionsWithDebugLogger): void;
|
|
3
4
|
declare const _default: {
|
|
4
5
|
inject: typeof inject;
|
|
5
6
|
setupMessagePort: typeof setupMessagePort;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { consts, isLegacyExtMessage,
|
|
1
|
+
import { consts, isLegacyExtMessage, fakeDebugLogger, injectedFactory, } from '@onekeyfe/cross-inpage-provider-core';
|
|
2
2
|
import messagePort from '../extensionMessagePort';
|
|
3
3
|
const { EXT_PORT_CS_TO_BG, JS_BRIDGE_MESSAGE_DIRECTION, JS_BRIDGE_MESSAGE_EXT_CHANNEL } = consts;
|
|
4
4
|
// TODO one-time only
|
|
@@ -16,7 +16,8 @@ function inject(filename) {
|
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
18
|
// TODO one-time only
|
|
19
|
-
function setupMessagePort() {
|
|
19
|
+
function setupMessagePort(options = {}) {
|
|
20
|
+
const debugLogger = options.debugLogger || fakeDebugLogger;
|
|
20
21
|
messagePort.connect({
|
|
21
22
|
name: EXT_PORT_CS_TO_BG,
|
|
22
23
|
// #### background -> content-script
|
|
@@ -50,6 +51,8 @@ function setupMessagePort() {
|
|
|
50
51
|
};
|
|
51
52
|
window.addEventListener('message', onWindowPostMessage, false);
|
|
52
53
|
return () => {
|
|
54
|
+
console.error('ONEKEY: lost connection to hosted bridge. You should reload page to establish a new connection.');
|
|
55
|
+
window.dispatchEvent(new Event('onekey_bridge_disconnect'));
|
|
53
56
|
window.removeEventListener('message', onWindowPostMessage, false);
|
|
54
57
|
};
|
|
55
58
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const bridgeSetup: {
|
|
2
2
|
contentScript: {
|
|
3
3
|
inject: (filename: string) => void;
|
|
4
|
-
setupMessagePort: () => void;
|
|
4
|
+
setupMessagePort: (options?: import("@onekeyfe/cross-inpage-provider-types").IOptionsWithDebugLogger) => void;
|
|
5
5
|
};
|
|
6
6
|
ui: {
|
|
7
7
|
createUiJsBridge: (config: import("..").IJsBridgeExtUiConfig) => import("../JsBridgeExtUi").JsBridgeExtUi;
|
|
@@ -21,7 +21,8 @@ function inject(filename) {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
// TODO one-time only
|
|
24
|
-
function setupMessagePort() {
|
|
24
|
+
function setupMessagePort(options = {}) {
|
|
25
|
+
const debugLogger = options.debugLogger || cross_inpage_provider_core_1.fakeDebugLogger;
|
|
25
26
|
extensionMessagePort_1.default.connect({
|
|
26
27
|
name: EXT_PORT_CS_TO_BG,
|
|
27
28
|
// #### background -> content-script
|
|
@@ -48,13 +49,15 @@ function setupMessagePort() {
|
|
|
48
49
|
// only accept extension messages
|
|
49
50
|
if (eventData.channel === JS_BRIDGE_MESSAGE_EXT_CHANNEL &&
|
|
50
51
|
eventData.direction === JS_BRIDGE_MESSAGE_DIRECTION.INPAGE_TO_HOST) {
|
|
51
|
-
|
|
52
|
+
debugLogger.extContentScripts('onWindowPostMessage', event.data);
|
|
52
53
|
// #### content-script -> background
|
|
53
54
|
port.postMessage(eventData.payload);
|
|
54
55
|
}
|
|
55
56
|
};
|
|
56
57
|
window.addEventListener('message', onWindowPostMessage, false);
|
|
57
58
|
return () => {
|
|
59
|
+
console.error('ONEKEY: lost connection to hosted bridge. You should reload page to establish a new connection.');
|
|
60
|
+
window.dispatchEvent(new Event('onekey_bridge_disconnect'));
|
|
58
61
|
window.removeEventListener('message', onWindowPostMessage, false);
|
|
59
62
|
};
|
|
60
63
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/extension-bridge-hosted",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"cross-inpage-provider"
|
|
6
6
|
],
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"start": "tsc --watch"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@onekeyfe/cross-inpage-provider-core": "^0.0.
|
|
32
|
-
"@onekeyfe/cross-inpage-provider-types": "^0.0.
|
|
31
|
+
"@onekeyfe/cross-inpage-provider-core": "^0.0.2",
|
|
32
|
+
"@onekeyfe/cross-inpage-provider-types": "^0.0.2"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "97aa3c911466f5c3a46b005a69d5b3edd1d8fd7c"
|
|
35
35
|
}
|