@zeppos/zeus-cli 1.2.2 → 1.2.3
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/package.json +1 -1
- package/private-modules/zeppos-app-utils/dist/config/device-server.js +113 -0
- package/private-modules/zeppos-app-utils/dist/config/device.js +74 -1
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/_package.json +14 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/empty/app-side/i18n/en-US.po +2 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/empty/app-side/index.js +13 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/empty/app.js +10 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/empty/app.json +59 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/empty/assets/default/icon.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/empty/page/i18n/en-US.po +2 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/empty/page/index.js +7 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/empty/setting/i18n/en-US.po +2 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/empty/setting/index.js +7 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/empty/watchface/index.js +13 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/hello-world/app-side/index.js +11 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/hello-world/app.js +10 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/hello-world/app.json +66 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/hello-world/assets/gtr3/icon.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/hello-world/assets/gtr3/image/logo.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/hello-world/assets/gtr3-pro/icon.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/hello-world/assets/gtr3-pro/image/logo.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/hello-world/assets/gts3/icon.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/hello-world/assets/gts3/image/logo.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/hello-world/page/gtr3/home/index.page.js +18 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/hello-world/page/gtr3/home/index.page.json +1 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/hello-world/page/gtr3/home/index.style.js +15 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/hello-world/page/gtr3-pro/home/index.page.js +18 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/hello-world/page/gtr3-pro/home/index.page.json +1 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/hello-world/page/gtr3-pro/home/index.style.js +15 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/hello-world/page/gts3/home/index.page.js +19 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/hello-world/page/gts3/home/index.page.json +1 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/hello-world/page/gts3/home/index.style.js +15 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/hello-world/page/i18n/en-US.po +3 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/hello-world/setting/i18n/en-US.po +2 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/hello-world/setting/index.js +5 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/hello-world/utils/index.js +3 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/jsconfig.json +14 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/app.js +7 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/app.json +51 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/bg/bg.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/bigNum/0.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/bigNum/1.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/bigNum/2.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/bigNum/3.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/bigNum/4.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/bigNum/5.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/bigNum/6.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/bigNum/7.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/bigNum/8.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/bigNum/9.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/bigNum/sp.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/btn/back.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/btn/lv.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/btn/red.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/point/bg.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/point/bottom.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/point/center.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/point/h.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/point/left.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/point/m.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/point/right.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/point/s.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/preview.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/second/second.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/smallNum/0.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/smallNum/1.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/smallNum/2.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/smallNum/3.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/smallNum/4.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/smallNum/5.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/smallNum/6.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/smallNum/7.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/smallNum/8.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/smallNum/9.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/smallNum/d.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/smallNum/n.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/week_ch/1.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/week_ch/2.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/week_ch/3.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/week_ch/4.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/week_ch/5.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/week_ch/6.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/week_ch/7.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/week_en/1.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/week_en/2.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/week_en/3.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/week_en/4.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/week_en/5.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/week_en/6.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/assets/gtr-3-pro/images/week_en/7.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/shared/buffer.js +11 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/shared/device-polyfill.js +3 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/shared/global.js +17 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/shared/js-module.js +27 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/shared/logger.js +21 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/shared/setTimeout.js +59 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/watchface/gtr-3-pro/index.js +1 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v1/timer/watchface/round/index.js +438 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/_package.json +14 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/app.js +28 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/app.json +51 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gt.s/consume.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gt.s/food/beer.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gt.s/food/cake.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gt.s/food/chocolate.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gt.s/food/coffee.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gt.s/food/cookies.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gt.s/food/ham.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gt.s/food/hamburger.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gt.s/food/ice cream.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gt.s/food/pizza.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gt.s/food/sausage.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gt.s/icon.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gt.s/multiply.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gt.s/selected.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gt.s/unselected.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gts/consume.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gts/food/beer.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gts/food/cake.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gts/food/chocolate.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gts/food/coffee.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gts/food/cookies.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gts/food/ham.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gts/food/hamburger.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gts/food/ice cream.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gts/food/pizza.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gts/food/sausage.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gts/icon.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gts/multiply.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gts/selected.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/assets/gts/unselected.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/page/gt/food-list.js +113 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/page/gt/index.js +126 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/page/gts/food-list.js +113 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/page/gts/index.js +126 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/page/i18n/en-US.po +42 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/page/i18n/zh-CN.po +42 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/utils/constants.js +54 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/utils/storage.js +42 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/utils/styles-gts-3.js +141 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/calories/utils/styles.js +142 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/empty/app-side/i18n/en-US.po +2 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/empty/app-side/index.js +13 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/empty/app.js +10 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/empty/app.json +59 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/empty/assets/default/icon.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/empty/page/i18n/en-US.po +2 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/empty/page/index.js +7 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/empty/setting/i18n/en-US.po +2 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/empty/setting/index.js +7 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/empty/watchface/index.js +13 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/fetch-api/app-side/i18n/en-US.po +2 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/fetch-api/app-side/index.js +72 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/fetch-api/app.js +23 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/fetch-api/app.json +55 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/fetch-api/assets/common/icon.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/fetch-api/assets/common.r/icon.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/fetch-api/assets/common.s/icon.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/fetch-api/page/i18n/en-US.po +2 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/fetch-api/page/index.js +55 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/fetch-api/pages/i18n/en-US.po +2 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/fetch-api/pages/index.js +55 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/fetch-api/shared/data.js +67 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/fetch-api/shared/defer.js +35 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/fetch-api/shared/device-polyfill.js +6 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/fetch-api/shared/es6-promise.js +1149 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/fetch-api/shared/event.js +42 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/fetch-api/shared/message-side.js +1145 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/fetch-api/shared/message.js +1151 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/fetch-api/utils/config/constants.js +2 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/fetch-api/utils/config/device.js +2 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/hello-world/app-side/index.js +11 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/hello-world/app.js +10 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/hello-world/app.json +66 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/hello-world/assets/gt.r/icon.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/hello-world/assets/gt.r/image/logo.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/hello-world/assets/gt.s/icon.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/hello-world/assets/gt.s/image/logo.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/hello-world/assets/gtr/icon.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/hello-world/assets/gtr/image/logo.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/hello-world/assets/gts/icon.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/hello-world/assets/gts/image/logo.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/hello-world/page/gt/home/index.page.js +17 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/hello-world/page/gt/home/index.page.json +1 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/hello-world/page/gt/home/index.page.r.layout.js +28 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/hello-world/page/gt/home/index.page.s.layout.js +28 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/hello-world/page/gt/home/index.style.js +18 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/hello-world/page/gtr/home/index.page.js +20 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/hello-world/page/gtr/home/index.page.json +1 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/hello-world/page/gtr/home/index.style.js +18 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/hello-world/page/gts/home/index.page.js +21 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/hello-world/page/gts/home/index.page.json +1 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/hello-world/page/gts/home/index.style.js +17 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/hello-world/page/i18n/en-US.po +3 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/hello-world/setting/i18n/en-US.po +2 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/hello-world/setting/index.js +5 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/hello-world/utils/index.js +3 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/jsconfig.json +14 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/todo-list/.prettierrc.js +6 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/todo-list/app-side/index.js +48 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/todo-list/app.js +25 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/todo-list/app.json +70 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/todo-list/assets/gt.s/icon.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/todo-list/assets/gts/icon.png +0 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/todo-list/page/home/index.page.js +155 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/todo-list/page/home/index.page.json +1 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/todo-list/page/home/index.style.js +93 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/todo-list/page/i18n/en-US.po +9 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/todo-list/setting/i18n/en-US.po +5 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/todo-list/setting/index.js +145 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/todo-list/shared/data.js +67 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/todo-list/shared/defer.js +35 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/todo-list/shared/device-polyfill.js +6 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/todo-list/shared/es6-promise.js +1149 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/todo-list/shared/event.js +42 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/todo-list/shared/message-side.js +1145 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/todo-list/shared/message.js +1151 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/todo-list/utils/constants.js +3 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/todo-list/utils/fs.js +38 -0
- package/private-modules/zeppos-app-utils/dist/public/template/config-version-v3/v2/todo-list/utils/index.js +38 -0
- package/private-modules/zeppos-app-utils/dist/tools/tools.js +14 -0
|
@@ -0,0 +1,1145 @@
|
|
|
1
|
+
import { EventBus } from './event'
|
|
2
|
+
import { Deferred, timeout } from './defer'
|
|
3
|
+
import { json2buf, buf2json, bin2hex, str2buf, buf2str } from './data'
|
|
4
|
+
|
|
5
|
+
let logger
|
|
6
|
+
|
|
7
|
+
function initLogger() {
|
|
8
|
+
logger = Logger.getLogger('side-message')
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const DEBUG = true
|
|
12
|
+
|
|
13
|
+
export const MESSAGE_SIZE = 3600
|
|
14
|
+
export const MESSAGE_HEADER = 16
|
|
15
|
+
export const MESSAGE_PAYLOAD = MESSAGE_SIZE - MESSAGE_HEADER
|
|
16
|
+
export const HM_MESSAGE_PROTO_HEADER = 66
|
|
17
|
+
export const HM_MESSAGE_PROTO_PAYLOAD = MESSAGE_PAYLOAD - HM_MESSAGE_PROTO_HEADER
|
|
18
|
+
|
|
19
|
+
export const MessageFlag = {
|
|
20
|
+
Runtime: 0x0,
|
|
21
|
+
App: 0x1
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const MessageType = {
|
|
25
|
+
Shake: 0x1,
|
|
26
|
+
Close: 0x2,
|
|
27
|
+
Heart: 0x3,
|
|
28
|
+
Data: 0x4,
|
|
29
|
+
DataWithSystemTool: 0x5,
|
|
30
|
+
Log: 0x6
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const MessageRuntimeType = {
|
|
34
|
+
Invoke: 0x1
|
|
35
|
+
}
|
|
36
|
+
export const MessageVersion = {
|
|
37
|
+
Version1: 0x1
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const MessagePayloadType = {
|
|
41
|
+
Request: 0x1,
|
|
42
|
+
Response: 0x2,
|
|
43
|
+
Notify: 0x3
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const DataType = {
|
|
47
|
+
empty: 'empty',
|
|
48
|
+
json: 'json',
|
|
49
|
+
text: 'text',
|
|
50
|
+
bin: 'bin'
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const MessagePayloadDataTypeOp = {
|
|
54
|
+
EMPTY: 0x0,
|
|
55
|
+
TEXT: 0x1,
|
|
56
|
+
JSON: 0x2,
|
|
57
|
+
BIN: 0x3
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function getDataType(type) {
|
|
61
|
+
switch (type.toLowerCase()) {
|
|
62
|
+
case DataType.json:
|
|
63
|
+
return MessagePayloadDataTypeOp.JSON
|
|
64
|
+
case DataType.text:
|
|
65
|
+
return MessagePayloadDataTypeOp.TEXT
|
|
66
|
+
case DataType.bin:
|
|
67
|
+
return MessagePayloadDataTypeOp.BIN
|
|
68
|
+
case DataType.empty:
|
|
69
|
+
return MessagePayloadDataTypeOp.EMPTY
|
|
70
|
+
default:
|
|
71
|
+
return MessagePayloadDataTypeOp.TEXT
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 中续,结束
|
|
76
|
+
export const MessagePayloadOpCode = {
|
|
77
|
+
Continued: 0x0,
|
|
78
|
+
Finished: 0x1
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let traceId = 10000
|
|
82
|
+
export function genTraceId() {
|
|
83
|
+
return traceId++
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let spanId = 1000
|
|
87
|
+
export function genSpanId() {
|
|
88
|
+
return spanId++
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function getTimestamp(t = Date.now()) {
|
|
92
|
+
return t % 10000000
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
class Session extends EventBus {
|
|
96
|
+
constructor(id, type, ctx) {
|
|
97
|
+
super()
|
|
98
|
+
this.id = id
|
|
99
|
+
this.type = type // payloadType
|
|
100
|
+
this.ctx = ctx
|
|
101
|
+
this.tempBuf = null
|
|
102
|
+
this.chunks = []
|
|
103
|
+
this.count = 0
|
|
104
|
+
this.finishChunk = null
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
addChunk(payload) {
|
|
108
|
+
if (payload.opCode === MessagePayloadOpCode.Finished) {
|
|
109
|
+
this.count = payload.seqId
|
|
110
|
+
this.finishChunk = payload
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (payload.payloadLength !== payload.payload.byteLength) {
|
|
114
|
+
logger.error('receive chunk data length error, expect %d but %d', payload.payloadLength, payload.payload.byteLength)
|
|
115
|
+
this.emit('error', Error(`receive chunk data length error, expect ${payload.payloadLength} but ${payload.payload.byteLength}`))
|
|
116
|
+
return
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
this.chunks.push(payload)
|
|
120
|
+
this.checkIfReceiveAllChunks()
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
checkIfReceiveAllChunks() {
|
|
124
|
+
if (this.count !== this.chunks.length) return
|
|
125
|
+
|
|
126
|
+
for (let i = 1; i <= this.count; i++) {
|
|
127
|
+
const chunk = this.chunks.find((c) => c.seqId === i)
|
|
128
|
+
|
|
129
|
+
if (!chunk) {
|
|
130
|
+
this.releaseBuf()
|
|
131
|
+
this.emit('error', Error('receive data error'))
|
|
132
|
+
return
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const buf = chunk.payload
|
|
136
|
+
this.tempBuf = this.tempBuf ? Buffer.concat([this.tempBuf, buf]) : buf
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (!this.finishChunk) return
|
|
140
|
+
|
|
141
|
+
this.finishChunk.payload = this.tempBuf
|
|
142
|
+
this.finishChunk.payloadLength = this.finishChunk.payload.byteLength
|
|
143
|
+
|
|
144
|
+
if (this.finishChunk.totalLength !== this.finishChunk.payloadLength) {
|
|
145
|
+
logger.error('receive full data length error, expect %d but %d', this.finishChunk.payloadLength, this.finishChunk.payload.byteLength)
|
|
146
|
+
this.emit('error', Error(`receive full data length error, expect ${this.finishChunk.payloadLength} but ${this.finishChunk.payload.byteLength}`))
|
|
147
|
+
return
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
this.emit('data', this.finishChunk)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
getLength() {
|
|
154
|
+
return this.tempBufLength
|
|
155
|
+
}
|
|
156
|
+
releaseBuf() {
|
|
157
|
+
this.tempBuf = null
|
|
158
|
+
this.chunks = []
|
|
159
|
+
this.finishChunk = null
|
|
160
|
+
this.count = 0
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
class SessionMgr {
|
|
165
|
+
constructor() {
|
|
166
|
+
this.sessions = new Map()
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
key(session) {
|
|
170
|
+
return `${session.id}:${session.type}`
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
newSession(id, type, ctx) {
|
|
174
|
+
const newSession = new Session(id, type, ctx)
|
|
175
|
+
this.sessions.set(this.key(newSession), newSession)
|
|
176
|
+
return newSession
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
destroy(session) {
|
|
180
|
+
session.releaseBuf()
|
|
181
|
+
this.sessions.delete(this.key(session))
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
has(id, type) {
|
|
185
|
+
return this.sessions.has(
|
|
186
|
+
this.key({
|
|
187
|
+
id,
|
|
188
|
+
type
|
|
189
|
+
})
|
|
190
|
+
)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
getById(id, type) {
|
|
194
|
+
return this.sessions.get(
|
|
195
|
+
this.key({
|
|
196
|
+
id,
|
|
197
|
+
type
|
|
198
|
+
})
|
|
199
|
+
)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
clear() {
|
|
203
|
+
this.sessions.clear()
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export class MessageBuilder extends EventBus {
|
|
208
|
+
constructor(
|
|
209
|
+
{ appId = 0, appDevicePort = 20, appSidePort = 0, ble = undefined } = {
|
|
210
|
+
appId: 0,
|
|
211
|
+
appDevicePort: 20,
|
|
212
|
+
appSidePort: 0,
|
|
213
|
+
ble: undefined
|
|
214
|
+
}
|
|
215
|
+
) {
|
|
216
|
+
super()
|
|
217
|
+
initLogger()
|
|
218
|
+
this.isDevice = typeof __ZEPPOS__ !== 'undefined'
|
|
219
|
+
this.isSide = !this.isDevice
|
|
220
|
+
|
|
221
|
+
this.appId = appId
|
|
222
|
+
this.appDevicePort = appDevicePort
|
|
223
|
+
this.appSidePort = appSidePort
|
|
224
|
+
this.ble = ble
|
|
225
|
+
this.sendMsg = this.getSafeSend()
|
|
226
|
+
this.chunkSize = MESSAGE_PAYLOAD
|
|
227
|
+
this.tempBuf = null
|
|
228
|
+
this.shakeTask = Deferred()
|
|
229
|
+
this.waitingShakePromise = this.shakeTask.promise
|
|
230
|
+
this.sessionMgr = new SessionMgr()
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
getMessageSize() {
|
|
234
|
+
return MESSAGE_SIZE
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
getMessagePayloadSize() {
|
|
238
|
+
return MESSAGE_PAYLOAD
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
getMessageHeaderSize() {
|
|
242
|
+
return MESSAGE_HEADER
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
buf2Json(buf) {
|
|
246
|
+
return buf2json(buf)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
json2Buf(json) {
|
|
250
|
+
return json2buf(json)
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
now(t = Date.now()) {
|
|
254
|
+
return getTimestamp(t)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
connect(cb) {
|
|
258
|
+
this.on('message', (message) => {
|
|
259
|
+
this.onMessage(message)
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
this.ble &&
|
|
263
|
+
this.ble.createConnect((index, data, size) => {
|
|
264
|
+
DEBUG && logger.warn('[RAW] [R] receive index=>%d size=>%d bin=>%s', index, size, bin2hex(data))
|
|
265
|
+
this.onFragmentData(data)
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
this.sendShake()
|
|
269
|
+
cb && cb(this)
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
disConnect(cb) {
|
|
273
|
+
logger.debug('app ble disconnect')
|
|
274
|
+
this.sendClose()
|
|
275
|
+
this.off('message')
|
|
276
|
+
this.ble && this.ble.disConnect()
|
|
277
|
+
|
|
278
|
+
cb && cb(this)
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
listen(cb) {
|
|
282
|
+
if (typeof messaging === 'undefined') {
|
|
283
|
+
return
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
messaging &&
|
|
287
|
+
messaging.peerSocket.addListener('message', (message) => {
|
|
288
|
+
DEBUG && logger.warn('[RAW] [R] receive size=>%d bin=>%s', message.byteLength, bin2hex(message))
|
|
289
|
+
this.onMessage(message)
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
this.waitingShakePromise = Promise.resolve()
|
|
293
|
+
cb && cb(this)
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
buildBin(data) {
|
|
297
|
+
if (data.payload.byteLength > this.chunkSize) {
|
|
298
|
+
throw new Error(`${data.payload.byteLength} greater than max size of ${this.chunkSize}`)
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const size = this.getMessageHeaderSize() + data.payload.byteLength
|
|
302
|
+
let buf = Buffer.alloc(size)
|
|
303
|
+
let offset = 0
|
|
304
|
+
|
|
305
|
+
buf.writeUInt8(data.flag, offset)
|
|
306
|
+
offset += 1
|
|
307
|
+
|
|
308
|
+
buf.writeUInt8(data.version, offset)
|
|
309
|
+
offset += 1
|
|
310
|
+
|
|
311
|
+
buf.writeUInt16LE(data.type, offset)
|
|
312
|
+
offset += 2
|
|
313
|
+
|
|
314
|
+
buf.writeUInt16LE(data.port1, offset)
|
|
315
|
+
offset += 2
|
|
316
|
+
|
|
317
|
+
buf.writeUInt16LE(data.port2, offset)
|
|
318
|
+
offset += 2
|
|
319
|
+
|
|
320
|
+
buf.writeUInt32LE(data.appId, offset)
|
|
321
|
+
offset += 4
|
|
322
|
+
|
|
323
|
+
buf.writeUInt32LE(data.extra, offset)
|
|
324
|
+
offset += 4
|
|
325
|
+
|
|
326
|
+
buf.fill(data.payload, offset, data.payload.byteLength + offset)
|
|
327
|
+
|
|
328
|
+
return buf
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
buildShake() {
|
|
332
|
+
return this.buildBin({
|
|
333
|
+
flag: MessageFlag.App,
|
|
334
|
+
version: MessageVersion.Version1,
|
|
335
|
+
type: MessageType.Shake,
|
|
336
|
+
port1: this.appDevicePort,
|
|
337
|
+
port2: this.appSidePort,
|
|
338
|
+
appId: this.appId,
|
|
339
|
+
extra: 0,
|
|
340
|
+
payload: Buffer.from([this.appId])
|
|
341
|
+
})
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
sendShake() {
|
|
345
|
+
if (this.appSidePort === 0) {
|
|
346
|
+
const shake = this.buildShake()
|
|
347
|
+
this.sendMsg(shake)
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
buildClose() {
|
|
352
|
+
return this.buildBin({
|
|
353
|
+
flag: MessageFlag.App,
|
|
354
|
+
version: MessageVersion.Version1,
|
|
355
|
+
type: MessageType.Close,
|
|
356
|
+
port1: this.appDevicePort,
|
|
357
|
+
port2: this.appSidePort,
|
|
358
|
+
appId: this.appId,
|
|
359
|
+
extra: 0,
|
|
360
|
+
payload: Buffer.from([this.appId])
|
|
361
|
+
})
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
sendClose() {
|
|
365
|
+
if (this.appSidePort !== 0) {
|
|
366
|
+
const close = this.buildClose()
|
|
367
|
+
|
|
368
|
+
this.sendMsg(close)
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
readBin(arrayBuf) {
|
|
373
|
+
const buf = Buffer.from(arrayBuf)
|
|
374
|
+
let offset = 0
|
|
375
|
+
|
|
376
|
+
const flag = buf.readUInt8(offset)
|
|
377
|
+
offset += 1
|
|
378
|
+
|
|
379
|
+
const version = buf.readUInt8(offset)
|
|
380
|
+
offset += 1
|
|
381
|
+
|
|
382
|
+
const type = buf.readUInt16LE(offset)
|
|
383
|
+
offset += 2
|
|
384
|
+
|
|
385
|
+
const port1 = buf.readUInt16LE(offset)
|
|
386
|
+
offset += 2
|
|
387
|
+
|
|
388
|
+
const port2 = buf.readUInt16LE(offset)
|
|
389
|
+
offset += 2
|
|
390
|
+
|
|
391
|
+
const appId = buf.readUInt32LE(offset)
|
|
392
|
+
offset += 4
|
|
393
|
+
|
|
394
|
+
const extra = buf.readUInt32LE(offset)
|
|
395
|
+
offset += 4
|
|
396
|
+
|
|
397
|
+
const payload = buf.subarray(offset)
|
|
398
|
+
|
|
399
|
+
return {
|
|
400
|
+
flag,
|
|
401
|
+
version,
|
|
402
|
+
type,
|
|
403
|
+
port1,
|
|
404
|
+
port2,
|
|
405
|
+
appId,
|
|
406
|
+
extra,
|
|
407
|
+
payload
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// opts 覆盖头部选项
|
|
412
|
+
buildData(payload, opts = {}) {
|
|
413
|
+
return this.buildBin({
|
|
414
|
+
flag: MessageFlag.App,
|
|
415
|
+
version: MessageVersion.Version1,
|
|
416
|
+
type: MessageType.Data,
|
|
417
|
+
port1: this.appDevicePort,
|
|
418
|
+
port2: this.appSidePort,
|
|
419
|
+
appId: this.appId,
|
|
420
|
+
extra: 0,
|
|
421
|
+
...opts,
|
|
422
|
+
payload
|
|
423
|
+
})
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
sendBin(buf, debug = DEBUG) {
|
|
427
|
+
// ble 发送消息
|
|
428
|
+
debug && logger.warn('[RAW] [S] send size=%d bin=%s', buf.byteLength, bin2hex(buf.buffer))
|
|
429
|
+
const result = this.ble.send(buf.buffer, buf.byteLength)
|
|
430
|
+
|
|
431
|
+
if (!result) {
|
|
432
|
+
throw Error('send message error')
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
sendBinBySide(buf, debug = DEBUG) {
|
|
437
|
+
// side 发送消息
|
|
438
|
+
debug && logger.warn('[RAW] [S] send size=%d bin=%s', buf.byteLength, bin2hex(buf.buffer))
|
|
439
|
+
messaging && messaging.peerSocket.send(buf.buffer)
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// 通用获取逻辑
|
|
443
|
+
getSafeSend() {
|
|
444
|
+
if (this.isDevice) {
|
|
445
|
+
return this.sendBin.bind(this)
|
|
446
|
+
} else {
|
|
447
|
+
return this.sendBinBySide.bind(this)
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
_logSend(buf) {
|
|
452
|
+
this.sendMsg(buf, false)
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// 大数据的复杂头部分包协议
|
|
456
|
+
sendHmProtocol({ requestId, dataBin, type, contentType, dataType }, { messageType = MessageType.Data } = {}) {
|
|
457
|
+
const headerSize = 0
|
|
458
|
+
const hmDataSize = HM_MESSAGE_PROTO_PAYLOAD
|
|
459
|
+
const userDataLength = dataBin.byteLength
|
|
460
|
+
|
|
461
|
+
let offset = 0
|
|
462
|
+
const _buf = Buffer.alloc(hmDataSize)
|
|
463
|
+
const traceId = requestId ? requestId : genTraceId()
|
|
464
|
+
const spanId = genSpanId()
|
|
465
|
+
let seqId = 1
|
|
466
|
+
|
|
467
|
+
const count = Math.ceil(userDataLength / hmDataSize)
|
|
468
|
+
|
|
469
|
+
function genSeqId() {
|
|
470
|
+
return seqId++
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
for (let i = 1; i <= count; i++) {
|
|
474
|
+
this.errorIfBleDisconnect()
|
|
475
|
+
if (i === count) {
|
|
476
|
+
// last
|
|
477
|
+
const tailSize = userDataLength - offset
|
|
478
|
+
const tailBuf = Buffer.alloc(headerSize + tailSize)
|
|
479
|
+
|
|
480
|
+
dataBin.copy(tailBuf, headerSize, offset, offset + tailSize)
|
|
481
|
+
offset += tailSize
|
|
482
|
+
this.sendDataWithSession(
|
|
483
|
+
{
|
|
484
|
+
traceId,
|
|
485
|
+
spanId: spanId,
|
|
486
|
+
seqId: genSeqId(),
|
|
487
|
+
payload: tailBuf,
|
|
488
|
+
type,
|
|
489
|
+
opCode: MessagePayloadOpCode.Finished,
|
|
490
|
+
totalLength: userDataLength,
|
|
491
|
+
contentType,
|
|
492
|
+
dataType
|
|
493
|
+
},
|
|
494
|
+
{
|
|
495
|
+
messageType
|
|
496
|
+
}
|
|
497
|
+
)
|
|
498
|
+
|
|
499
|
+
break
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
dataBin.copy(_buf, headerSize, offset, offset + hmDataSize)
|
|
503
|
+
offset += hmDataSize
|
|
504
|
+
|
|
505
|
+
this.sendDataWithSession(
|
|
506
|
+
{
|
|
507
|
+
traceId,
|
|
508
|
+
spanId: spanId,
|
|
509
|
+
seqId: genSeqId(),
|
|
510
|
+
payload: _buf,
|
|
511
|
+
type,
|
|
512
|
+
opCode: MessagePayloadOpCode.Continued,
|
|
513
|
+
totalLength: userDataLength,
|
|
514
|
+
contentType,
|
|
515
|
+
dataType
|
|
516
|
+
},
|
|
517
|
+
{
|
|
518
|
+
messageType
|
|
519
|
+
}
|
|
520
|
+
)
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
if (offset === userDataLength) {
|
|
524
|
+
DEBUG && logger.debug('HmProtocol send ok msgSize=> %d dataSize=> %d', offset, userDataLength)
|
|
525
|
+
} else {
|
|
526
|
+
DEBUG && logger.error('HmProtocol send error msgSize=> %d dataSize=> %d', offset, userDataLength)
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
// 大数据的简单分包协议
|
|
531
|
+
sendSimpleProtocol({ dataBin }, { messageType = MessageType.Data } = {}) {
|
|
532
|
+
const dataSize = this.chunkSize
|
|
533
|
+
const headerSize = 0
|
|
534
|
+
const userDataLength = dataBin.byteLength
|
|
535
|
+
|
|
536
|
+
let offset = 0
|
|
537
|
+
const _buf = Buffer.alloc(dataSize)
|
|
538
|
+
|
|
539
|
+
const count = Math.ceil(userDataLength / dataSize)
|
|
540
|
+
|
|
541
|
+
for (let i = 1; i <= count; i++) {
|
|
542
|
+
if (i === count) {
|
|
543
|
+
// last
|
|
544
|
+
const tailSize = userDataLength - offset
|
|
545
|
+
const tailBuf = Buffer.alloc(headerSize + tailSize)
|
|
546
|
+
|
|
547
|
+
dataBin.copy(tailBuf, headerSize, offset, offset + tailSize)
|
|
548
|
+
offset += tailSize
|
|
549
|
+
this.sendSimpleData(
|
|
550
|
+
{
|
|
551
|
+
payload: tailBuf
|
|
552
|
+
},
|
|
553
|
+
{
|
|
554
|
+
messageType
|
|
555
|
+
}
|
|
556
|
+
)
|
|
557
|
+
|
|
558
|
+
break
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
dataBin.copy(_buf, headerSize, offset, offset + dataSize)
|
|
562
|
+
offset += dataSize
|
|
563
|
+
|
|
564
|
+
this.sendSimpleData(
|
|
565
|
+
{
|
|
566
|
+
payload: _buf
|
|
567
|
+
},
|
|
568
|
+
{
|
|
569
|
+
messageType
|
|
570
|
+
}
|
|
571
|
+
)
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
if (offset === userDataLength) {
|
|
575
|
+
// logger.debug('SimpleProtocol send ok msgSize=> %d dataSize=> %d', offset, userDataLength)
|
|
576
|
+
} else {
|
|
577
|
+
// logger.error('SimpleProtocol send error msgSize=> %d dataSize=> %d', offset, userDataLength)
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
sendJson({ requestId = 0, json, type = MessagePayloadType.Request, contentType, dataType }) {
|
|
582
|
+
const packageBin = json2buf(json)
|
|
583
|
+
const traceId = requestId ? requestId : genTraceId()
|
|
584
|
+
|
|
585
|
+
this.sendHmProtocol({
|
|
586
|
+
requestId: traceId,
|
|
587
|
+
dataBin: packageBin,
|
|
588
|
+
type,
|
|
589
|
+
contentType,
|
|
590
|
+
dataType
|
|
591
|
+
})
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
sendBuf({ requestId = 0, buf, type = MessagePayloadType.Request, contentType, dataType }) {
|
|
595
|
+
const traceId = requestId ? requestId : genTraceId()
|
|
596
|
+
|
|
597
|
+
return this.sendHmProtocol({
|
|
598
|
+
requestId: traceId,
|
|
599
|
+
dataBin: buf,
|
|
600
|
+
type,
|
|
601
|
+
contentType,
|
|
602
|
+
dataType
|
|
603
|
+
})
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
sendLog(str) {
|
|
607
|
+
const packageBuf = str2buf(str)
|
|
608
|
+
this.sendSimpleProtocol(
|
|
609
|
+
{
|
|
610
|
+
dataBin: packageBuf
|
|
611
|
+
},
|
|
612
|
+
{
|
|
613
|
+
messageType: MessageType.Log
|
|
614
|
+
}
|
|
615
|
+
)
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
sendDataWithSession({ traceId, spanId, seqId, payload, type, opCode, totalLength, contentType, dataType }, { messageType }) {
|
|
619
|
+
const payloadBin = this.buildPayload({
|
|
620
|
+
traceId,
|
|
621
|
+
spanId,
|
|
622
|
+
seqId,
|
|
623
|
+
totalLength,
|
|
624
|
+
type,
|
|
625
|
+
opCode,
|
|
626
|
+
payload,
|
|
627
|
+
contentType,
|
|
628
|
+
dataType
|
|
629
|
+
})
|
|
630
|
+
|
|
631
|
+
let data = this.isDevice
|
|
632
|
+
? this.buildData(payloadBin, {
|
|
633
|
+
type: messageType
|
|
634
|
+
})
|
|
635
|
+
: payloadBin
|
|
636
|
+
|
|
637
|
+
this.sendMsg(data)
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
sendSimpleData({ payload }, { messageType }) {
|
|
641
|
+
let data = this.isDevice
|
|
642
|
+
? this.buildData(payload, {
|
|
643
|
+
type: messageType
|
|
644
|
+
})
|
|
645
|
+
: payload
|
|
646
|
+
|
|
647
|
+
this._logSend(data)
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
buildPayload(data) {
|
|
651
|
+
const size = HM_MESSAGE_PROTO_HEADER + data.payload.byteLength
|
|
652
|
+
let buf = Buffer.alloc(size)
|
|
653
|
+
let offset = 0
|
|
654
|
+
|
|
655
|
+
// header
|
|
656
|
+
// traceId
|
|
657
|
+
buf.writeUInt32LE(data.traceId, offset)
|
|
658
|
+
offset += 4
|
|
659
|
+
|
|
660
|
+
// parentId
|
|
661
|
+
buf.writeUInt32LE(0, offset)
|
|
662
|
+
offset += 4
|
|
663
|
+
|
|
664
|
+
// spanId
|
|
665
|
+
buf.writeUInt32LE(data.spanId, offset)
|
|
666
|
+
offset += 4
|
|
667
|
+
|
|
668
|
+
// seqId // 顺序 id,消息部分顺序序列号
|
|
669
|
+
buf.writeUInt32LE(data.seqId, offset)
|
|
670
|
+
offset += 4
|
|
671
|
+
|
|
672
|
+
// message total length
|
|
673
|
+
buf.writeUInt32LE(data.totalLength, offset)
|
|
674
|
+
offset += 4
|
|
675
|
+
|
|
676
|
+
// payload length 当前
|
|
677
|
+
buf.writeUInt32LE(data.payload.byteLength, offset)
|
|
678
|
+
offset += 4
|
|
679
|
+
|
|
680
|
+
// payload type
|
|
681
|
+
buf.writeUInt8(data.type, offset)
|
|
682
|
+
offset += 1
|
|
683
|
+
|
|
684
|
+
// opCode
|
|
685
|
+
buf.writeUInt8(data.opCode, offset)
|
|
686
|
+
offset += 1
|
|
687
|
+
|
|
688
|
+
// timestamp1
|
|
689
|
+
buf.writeUInt32LE(this.now(), offset)
|
|
690
|
+
offset += 4
|
|
691
|
+
|
|
692
|
+
// timestamp2
|
|
693
|
+
buf.writeUInt32LE(0, offset)
|
|
694
|
+
offset += 4
|
|
695
|
+
|
|
696
|
+
// timestamp3
|
|
697
|
+
buf.writeUInt32LE(0, offset)
|
|
698
|
+
offset += 4
|
|
699
|
+
|
|
700
|
+
// timestamp4
|
|
701
|
+
buf.writeUInt32LE(0, offset)
|
|
702
|
+
offset += 4
|
|
703
|
+
|
|
704
|
+
// timestamp5
|
|
705
|
+
buf.writeUInt32LE(0, offset)
|
|
706
|
+
offset += 4
|
|
707
|
+
|
|
708
|
+
// timestamp6
|
|
709
|
+
buf.writeUInt32LE(0, offset)
|
|
710
|
+
offset += 4
|
|
711
|
+
|
|
712
|
+
// timestamp7
|
|
713
|
+
buf.writeUInt32LE(0, offset)
|
|
714
|
+
offset += 4
|
|
715
|
+
|
|
716
|
+
// request content data type
|
|
717
|
+
buf.writeUInt8(data.contentType, offset)
|
|
718
|
+
offset += 1
|
|
719
|
+
|
|
720
|
+
// response data type
|
|
721
|
+
buf.writeUInt8(data.dataType, offset)
|
|
722
|
+
offset += 1
|
|
723
|
+
|
|
724
|
+
buf.writeUInt16LE(0, offset)
|
|
725
|
+
offset += 2
|
|
726
|
+
|
|
727
|
+
// extra1
|
|
728
|
+
buf.writeUInt32LE(0, offset)
|
|
729
|
+
offset += 4
|
|
730
|
+
|
|
731
|
+
// extra2
|
|
732
|
+
buf.writeUInt32LE(0, offset)
|
|
733
|
+
offset += 4
|
|
734
|
+
|
|
735
|
+
// payload
|
|
736
|
+
buf.fill(data.payload, offset, data.payload.byteLength + offset)
|
|
737
|
+
|
|
738
|
+
return buf
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
readPayload(arrayBuf) {
|
|
742
|
+
const buf = Buffer.from(arrayBuf)
|
|
743
|
+
let offset = 0
|
|
744
|
+
|
|
745
|
+
const traceId = buf.readUInt32LE(offset)
|
|
746
|
+
offset += 4
|
|
747
|
+
|
|
748
|
+
const parentId = buf.readUInt32LE(offset)
|
|
749
|
+
offset += 4
|
|
750
|
+
|
|
751
|
+
const spanId = buf.readUInt32LE(offset)
|
|
752
|
+
offset += 4
|
|
753
|
+
|
|
754
|
+
const seqId = buf.readUInt32LE(offset)
|
|
755
|
+
offset += 4
|
|
756
|
+
|
|
757
|
+
const totalLength = buf.readUInt32LE(offset)
|
|
758
|
+
offset += 4
|
|
759
|
+
|
|
760
|
+
const payloadLength = buf.readUInt32LE(offset)
|
|
761
|
+
offset += 4
|
|
762
|
+
|
|
763
|
+
const payloadType = buf.readUInt8(offset)
|
|
764
|
+
offset += 1
|
|
765
|
+
|
|
766
|
+
const opCode = buf.readUInt8(offset)
|
|
767
|
+
offset += 1
|
|
768
|
+
|
|
769
|
+
const timestamp1 = buf.readUInt32LE(offset)
|
|
770
|
+
offset += 4
|
|
771
|
+
|
|
772
|
+
const timestamp2 = buf.readUInt32LE(offset)
|
|
773
|
+
offset += 4
|
|
774
|
+
|
|
775
|
+
const timestamp3 = buf.readUInt32LE(offset)
|
|
776
|
+
offset += 4
|
|
777
|
+
|
|
778
|
+
const timestamp4 = buf.readUInt32LE(offset)
|
|
779
|
+
offset += 4
|
|
780
|
+
|
|
781
|
+
const timestamp5 = buf.readUInt32LE(offset)
|
|
782
|
+
offset += 4
|
|
783
|
+
|
|
784
|
+
const timestamp6 = buf.readUInt32LE(offset)
|
|
785
|
+
offset += 4
|
|
786
|
+
|
|
787
|
+
const timestamp7 = buf.readUInt32LE(offset)
|
|
788
|
+
offset += 4
|
|
789
|
+
|
|
790
|
+
// request data type
|
|
791
|
+
const contentType = buf.readUInt8(offset)
|
|
792
|
+
offset += 1
|
|
793
|
+
|
|
794
|
+
// response data type
|
|
795
|
+
const dataType = buf.readUInt8(offset)
|
|
796
|
+
offset += 1
|
|
797
|
+
|
|
798
|
+
const extra1 = buf.readUInt16LE(offset)
|
|
799
|
+
offset += 2
|
|
800
|
+
|
|
801
|
+
const extra2 = buf.readUInt32LE(offset)
|
|
802
|
+
offset += 4
|
|
803
|
+
|
|
804
|
+
const extra3 = buf.readUInt32LE(offset)
|
|
805
|
+
offset += 4
|
|
806
|
+
|
|
807
|
+
const payload = buf.subarray(offset)
|
|
808
|
+
|
|
809
|
+
return {
|
|
810
|
+
traceId,
|
|
811
|
+
parentId,
|
|
812
|
+
spanId,
|
|
813
|
+
seqId,
|
|
814
|
+
totalLength,
|
|
815
|
+
payloadLength,
|
|
816
|
+
payloadType,
|
|
817
|
+
opCode,
|
|
818
|
+
contentType,
|
|
819
|
+
dataType,
|
|
820
|
+
timestamp1,
|
|
821
|
+
timestamp2,
|
|
822
|
+
timestamp3,
|
|
823
|
+
timestamp4,
|
|
824
|
+
timestamp5,
|
|
825
|
+
timestamp6,
|
|
826
|
+
timestamp7,
|
|
827
|
+
extra1,
|
|
828
|
+
extra2,
|
|
829
|
+
extra3,
|
|
830
|
+
payload
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
onFragmentData(bin) {
|
|
835
|
+
const data = this.readBin(bin)
|
|
836
|
+
this.emit('raw', bin)
|
|
837
|
+
|
|
838
|
+
DEBUG && logger.debug('receive data=>', JSON.stringify(data))
|
|
839
|
+
if (data.flag === MessageFlag.App && data.type === MessageType.Shake) {
|
|
840
|
+
this.appSidePort = data.port2
|
|
841
|
+
logger.debug('appSidePort=>', data.port2)
|
|
842
|
+
this.shakeTask.resolve()
|
|
843
|
+
} else if (data.flag === MessageFlag.App && data.type === MessageType.Data && data.port2 === this.appSidePort) {
|
|
844
|
+
this.emit('message', data.payload)
|
|
845
|
+
this.emit('read', data)
|
|
846
|
+
} else if (data.flag === MessageFlag.App && data.type === MessageType.DataWithSystemTool && data.port2 === this.appSidePort) {
|
|
847
|
+
this.emit('message', data.payload)
|
|
848
|
+
this.emit('read', data)
|
|
849
|
+
} else if (data.flag === MessageFlag.App && data.type === MessageType.Log && data.port2 === this.appSidePort) {
|
|
850
|
+
this.emit('log', data.payload)
|
|
851
|
+
} else {
|
|
852
|
+
logger.error('error appSidePort=>%d data=>%j', this.appSidePort, data)
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
errorIfBleDisconnect() { }
|
|
857
|
+
|
|
858
|
+
onMessage(messagePayload) {
|
|
859
|
+
const payload = this.readPayload(messagePayload)
|
|
860
|
+
let session = this.sessionMgr.getById(payload.traceId, payload.payloadType)
|
|
861
|
+
|
|
862
|
+
if (!session) {
|
|
863
|
+
session = this.sessionMgr.newSession(payload.traceId, payload.payloadType, this)
|
|
864
|
+
|
|
865
|
+
// TODO: 需要考虑缓冲,监听回调要放到启动之前,或者没有增加监听就缓存请求
|
|
866
|
+
session.on('data', (fullPayload) => {
|
|
867
|
+
if (fullPayload.opCode === MessagePayloadOpCode.Finished) {
|
|
868
|
+
if (fullPayload.payloadType === MessagePayloadType.Request) {
|
|
869
|
+
this.emit('request', {
|
|
870
|
+
request: fullPayload,
|
|
871
|
+
response: ({ data }) => {
|
|
872
|
+
this.response({
|
|
873
|
+
requestId: fullPayload.traceId,
|
|
874
|
+
contentType: fullPayload.contentType,
|
|
875
|
+
dataType: fullPayload.dataType,
|
|
876
|
+
data
|
|
877
|
+
})
|
|
878
|
+
}
|
|
879
|
+
})
|
|
880
|
+
} else if (fullPayload.payloadType === MessagePayloadType.Response) {
|
|
881
|
+
this.emit('response', fullPayload)
|
|
882
|
+
} else if (fullPayload.payloadType === MessagePayloadType.Notify) {
|
|
883
|
+
this.emit('call', fullPayload)
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
this.emit('data', fullPayload)
|
|
887
|
+
this.sessionMgr.destroy(session)
|
|
888
|
+
}
|
|
889
|
+
})
|
|
890
|
+
|
|
891
|
+
session.on('error', (error) => {
|
|
892
|
+
this.sessionMgr.destroy(session)
|
|
893
|
+
this.emit('error', error)
|
|
894
|
+
})
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
session.addChunk(payload)
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
/**
|
|
901
|
+
* 发送请求
|
|
902
|
+
* @param {object buffer arraybuffer arraybuffer like} data 传输的数据
|
|
903
|
+
* @param {*} opts
|
|
904
|
+
* @returns
|
|
905
|
+
*/
|
|
906
|
+
request(data, opts) {
|
|
907
|
+
const _request = () => {
|
|
908
|
+
const defaultOpts = {
|
|
909
|
+
timeout: 60000,
|
|
910
|
+
contentType: 'json',
|
|
911
|
+
dataType: 'json'
|
|
912
|
+
}
|
|
913
|
+
const requestId = genTraceId()
|
|
914
|
+
const defer = Deferred()
|
|
915
|
+
opts = Object.assign(defaultOpts, opts)
|
|
916
|
+
|
|
917
|
+
const error = (error) => {
|
|
918
|
+
this.off('error', error)
|
|
919
|
+
defer.reject(error)
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
const transact = ({ traceId, payload, dataType }) => {
|
|
923
|
+
this.errorIfBleDisconnect()
|
|
924
|
+
DEBUG && logger.debug('traceId=>%d payload=>%s', traceId, payload.toString('hex'))
|
|
925
|
+
if (traceId === requestId) {
|
|
926
|
+
let result
|
|
927
|
+
switch (dataType) {
|
|
928
|
+
case MessagePayloadDataTypeOp.TEXT:
|
|
929
|
+
result = buf2str(payload)
|
|
930
|
+
break
|
|
931
|
+
case MessagePayloadDataTypeOp.BIN:
|
|
932
|
+
result = payload
|
|
933
|
+
break
|
|
934
|
+
case MessagePayloadDataTypeOp.JSON:
|
|
935
|
+
result = buf2json(payload)
|
|
936
|
+
break
|
|
937
|
+
default: // text
|
|
938
|
+
result = buf2str(payload)
|
|
939
|
+
break
|
|
940
|
+
}
|
|
941
|
+
DEBUG && logger.debug('request id=>%d payload=>%j', requestId, data)
|
|
942
|
+
DEBUG && logger.debug('response id=>%d payload=>%j', requestId, result)
|
|
943
|
+
|
|
944
|
+
this.off('response', transact)
|
|
945
|
+
this.off('error', error)
|
|
946
|
+
defer.resolve(result)
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
this.on('response', transact)
|
|
951
|
+
this.on('error', error)
|
|
952
|
+
if (Buffer.isBuffer(data)) {
|
|
953
|
+
this.sendBuf({
|
|
954
|
+
requestId,
|
|
955
|
+
buf: data,
|
|
956
|
+
type: MessagePayloadType.Request,
|
|
957
|
+
contentType: MessagePayloadDataTypeOp.BIN,
|
|
958
|
+
dataType: getDataType(opts.dataType)
|
|
959
|
+
})
|
|
960
|
+
} else if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {
|
|
961
|
+
this.sendBuf({
|
|
962
|
+
requestId,
|
|
963
|
+
buf: Buffer.from(data),
|
|
964
|
+
type: MessagePayloadType.Request,
|
|
965
|
+
contentType: MessagePayloadDataTypeOp.BIN,
|
|
966
|
+
dataType: getDataType(opts.dataType)
|
|
967
|
+
})
|
|
968
|
+
} else {
|
|
969
|
+
this.sendJson({
|
|
970
|
+
requestId,
|
|
971
|
+
json: data,
|
|
972
|
+
type: MessagePayloadType.Request,
|
|
973
|
+
contentType: MessagePayloadDataTypeOp.JSON,
|
|
974
|
+
dataType: getDataType(opts.dataType)
|
|
975
|
+
})
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
let hasReturned = false
|
|
979
|
+
|
|
980
|
+
return Promise.race([
|
|
981
|
+
timeout(opts.timeout, (resolve, reject) => {
|
|
982
|
+
if (hasReturned) {
|
|
983
|
+
return resolve()
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
DEBUG && logger.error(`request timeout in ${opts.timeout}ms error=> %d data=> %j`, requestId, data)
|
|
987
|
+
this.off('response', transact)
|
|
988
|
+
|
|
989
|
+
reject(Error(`Timed out in ${opts.timeout}ms.`))
|
|
990
|
+
}),
|
|
991
|
+
defer.promise.finally(() => {
|
|
992
|
+
hasReturned = true
|
|
993
|
+
})
|
|
994
|
+
])
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
return this.waitingShakePromise.then(_request)
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
requestCb(data, opts, cb) {
|
|
1001
|
+
const _requestCb = () => {
|
|
1002
|
+
const defaultOpts = {
|
|
1003
|
+
timeout: 60000,
|
|
1004
|
+
contentType: 'json',
|
|
1005
|
+
dataType: 'json'
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
if (typeof opts === 'function') {
|
|
1009
|
+
cb = opts
|
|
1010
|
+
opts = defaultOpts
|
|
1011
|
+
} else {
|
|
1012
|
+
opts = Object.assign(defaultOpts, opts)
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
const requestId = genTraceId()
|
|
1016
|
+
let timer1 = null
|
|
1017
|
+
let hasReturned = false
|
|
1018
|
+
|
|
1019
|
+
const transact = ({ traceId, payload, dataType }) => {
|
|
1020
|
+
DEBUG && logger.debug('traceId=>%d payload=>%s', traceId, payload.toString('hex'))
|
|
1021
|
+
if (traceId === requestId) {
|
|
1022
|
+
let result
|
|
1023
|
+
switch (dataType) {
|
|
1024
|
+
case MessagePayloadDataTypeOp.TEXT:
|
|
1025
|
+
result = buf2str(payload)
|
|
1026
|
+
break
|
|
1027
|
+
case MessagePayloadDataTypeOp.BIN:
|
|
1028
|
+
result = payload
|
|
1029
|
+
break
|
|
1030
|
+
case MessagePayloadDataTypeOp.JSON:
|
|
1031
|
+
result = buf2json(payload)
|
|
1032
|
+
break
|
|
1033
|
+
default: // text
|
|
1034
|
+
result = buf2str(payload)
|
|
1035
|
+
break
|
|
1036
|
+
}
|
|
1037
|
+
DEBUG && logger.debug('request id=>%d payload=>%j', requestId, data)
|
|
1038
|
+
DEBUG && logger.debug('response id=>%d payload=>%j', requestId, result)
|
|
1039
|
+
|
|
1040
|
+
timer1 && clearTimeout(timer1)
|
|
1041
|
+
timer1 = null
|
|
1042
|
+
this.off('response', transact)
|
|
1043
|
+
hasReturned = true
|
|
1044
|
+
cb(null, result)
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
this.on('response', transact)
|
|
1049
|
+
if (Buffer.isBuffer(data)) {
|
|
1050
|
+
this.sendBuf({
|
|
1051
|
+
requestId,
|
|
1052
|
+
buf: data,
|
|
1053
|
+
type: MessagePayloadType.Request,
|
|
1054
|
+
contentType: MessagePayloadDataTypeOp.BIN,
|
|
1055
|
+
dataType: getDataType(opts.dataType)
|
|
1056
|
+
})
|
|
1057
|
+
} else if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {
|
|
1058
|
+
this.sendBuf({
|
|
1059
|
+
requestId,
|
|
1060
|
+
buf: Buffer.from(data),
|
|
1061
|
+
type: MessagePayloadType.Request,
|
|
1062
|
+
contentType: MessagePayloadDataTypeOp.BIN,
|
|
1063
|
+
dataType: getDataType(opts.dataType)
|
|
1064
|
+
})
|
|
1065
|
+
} else {
|
|
1066
|
+
this.sendJson({
|
|
1067
|
+
requestId,
|
|
1068
|
+
json: data,
|
|
1069
|
+
type: MessagePayloadType.Request,
|
|
1070
|
+
contentType: MessagePayloadDataTypeOp.JSON,
|
|
1071
|
+
dataType: getDataType(opts.dataType)
|
|
1072
|
+
})
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
timer1 = setTimeout(() => {
|
|
1076
|
+
timer1 = null
|
|
1077
|
+
if (hasReturned) {
|
|
1078
|
+
return
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
DEBUG && logger.error(`request time out in ${opts.timeout}ms error=>%d data=>%j`, requestId, data)
|
|
1082
|
+
this.off('response', transact)
|
|
1083
|
+
cb(Error(`Timed out in ${opts.timeout}ms.`))
|
|
1084
|
+
}, opts.timeout)
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
return this.waitingShakePromise.then(_requestCb)
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
/**
|
|
1091
|
+
* 相应接口给当前请求
|
|
1092
|
+
* @param {obj} param0
|
|
1093
|
+
*/
|
|
1094
|
+
response({ requestId, contentType, dataType, data }) {
|
|
1095
|
+
if (MessagePayloadDataTypeOp.BIN === dataType) {
|
|
1096
|
+
this.sendBuf({
|
|
1097
|
+
requestId,
|
|
1098
|
+
buf: data,
|
|
1099
|
+
type: MessagePayloadType.Response,
|
|
1100
|
+
contentType,
|
|
1101
|
+
dataType
|
|
1102
|
+
})
|
|
1103
|
+
} else {
|
|
1104
|
+
this.sendJson({
|
|
1105
|
+
requestId,
|
|
1106
|
+
json: data,
|
|
1107
|
+
type: MessagePayloadType.Response,
|
|
1108
|
+
contentType,
|
|
1109
|
+
dataType
|
|
1110
|
+
})
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
/**
|
|
1115
|
+
* call 模式调用接口到伴生服务
|
|
1116
|
+
* @param {json | buffer} data
|
|
1117
|
+
* @returns
|
|
1118
|
+
*/
|
|
1119
|
+
call(data) {
|
|
1120
|
+
return this.waitingShakePromise.then(() => {
|
|
1121
|
+
if (Buffer.isBuffer(data)) {
|
|
1122
|
+
return this.sendBuf({
|
|
1123
|
+
buf: data,
|
|
1124
|
+
type: MessagePayloadType.Notify,
|
|
1125
|
+
contentType: MessagePayloadDataTypeOp.BIN,
|
|
1126
|
+
dataType: MessagePayloadDataTypeOp.EMPTY
|
|
1127
|
+
})
|
|
1128
|
+
} else if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {
|
|
1129
|
+
return this.sendBuf({
|
|
1130
|
+
buf: Buffer.from(data),
|
|
1131
|
+
type: MessagePayloadType.Notify,
|
|
1132
|
+
contentType: MessagePayloadDataTypeOp.BIN,
|
|
1133
|
+
dataType: MessagePayloadDataTypeOp.EMPTY
|
|
1134
|
+
})
|
|
1135
|
+
} else {
|
|
1136
|
+
return this.sendJson({
|
|
1137
|
+
json: data,
|
|
1138
|
+
type: MessagePayloadType.Notify,
|
|
1139
|
+
contentType: MessagePayloadDataTypeOp.JSON,
|
|
1140
|
+
dataType: MessagePayloadDataTypeOp.EMPTY
|
|
1141
|
+
})
|
|
1142
|
+
}
|
|
1143
|
+
})
|
|
1144
|
+
}
|
|
1145
|
+
}
|