@jolibox/implement 1.1.35 → 1.1.36-beta.1

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.
@@ -7,3 +7,4 @@ import './task';
7
7
  import './login';
8
8
  import './ads';
9
9
  import './navigate';
10
+ import './runtime';
@@ -0,0 +1 @@
1
+ export {};
@@ -1,9 +1,9 @@
1
1
  Invoking: npm run clean && npm run build:esm && tsc
2
2
 
3
- > @jolibox/implement@1.1.35 clean
3
+ > @jolibox/implement@1.1.36-beta.1 clean
4
4
  > rimraf ./dist
5
5
 
6
6
 
7
- > @jolibox/implement@1.1.35 build:esm
7
+ > @jolibox/implement@1.1.36-beta.1 build:esm
8
8
  > BUILD_VERSION=$(node -p "require('./package.json').version") node esbuild.config.js --format=esm
9
9
 
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@jolibox/implement",
3
3
  "description": "This project is Jolibox JS-SDk implement for Native && H5",
4
- "version": "1.1.35",
4
+ "version": "1.1.36-beta.1",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
7
7
  "license": "MIT",
8
8
  "dependencies": {
9
- "@jolibox/common": "1.1.35",
10
- "@jolibox/types": "1.1.35",
11
- "@jolibox/native-bridge": "1.1.35",
12
- "@jolibox/ads": "1.1.35",
9
+ "@jolibox/common": "1.1.36-beta.1",
10
+ "@jolibox/types": "1.1.36-beta.1",
11
+ "@jolibox/native-bridge": "1.1.36-beta.1",
12
+ "@jolibox/ads": "1.1.36-beta.1",
13
13
  "localforage": "1.10.0",
14
14
  "@jolibox/ui": "1.0.0",
15
15
  "web-vitals": "4.2.4"
@@ -3,3 +3,4 @@ import './lifecycle';
3
3
  import './storage';
4
4
  import './task';
5
5
  import './ads';
6
+ import './runtime';
@@ -0,0 +1,11 @@
1
+ import { createCommands } from '@jolibox/common';
2
+
3
+ const commands = createCommands();
4
+
5
+ commands.registerCommand('RuntimeSDK.loadFinishedEvent', () => {
6
+ console.log('RuntimeSDK.loadFinishedEvent');
7
+ });
8
+
9
+ commands.registerCommand('RuntimeSDK.loadProgressEvent', (progress) => {
10
+ console.log('RuntimeSDK.loadProgressEvent', progress);
11
+ });
@@ -1,7 +1,10 @@
1
- import { hostEmitter } from '@jolibox/common';
1
+ import { hostEmitter, InternalGlobalJSError, UserCustomError } from '@jolibox/common';
2
2
  import { taskTracker, track } from '../report';
3
3
  import { onFCP, onLCP, onTTFB } from 'web-vitals';
4
4
  import { context } from '@/common/context';
5
+ import { httpClientManager } from '../http';
6
+ import { IResponse } from '@jolibox/ads';
7
+ import { reportError } from '@/common/report/errors/report';
5
8
 
6
9
  function trackPerformance() {
7
10
  onFCP((metric) => {
@@ -30,10 +33,8 @@ function trackPerformance() {
30
33
  }
31
34
 
32
35
  function addDomContentLoaded() {
33
- hostEmitter.on('onDocumentReady', (startTime: number) => {
34
- hostEmitter.emit('LifecycleEvent.onReady', {
35
- isLogin: false
36
- });
36
+ hostEmitter.on('onDocumentReady', async (startTime: number) => {
37
+ hostEmitter.emit('LifecycleEvent.onReady', { isLogin: false });
37
38
 
38
39
  if (context.mpType === 'game') {
39
40
  taskTracker.start(Date.now() - startTime);
@@ -7,3 +7,4 @@ import './task';
7
7
  import './login';
8
8
  import './ads';
9
9
  import './navigate';
10
+ import './runtime';
@@ -0,0 +1,48 @@
1
+ import { createCommands } from '@jolibox/common';
2
+ import { t, createSyncAPI } from './base';
3
+ import { emitNative } from '@jolibox/native-bridge';
4
+ import { context } from '@/common/context';
5
+
6
+ const commands = createCommands();
7
+
8
+ const onLoadFinished = createSyncAPI('onLoadFinished', {
9
+ implement: () => {
10
+ emitNative('cpLoadFinishEvent', {}, context.webviewId, true);
11
+ }
12
+ });
13
+
14
+ let lastProgress: number | null = null;
15
+ let scheduled = false;
16
+ let lastEmitTime = 0;
17
+ const THROTTLE_INTERVAL = 200;
18
+
19
+ function notifyProgress(progress: number) {
20
+ emitNative('cpLoadProgressEvent', { progress }, context.webviewId, true);
21
+ }
22
+
23
+ const onLoadProgress = createSyncAPI('onLoadProgress', {
24
+ paramsSchema: t.tuple(t.number()),
25
+ implement: (progress) => {
26
+ lastProgress = progress;
27
+ if (!scheduled) {
28
+ scheduled = true;
29
+ requestAnimationFrame(function frame() {
30
+ const now = Date.now();
31
+ if (now - lastEmitTime >= THROTTLE_INTERVAL) {
32
+ if (lastProgress !== null) {
33
+ notifyProgress(lastProgress);
34
+ lastEmitTime = now;
35
+ lastProgress = null;
36
+ }
37
+ scheduled = false;
38
+ } else {
39
+ requestAnimationFrame(frame);
40
+ }
41
+ });
42
+ }
43
+ }
44
+ });
45
+
46
+ commands.registerCommand('RuntimeSDK.loadFinishedEvent', onLoadFinished);
47
+
48
+ commands.registerCommand('RuntimeSDK.loadProgressEvent', onLoadProgress);