@open-jsbridge/web 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +54 -2
- package/package.json +50 -4
- package/packages/protocol/src/index.d.ts +68 -0
- package/packages/protocol/src/index.js +165 -0
- package/packages/web-mock/src/index.d.ts +31 -0
- package/packages/web-mock/src/index.js +305 -0
- package/packages/web-sdk/src/app.d.ts +5 -0
- package/packages/web-sdk/src/app.js +9 -0
- package/packages/web-sdk/src/auto.d.ts +6 -0
- package/packages/web-sdk/src/auto.js +6 -0
- package/packages/web-sdk/src/bridge.d.ts +35 -0
- package/packages/web-sdk/src/bridge.js +517 -0
- package/packages/web-sdk/src/device.d.ts +8 -0
- package/packages/web-sdk/src/device.js +6 -0
- package/packages/web-sdk/src/errors.d.ts +14 -0
- package/packages/web-sdk/src/errors.js +10 -0
- package/packages/web-sdk/src/events.d.ts +41 -0
- package/packages/web-sdk/src/events.js +226 -0
- package/packages/web-sdk/src/index.d.ts +4 -0
- package/packages/web-sdk/src/index.js +1 -0
- package/packages/web-sdk/src/media-profile.d.ts +4 -0
- package/packages/web-sdk/src/media-profile.js +3 -0
- package/packages/web-sdk/src/media.d.ts +29 -0
- package/packages/web-sdk/src/media.js +76 -0
- package/packages/web-sdk/src/network.d.ts +7 -0
- package/packages/web-sdk/src/network.js +9 -0
- package/packages/web-sdk/src/session.d.ts +21 -0
- package/packages/web-sdk/src/session.js +54 -0
- package/packages/web-sdk/src/singleton.d.ts +1 -0
- package/packages/web-sdk/src/singleton.js +2 -0
- package/packages/web-sdk/src/transport.d.ts +20 -0
- package/packages/web-sdk/src/transport.js +57 -0
- package/packages/web-sdk/src/ui.d.ts +8 -0
- package/packages/web-sdk/src/ui.js +8 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Open JSBridge contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,55 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @open-jsbridge/web
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
面向 Open JSBridge 宿主的 Web SDK。仅支持 ESM,随包提供 TypeScript 类型声明。
|
|
4
|
+
|
|
5
|
+
## 安装 0.2.0 预览版
|
|
6
|
+
|
|
7
|
+
通过 npm 的 `next` 频道安装。也可以从仓库运行 `npm run pack:web`,在应用中安装生成的 tarball。
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @open-jsbridge/web@next
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
[CHANGELOG](https://github.com/Josp3r/open-jsbridge/blob/main/CHANGELOG.md#020) · [从 0.1.x 升级](https://github.com/Josp3r/open-jsbridge/blob/main/docs/migrate-0.2.0.md)
|
|
14
|
+
|
|
15
|
+
## App WebView
|
|
16
|
+
|
|
17
|
+
使用默认单例。第一次调用会等待原生 transport 并自动握手。下面的调用要求宿主启用 `device.getInfo`。
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { bridge } from '@open-jsbridge/web/auto'
|
|
21
|
+
|
|
22
|
+
const device = await bridge.call('device.getInfo')
|
|
23
|
+
console.log(device)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
宿主启用 Toast 后,可以使用同一单例上的类型化入口。
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { ui } from '@open-jsbridge/web/ui'
|
|
30
|
+
|
|
31
|
+
await ui.toast.show({ text: '已保存' })
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## 浏览器本地联调
|
|
35
|
+
|
|
36
|
+
从 `@open-jsbridge/web/mock` 显式安装 Mock transport。应用代码仍使用同一个 SDK 单例。
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { bridge } from '@open-jsbridge/web/auto'
|
|
40
|
+
import { installMockTransport } from '@open-jsbridge/web/mock'
|
|
41
|
+
|
|
42
|
+
const mock = installMockTransport({ events: ['acme.app.configChanged'] })
|
|
43
|
+
const stop = bridge.on<{ theme: string }>('acme.app.configChanged', console.log)
|
|
44
|
+
await stop.ready
|
|
45
|
+
mock?.emit('acme.app.configChanged', { theme: 'dark' })
|
|
46
|
+
stop()
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
[项目仓库和宿主接入方式](https://github.com/Josp3r/open-jsbridge)
|
|
50
|
+
|
|
51
|
+
## 入口
|
|
52
|
+
|
|
53
|
+
从主入口 `@open-jsbridge/web` 导入 `createBridge` 可创建独立的连接,主入口加载时不会创建默认单例。0.1.x 用户可将默认 `bridge` 和能力的导入移到 `@open-jsbridge/web/auto`。
|
|
54
|
+
|
|
55
|
+
可通过 `@open-jsbridge/web/device`、`/network`、`/app`、`/ui` 和 `/media` 单独导入能力。模块和 `/auto` 共用一个连接。应用用 `bridge.has()` 和 `bridge.hasEvent()` 检测当前宿主声明的能力。
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-jsbridge/web",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Web SDK for Open JSBridge hosts",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"types": "./packages/web-sdk/src/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./packages/web-sdk/src/index.d.ts",
|
|
11
|
+
"import": "./packages/web-sdk/src/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./auto": {
|
|
14
|
+
"types": "./packages/web-sdk/src/auto.d.ts",
|
|
15
|
+
"import": "./packages/web-sdk/src/auto.js"
|
|
16
|
+
},
|
|
17
|
+
"./mock": {
|
|
18
|
+
"types": "./packages/web-mock/src/index.d.ts",
|
|
19
|
+
"import": "./packages/web-mock/src/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./app": {
|
|
22
|
+
"types": "./packages/web-sdk/src/app.d.ts",
|
|
23
|
+
"import": "./packages/web-sdk/src/app.js"
|
|
24
|
+
},
|
|
25
|
+
"./device": {
|
|
26
|
+
"types": "./packages/web-sdk/src/device.d.ts",
|
|
27
|
+
"import": "./packages/web-sdk/src/device.js"
|
|
28
|
+
},
|
|
29
|
+
"./network": {
|
|
30
|
+
"types": "./packages/web-sdk/src/network.d.ts",
|
|
31
|
+
"import": "./packages/web-sdk/src/network.js"
|
|
32
|
+
},
|
|
33
|
+
"./ui": {
|
|
34
|
+
"types": "./packages/web-sdk/src/ui.d.ts",
|
|
35
|
+
"import": "./packages/web-sdk/src/ui.js"
|
|
36
|
+
},
|
|
37
|
+
"./media": {
|
|
38
|
+
"types": "./packages/web-sdk/src/media-profile.d.ts",
|
|
39
|
+
"import": "./packages/web-sdk/src/media-profile.js"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"packages/protocol/src",
|
|
44
|
+
"packages/web-mock/src",
|
|
45
|
+
"packages/web-sdk/src"
|
|
46
|
+
],
|
|
47
|
+
"repository": "https://github.com/Josp3r/open-jsbridge",
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
},
|
|
51
|
+
"sideEffects": false
|
|
52
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export type JsonValue = null | boolean | number | string | JsonObject | JsonValue[];
|
|
2
|
+
export interface JsonObject {
|
|
3
|
+
[key: string]: JsonValue;
|
|
4
|
+
}
|
|
5
|
+
interface RpcMethod {
|
|
6
|
+
jsonrpc: '2.0';
|
|
7
|
+
method: string;
|
|
8
|
+
params?: JsonObject;
|
|
9
|
+
}
|
|
10
|
+
export interface RpcRequest extends RpcMethod {
|
|
11
|
+
id: string;
|
|
12
|
+
}
|
|
13
|
+
export interface RpcNotification extends RpcMethod {
|
|
14
|
+
}
|
|
15
|
+
export interface RpcSuccess {
|
|
16
|
+
jsonrpc: '2.0';
|
|
17
|
+
id: string;
|
|
18
|
+
result: JsonValue;
|
|
19
|
+
}
|
|
20
|
+
export interface RpcFailure {
|
|
21
|
+
jsonrpc: '2.0';
|
|
22
|
+
id: string | null;
|
|
23
|
+
error: {
|
|
24
|
+
code: number;
|
|
25
|
+
message: string;
|
|
26
|
+
data?: JsonValue;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface Envelope {
|
|
30
|
+
jsb: '1.0';
|
|
31
|
+
meta?: {
|
|
32
|
+
sid?: string;
|
|
33
|
+
timeout?: number;
|
|
34
|
+
ts?: number;
|
|
35
|
+
traceId?: string;
|
|
36
|
+
[field: string]: JsonValue | undefined;
|
|
37
|
+
};
|
|
38
|
+
rpc: RpcRequest | RpcNotification | RpcSuccess | RpcFailure;
|
|
39
|
+
[field: string]: unknown;
|
|
40
|
+
}
|
|
41
|
+
export declare const ErrorCode: Readonly<{
|
|
42
|
+
readonly ParseError: -32700;
|
|
43
|
+
readonly InvalidRequest: -32600;
|
|
44
|
+
readonly MethodNotFound: -32601;
|
|
45
|
+
readonly InvalidParams: -32602;
|
|
46
|
+
readonly InternalError: -32603;
|
|
47
|
+
readonly Unavailable: -32000;
|
|
48
|
+
readonly Timeout: -32001;
|
|
49
|
+
readonly Cancelled: -32002;
|
|
50
|
+
readonly PermissionDenied: -32003;
|
|
51
|
+
readonly UnsupportedProtocol: -32004;
|
|
52
|
+
readonly NotReady: -32005;
|
|
53
|
+
readonly PayloadTooLarge: -32006;
|
|
54
|
+
readonly UserDenied: -32007;
|
|
55
|
+
readonly RateLimited: -32008;
|
|
56
|
+
readonly SessionExpired: -32009;
|
|
57
|
+
readonly Busy: -32010;
|
|
58
|
+
}>;
|
|
59
|
+
type DecodeErrorCode = typeof ErrorCode.ParseError | typeof ErrorCode.InvalidRequest;
|
|
60
|
+
export declare class WireDecodeError extends Error {
|
|
61
|
+
readonly code: DecodeErrorCode;
|
|
62
|
+
readonly cause?: unknown | undefined;
|
|
63
|
+
constructor(code: DecodeErrorCode, message: string, cause?: unknown | undefined);
|
|
64
|
+
}
|
|
65
|
+
export declare function decodeEnvelope(raw: string): Envelope;
|
|
66
|
+
export declare function snapshotJson(value: unknown): JsonValue;
|
|
67
|
+
export declare function encodeEnvelope(envelope: Envelope): string;
|
|
68
|
+
export {};
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
export const ErrorCode = Object.freeze({
|
|
2
|
+
ParseError: -32700,
|
|
3
|
+
InvalidRequest: -32600,
|
|
4
|
+
MethodNotFound: -32601,
|
|
5
|
+
InvalidParams: -32602,
|
|
6
|
+
InternalError: -32603,
|
|
7
|
+
Unavailable: -32000,
|
|
8
|
+
Timeout: -32001,
|
|
9
|
+
Cancelled: -32002,
|
|
10
|
+
PermissionDenied: -32003,
|
|
11
|
+
UnsupportedProtocol: -32004,
|
|
12
|
+
NotReady: -32005,
|
|
13
|
+
PayloadTooLarge: -32006,
|
|
14
|
+
UserDenied: -32007,
|
|
15
|
+
RateLimited: -32008,
|
|
16
|
+
SessionExpired: -32009,
|
|
17
|
+
Busy: -32010,
|
|
18
|
+
});
|
|
19
|
+
export class WireDecodeError extends Error {
|
|
20
|
+
constructor(code, message, cause) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.code = code;
|
|
23
|
+
this.cause = cause;
|
|
24
|
+
this.name = 'WireDecodeError';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const methodPattern = /^(?!rpc\.)[a-z][a-zA-Z0-9]*(\.[a-z][a-zA-Z0-9]*)+(@[1-9][0-9]*)?$/;
|
|
28
|
+
const notificationOnlyMethodPattern = /^bridge\.(cancel|event|progress)(@[1-9][0-9]*)?$/;
|
|
29
|
+
function isObject(value) {
|
|
30
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
31
|
+
}
|
|
32
|
+
function hasOwn(value, key) {
|
|
33
|
+
return Object.prototype.hasOwnProperty.call(value, key);
|
|
34
|
+
}
|
|
35
|
+
function isId(value) {
|
|
36
|
+
return typeof value === 'string' && value.length <= 256 && /^.{1,128}$/su.test(value);
|
|
37
|
+
}
|
|
38
|
+
function hasOnlyKeys(value, keys) {
|
|
39
|
+
return Object.keys(value).every((key) => keys.includes(key));
|
|
40
|
+
}
|
|
41
|
+
function isNonNegativeInteger(value) {
|
|
42
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
|
|
43
|
+
}
|
|
44
|
+
function isMeta(value) {
|
|
45
|
+
return isObject(value) &&
|
|
46
|
+
(!hasOwn(value, 'sid') || (typeof value.sid === 'string' && value.sid.length > 0)) &&
|
|
47
|
+
(!hasOwn(value, 'timeout') || isNonNegativeInteger(value.timeout)) &&
|
|
48
|
+
(!hasOwn(value, 'ts') || isNonNegativeInteger(value.ts)) &&
|
|
49
|
+
(!hasOwn(value, 'traceId') || typeof value.traceId === 'string');
|
|
50
|
+
}
|
|
51
|
+
function isError(value) {
|
|
52
|
+
return isObject(value) && Number.isSafeInteger(value.code) && typeof value.message === 'string' &&
|
|
53
|
+
hasOnlyKeys(value, ['code', 'message', 'data']);
|
|
54
|
+
}
|
|
55
|
+
function isRpcMessage(value) {
|
|
56
|
+
if (!isObject(value) || value.jsonrpc !== '2.0')
|
|
57
|
+
return false;
|
|
58
|
+
if (hasOwn(value, 'method')) {
|
|
59
|
+
return typeof value.method === 'string' && methodPattern.test(value.method) &&
|
|
60
|
+
(!hasOwn(value, 'params') || isObject(value.params)) &&
|
|
61
|
+
(!hasOwn(value, 'id') || (!notificationOnlyMethodPattern.test(value.method) && isId(value.id))) &&
|
|
62
|
+
hasOnlyKeys(value, ['jsonrpc', 'method', 'params', 'id']);
|
|
63
|
+
}
|
|
64
|
+
if (hasOwn(value, 'error')) {
|
|
65
|
+
return (isId(value.id) || value.id === null) && isError(value.error) &&
|
|
66
|
+
hasOnlyKeys(value, ['jsonrpc', 'id', 'error']);
|
|
67
|
+
}
|
|
68
|
+
return isId(value.id) && hasOwn(value, 'result') &&
|
|
69
|
+
hasOnlyKeys(value, ['jsonrpc', 'id', 'result']);
|
|
70
|
+
}
|
|
71
|
+
function isEnvelope(value) {
|
|
72
|
+
return isObject(value) && value.jsb === '1.0' && isRpcMessage(value.rpc) &&
|
|
73
|
+
(!hasOwn(value, 'meta') || isMeta(value.meta));
|
|
74
|
+
}
|
|
75
|
+
function checkJsonNumber(value) {
|
|
76
|
+
if (typeof value === 'number' &&
|
|
77
|
+
(!Number.isFinite(value) || (Number.isInteger(value) && !Number.isSafeInteger(value)))) {
|
|
78
|
+
throw new WireDecodeError(ErrorCode.InvalidRequest, 'Number is outside the supported JSON range');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function decodeJsonProperty(key, value) {
|
|
82
|
+
checkJsonNumber(value);
|
|
83
|
+
if (key === '__proto__')
|
|
84
|
+
return undefined;
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
87
|
+
export function decodeEnvelope(raw) {
|
|
88
|
+
let value;
|
|
89
|
+
try {
|
|
90
|
+
value = JSON.parse(raw, decodeJsonProperty);
|
|
91
|
+
}
|
|
92
|
+
catch (cause) {
|
|
93
|
+
if (cause instanceof WireDecodeError)
|
|
94
|
+
throw cause;
|
|
95
|
+
throw new WireDecodeError(ErrorCode.ParseError, 'Parse error', cause);
|
|
96
|
+
}
|
|
97
|
+
if (!isEnvelope(value)) {
|
|
98
|
+
throw new WireDecodeError(ErrorCode.InvalidRequest, 'Invalid request');
|
|
99
|
+
}
|
|
100
|
+
return value;
|
|
101
|
+
}
|
|
102
|
+
function jsonProperty(object, key, ancestors) {
|
|
103
|
+
const descriptor = Object.getOwnPropertyDescriptor(object, key);
|
|
104
|
+
if (!descriptor?.enumerable || !hasOwn(descriptor, 'value')) {
|
|
105
|
+
throw new WireDecodeError(ErrorCode.InvalidRequest, 'Expected an enumerable JSON data property');
|
|
106
|
+
}
|
|
107
|
+
return copyJson(descriptor.value, ancestors);
|
|
108
|
+
}
|
|
109
|
+
function copyJson(value, ancestors) {
|
|
110
|
+
if (value === null || typeof value === 'boolean' || typeof value === 'string')
|
|
111
|
+
return value;
|
|
112
|
+
if (typeof value === 'number') {
|
|
113
|
+
checkJsonNumber(value);
|
|
114
|
+
return value;
|
|
115
|
+
}
|
|
116
|
+
if (typeof value !== 'object' || ancestors.has(value)) {
|
|
117
|
+
throw new WireDecodeError(ErrorCode.InvalidRequest, 'Expected an acyclic JSON value');
|
|
118
|
+
}
|
|
119
|
+
ancestors.add(value);
|
|
120
|
+
try {
|
|
121
|
+
const keys = Reflect.ownKeys(value);
|
|
122
|
+
if (Array.isArray(value)) {
|
|
123
|
+
if (keys.length !== value.length + 1 || 'toJSON' in value) {
|
|
124
|
+
throw new WireDecodeError(ErrorCode.InvalidRequest, 'Expected a dense JSON array');
|
|
125
|
+
}
|
|
126
|
+
const result = [];
|
|
127
|
+
for (let index = 0; index < value.length; index++) {
|
|
128
|
+
result.push(jsonProperty(value, String(index), ancestors));
|
|
129
|
+
}
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
const prototype = Object.getPrototypeOf(value);
|
|
133
|
+
if (prototype !== null && prototype !== Object.prototype) {
|
|
134
|
+
throw new WireDecodeError(ErrorCode.InvalidRequest, 'Expected a plain JSON object');
|
|
135
|
+
}
|
|
136
|
+
const result = Object.create(null);
|
|
137
|
+
for (const key of keys) {
|
|
138
|
+
if (typeof key !== 'string') {
|
|
139
|
+
throw new WireDecodeError(ErrorCode.InvalidRequest, 'Expected a string JSON property name');
|
|
140
|
+
}
|
|
141
|
+
result[key] = jsonProperty(value, key, ancestors);
|
|
142
|
+
}
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
145
|
+
finally {
|
|
146
|
+
ancestors.delete(value);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
export function snapshotJson(value) {
|
|
150
|
+
try {
|
|
151
|
+
return copyJson(value, new Set());
|
|
152
|
+
}
|
|
153
|
+
catch (cause) {
|
|
154
|
+
if (cause instanceof WireDecodeError)
|
|
155
|
+
throw cause;
|
|
156
|
+
throw new WireDecodeError(ErrorCode.InvalidRequest, 'Message is not serializable', cause);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
export function encodeEnvelope(envelope) {
|
|
160
|
+
const snapshot = snapshotJson(envelope);
|
|
161
|
+
if (!isEnvelope(snapshot)) {
|
|
162
|
+
throw new WireDecodeError(ErrorCode.InvalidRequest, 'Invalid request');
|
|
163
|
+
}
|
|
164
|
+
return JSON.stringify(snapshot);
|
|
165
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type JsonValue } from '../../protocol/src/index.js';
|
|
2
|
+
declare const networkTypes: readonly ["wifi", "cellular", "ethernet", "other", "none", "unknown"];
|
|
3
|
+
export interface MockAdapterOptions {
|
|
4
|
+
events?: readonly string[];
|
|
5
|
+
/** Advertised events whose subscription requests are denied by the Mock host. */
|
|
6
|
+
deniedEvents?: readonly string[];
|
|
7
|
+
deviceInfo?: {
|
|
8
|
+
os: 'ios' | 'android';
|
|
9
|
+
osVersion: string;
|
|
10
|
+
};
|
|
11
|
+
getNetworkStatus?: () => {
|
|
12
|
+
type: typeof networkTypes[number];
|
|
13
|
+
};
|
|
14
|
+
showToast?: (text: string) => void | Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
/** A standalone Mock session with Promise responses and out-of-band event delivery. */
|
|
17
|
+
export declare function createMockAdapter(options?: MockAdapterOptions): {
|
|
18
|
+
name: string;
|
|
19
|
+
send: (raw: string) => Promise<string | null>;
|
|
20
|
+
emit: (name: string, payload: JsonValue) => boolean;
|
|
21
|
+
listen(onMessage: (raw: string) => void): () => void;
|
|
22
|
+
};
|
|
23
|
+
type FrameDirection = 'request' | 'response' | 'event';
|
|
24
|
+
export interface MockTransportOptions extends MockAdapterOptions {
|
|
25
|
+
onFrame?: (direction: FrameDirection, raw: string | null) => void;
|
|
26
|
+
}
|
|
27
|
+
/** Installs a Mock Host Shim on the current browser window when its transport slot is free. */
|
|
28
|
+
export declare function installMockTransport(options?: MockTransportOptions): {
|
|
29
|
+
emit(name: string, payload: JsonValue): boolean;
|
|
30
|
+
} | undefined;
|
|
31
|
+
export {};
|