jubo-sdk 1.1.4 → 1.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/dist/JuboSdk.d.ts CHANGED
@@ -8,6 +8,10 @@ declare class JuboSdk {
8
8
  readonly isApp: boolean;
9
9
  /** 是否是小程序 */
10
10
  readonly isMiniProgram: boolean;
11
+ /** 是否是h5 */
12
+ readonly isH5: boolean;
13
+ /** 是否是H5内嵌 */
14
+ readonly isIframe: boolean;
11
15
  /** 是否是ios */
12
16
  readonly isIos: boolean;
13
17
  /** 是否可以显示自定义导航栏 */
@@ -8,6 +8,10 @@ declare class OldJuboSdk {
8
8
  readonly isApp: boolean;
9
9
  /** 是否是小程序 */
10
10
  readonly isMiniProgram: boolean;
11
+ /** 是否是h5 */
12
+ readonly isH5: boolean;
13
+ /** 是否是H5内嵌 */
14
+ readonly isIframe: boolean;
11
15
  /** 是否是ios */
12
16
  readonly isIos: boolean;
13
17
  /** 是否可以显示自定义导航栏 */
@@ -0,0 +1,52 @@
1
+ interface ChannelClientOptions {
2
+ clientWindow: Window;
3
+ parentWindow: Window;
4
+ origin: string;
5
+ /**
6
+ * 超时时间
7
+ * @default 3000
8
+ */
9
+ failedTime?: number;
10
+ }
11
+ type Callback = {
12
+ success: (response: any) => void;
13
+ failed: (error: any) => void;
14
+ };
15
+ type MessageEventData = {
16
+ requestId: string;
17
+ type: 'response' | 'register';
18
+ isSuccess: boolean;
19
+ handlerName: string;
20
+ body: any;
21
+ };
22
+ declare class ChannelClient {
23
+ constructor(options: ChannelClientOptions);
24
+ clientWindow: Window;
25
+ parentWindow: Window;
26
+ origin: string;
27
+ /**
28
+ * 超时时间
29
+ * @default 3000
30
+ */
31
+ failedTime: number;
32
+ requestCache: Map<string, Callback>;
33
+ /**
34
+ * 接受回调处理
35
+ * @param ev
36
+ * @returns
37
+ */
38
+ receiveResponse(ev: MessageEvent<MessageEventData>): void;
39
+ /**
40
+ * 发送事件
41
+ * @param handlerName 事件名
42
+ * @param body 参数
43
+ * @returns Promise
44
+ */
45
+ call(handlerName: string, body?: any): Promise<unknown>;
46
+ /**
47
+ * 超时处理
48
+ * @param requestId
49
+ */
50
+ timeoutFailed(requestId: string): void;
51
+ }
52
+ export default ChannelClient;
@@ -0,0 +1,19 @@
1
+ type OnRequest = (request: any) => any;
2
+ declare class ChannelParent {
3
+ constructor();
4
+ requestHandlerMap: Map<string, OnRequest>;
5
+ receiveRequest(ev: MessageEvent): void;
6
+ /**
7
+ * 接受事件处理
8
+ * @param ev
9
+ * @returns
10
+ */
11
+ handleRequest(request: any): any;
12
+ /**
13
+ * 注册异步事件
14
+ * @param handlerName 事件名
15
+ * @param callback 事件执行函数
16
+ */
17
+ register(handlerName: string, callback: any): void;
18
+ }
19
+ export default ChannelParent;
@@ -0,0 +1,3 @@
1
+ import ChannelClient from './ChannelClient';
2
+ import ChannelParent from './ChannelParent';
3
+ export { ChannelClient, ChannelParent };