@dobot-plus/template 1.2.6 → 1.2.8

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.
Files changed (64) hide show
  1. package/.dobot/components/DobotPlusApp.tsx +78 -78
  2. package/.dobot/http/axios.ts +52 -52
  3. package/.dobot/http/http.ts +22 -22
  4. package/.dobot/index.ts +2 -2
  5. package/.dobot/protocol/methodsHandler.ts +15 -15
  6. package/.dobot/protocol/postMessageHandler.ts +289 -289
  7. package/.dobot/shim.d.ts +3 -3
  8. package/.dobot/store/actions/toolActions.ts +69 -69
  9. package/.dobot/store/reducers/index.ts +8 -8
  10. package/.dobot/store/reducers/toolReducer.ts +152 -152
  11. package/.dobot/store/types.ts +240 -240
  12. package/.dobot/template/default.tsx.mustache +19 -19
  13. package/.dobot/template/entry.css +25 -25
  14. package/.dobot/template/entry.tsx +53 -53
  15. package/.dobot/template/index.html +23 -23
  16. package/.dobot/template/index.scss +5 -5
  17. package/.dobot/utils/i18n.ts +31 -31
  18. package/.dobot/utils/mqtt.ts +61 -61
  19. package/.dobot/utils/rem.js +21 -21
  20. package/.dobot/utils/tool.ts +15 -15
  21. package/.eslintrc.cjs +18 -18
  22. package/.luarc.json +8 -8
  23. package/.vscode/Api.schema.json +103 -103
  24. package/.vscode/Blocks.schema.json +94 -94
  25. package/.vscode/Main.schema.json +42 -42
  26. package/.vscode/Script.schema.json +22 -22
  27. package/.vscode/Toolbar.schema.json +19 -19
  28. package/.vscode/extensions.json +8 -8
  29. package/.vscode/settings.json +51 -51
  30. package/Resources/i18n/client/de.json +11 -11
  31. package/Resources/i18n/client/en.json +11 -11
  32. package/Resources/i18n/client/es.json +11 -11
  33. package/Resources/i18n/client/hk.json +11 -11
  34. package/Resources/i18n/client/ja.json +11 -11
  35. package/Resources/i18n/client/ko.json +11 -11
  36. package/Resources/i18n/client/ru.json +11 -11
  37. package/Resources/i18n/client/zh.json +11 -11
  38. package/Resources/i18n/plugin/de.json +3 -3
  39. package/Resources/i18n/plugin/en.json +3 -3
  40. package/Resources/i18n/plugin/es.json +3 -3
  41. package/Resources/i18n/plugin/hk.json +3 -3
  42. package/Resources/i18n/plugin/ja.json +3 -3
  43. package/Resources/i18n/plugin/ko.json +3 -3
  44. package/Resources/i18n/plugin/ru.json +3 -3
  45. package/Resources/i18n/plugin/zh.json +3 -3
  46. package/configs/Blocks.json +21 -21
  47. package/configs/Main.json +5 -5
  48. package/configs/Scripts.json +7 -7
  49. package/configs/Toolbar.json +5 -5
  50. package/dpt.json +4 -4
  51. package/lua/control.lua +18 -18
  52. package/lua/daemon.lua +22 -22
  53. package/lua/httpAPI.lua +66 -66
  54. package/lua/userAPI.lua +51 -51
  55. package/lua/utils/mqtt.lua +16 -16
  56. package/lua/utils/num_convert.lua +41 -41
  57. package/lua/utils/tcp.lua +30 -30
  58. package/lua/utils/util.lua +30 -30
  59. package/package.json +58 -48
  60. package/project.json +3 -3
  61. package/tsconfig.json +26 -26
  62. package/ui/Blocks.tsx +5 -5
  63. package/ui/Main.tsx +31 -31
  64. package/ui/Toolbar.tsx +5 -5
@@ -1,78 +1,78 @@
1
- import { ReactNode, useEffect } from 'react'
2
- import { MqttWebSocketClient } from '../utils/mqtt'
3
- import dptConfig from '../../dpt.json'
4
- import MainConfig from '../../configs/Main.json'
5
- import { getPluginPort } from '@dobot/http/axios'
6
- import '@dobot/protocol/methodsHandler'
7
- import { toolActions } from '@dobot/store/actions/toolActions'
8
- import store from '@dobot/store'
9
- import { useSelector } from 'react-redux'
10
- import { IStoreState } from '@dobot/store/types'
11
-
12
- type BasicProps = {
13
- children: ReactNode
14
- }
15
-
16
- export type DobotPlusAppProps =
17
- | (BasicProps & {
18
- useMqtt: true
19
- topic?: string
20
- onMessage: (data: any) => void
21
- port?: number
22
- })
23
- | (BasicProps & {
24
- useMqtt?: false
25
- })
26
-
27
- export function DobotPlusApp(props: DobotPlusAppProps) {
28
- const { children, useMqtt } = props
29
- const { portData } = useSelector((state: IStoreState) => state.toolReducer)
30
- useEffect(() => {
31
- const pluginName = MainConfig.name
32
- const pluginVersion = MainConfig.version
33
-
34
- if (useMqtt) {
35
- const { topic, onMessage, port } = props
36
-
37
- const ip = process.env.NODE_ENV === 'production' ? portData.ip : dptConfig.ip
38
-
39
- if (ip && onMessage) {
40
- const serverUrl = `ws://${ip}:${port || 8083}/mqtt`
41
- const clientId = `${pluginName}_clientId`
42
- const mqttClient = new MqttWebSocketClient(serverUrl, clientId)
43
- mqttClient.connect()
44
- mqttClient.subscribe(topic || `${pluginName}Status`, (topic, buf) => {
45
- let data = {}
46
- try {
47
- data = JSON.parse(buf.toString())
48
- } catch {
49
- data = buf.toString()
50
- }
51
- onMessage(data)
52
- })
53
- }
54
- }
55
-
56
- getPluginPort()
57
- .then((res) => {
58
- const { data } = res
59
- const pluginKey = data[`${pluginName}_v${pluginVersion}`]
60
- if (data) {
61
- console.log('pluginPorts', data)
62
- const pluginPort = data[pluginKey]
63
- if (!pluginPort) {
64
- setTimeout(() => {
65
- getPluginPort()
66
- }, 500)
67
- } else {
68
- store.dispatch(toolActions.setPluginPort(pluginPort))
69
- }
70
- }
71
- })
72
- .catch((err) => {
73
- console.log(err)
74
- })
75
- }, [portData.isSync])
76
-
77
- return <>{children}</>
78
- }
1
+ import { ReactNode, useEffect } from 'react'
2
+ import { MqttWebSocketClient } from '../utils/mqtt'
3
+ import dptConfig from '../../dpt.json'
4
+ import MainConfig from '../../configs/Main.json'
5
+ import { getPluginPort } from '@dobot/http/axios'
6
+ import '@dobot/protocol/methodsHandler'
7
+ import { toolActions } from '@dobot/store/actions/toolActions'
8
+ import store from '@dobot/store'
9
+ import { useSelector } from 'react-redux'
10
+ import { IStoreState } from '@dobot/store/types'
11
+
12
+ type BasicProps = {
13
+ children: ReactNode
14
+ }
15
+
16
+ export type DobotPlusAppProps =
17
+ | (BasicProps & {
18
+ useMqtt: true
19
+ topic?: string
20
+ onMessage: (data: any) => void
21
+ port?: number
22
+ })
23
+ | (BasicProps & {
24
+ useMqtt?: false
25
+ })
26
+
27
+ export function DobotPlusApp(props: DobotPlusAppProps) {
28
+ const { children, useMqtt } = props
29
+ const { portData } = useSelector((state: IStoreState) => state.toolReducer)
30
+ useEffect(() => {
31
+ const pluginName = MainConfig.name
32
+ const pluginVersion = MainConfig.version
33
+
34
+ if (useMqtt) {
35
+ const { topic, onMessage, port } = props
36
+
37
+ const ip = process.env.NODE_ENV === 'production' ? portData.ip : dptConfig.ip
38
+
39
+ if (ip && onMessage) {
40
+ const serverUrl = `ws://${ip}:${port || 8083}/mqtt`
41
+ const clientId = `${pluginName}_clientId`
42
+ const mqttClient = new MqttWebSocketClient(serverUrl, clientId)
43
+ mqttClient.connect()
44
+ mqttClient.subscribe(topic || `${pluginName}Status`, (topic, buf) => {
45
+ let data = {}
46
+ try {
47
+ data = JSON.parse(buf.toString())
48
+ } catch {
49
+ data = buf.toString()
50
+ }
51
+ onMessage(data)
52
+ })
53
+ }
54
+ }
55
+
56
+ getPluginPort()
57
+ .then((res) => {
58
+ const { data } = res
59
+ const pluginKey = data[`${pluginName}_v${pluginVersion}`]
60
+ if (data) {
61
+ console.log('pluginPorts', data)
62
+ const pluginPort = data[pluginKey]
63
+ if (!pluginPort) {
64
+ setTimeout(() => {
65
+ getPluginPort()
66
+ }, 500)
67
+ } else {
68
+ store.dispatch(toolActions.setPluginPort(pluginPort))
69
+ }
70
+ }
71
+ })
72
+ .catch((err) => {
73
+ console.log(err)
74
+ })
75
+ }, [portData.isSync])
76
+
77
+ return <>{children}</>
78
+ }
@@ -1,52 +1,52 @@
1
- import axios, { AxiosError, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios'
2
- import dptConfig from '../../dpt.json'
3
- import pluginConfig from '../../configs/Main.json'
4
- import store from '@dobot/store'
5
-
6
- const instance = axios.create()
7
-
8
- instance.interceptors.request.use(
9
- (config: InternalAxiosRequestConfig) => {
10
- config.headers.AuthorizationToken = localStorage.getItem('AuthorizationToken') || ''
11
- return config
12
- },
13
- (err: AxiosError) => Promise.reject(err)
14
- )
15
-
16
- instance.interceptors.response.use(
17
- (res: AxiosResponse) => {
18
- return res
19
- },
20
- (err: AxiosError) => {
21
- return Promise.reject(err)
22
- }
23
- )
24
-
25
- export function request(config: AxiosRequestConfig, port?: number) {
26
- const { portData } = store.getState().toolReducer
27
-
28
- const options: AxiosRequestConfig = {
29
- ...config,
30
- withCredentials: true,
31
- baseURL: `http://${portData.ip}:${port}/dobotPlus/${pluginConfig.name}_v${pluginConfig.version}`
32
- }
33
-
34
- if (process.env.NODE_ENV !== 'production') {
35
- options.baseURL = `/dobotPlus/${pluginConfig.name}_v${pluginConfig.version}`
36
- }
37
-
38
- return instance.request({
39
- ...options,
40
- method: 'post'
41
- })
42
- }
43
-
44
- export function getPluginPort() {
45
- return instance.request({
46
- baseURL: process.env.NODE_ENV !== 'production' ? `` : `http://${dptConfig.ip}:22001`,
47
- url: '/dobotPlus/getPorts',
48
- method: 'get'
49
- })
50
- }
51
-
52
- export default instance
1
+ import axios, { AxiosError, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios'
2
+ import dptConfig from '../../dpt.json'
3
+ import pluginConfig from '../../configs/Main.json'
4
+ import store from '@dobot/store'
5
+
6
+ const instance = axios.create()
7
+
8
+ instance.interceptors.request.use(
9
+ (config: InternalAxiosRequestConfig) => {
10
+ config.headers.AuthorizationToken = localStorage.getItem('AuthorizationToken') || ''
11
+ return config
12
+ },
13
+ (err: AxiosError) => Promise.reject(err)
14
+ )
15
+
16
+ instance.interceptors.response.use(
17
+ (res: AxiosResponse) => {
18
+ return res
19
+ },
20
+ (err: AxiosError) => {
21
+ return Promise.reject(err)
22
+ }
23
+ )
24
+
25
+ export function request(config: AxiosRequestConfig, port?: number) {
26
+ const { portData } = store.getState().toolReducer
27
+
28
+ const options: AxiosRequestConfig = {
29
+ ...config,
30
+ withCredentials: true,
31
+ baseURL: `http://${portData.ip}:${port}/dobotPlus/${pluginConfig.name}_v${pluginConfig.version}`
32
+ }
33
+
34
+ if (process.env.NODE_ENV !== 'production') {
35
+ options.baseURL = `/dobotPlus/${pluginConfig.name}_v${pluginConfig.version}`
36
+ }
37
+
38
+ return instance.request({
39
+ ...options,
40
+ method: 'post'
41
+ })
42
+ }
43
+
44
+ export function getPluginPort() {
45
+ return instance.request({
46
+ baseURL: process.env.NODE_ENV !== 'production' ? `` : `http://${dptConfig.ip}:22001`,
47
+ url: '/dobotPlus/getPorts',
48
+ method: 'get'
49
+ })
50
+ }
51
+
52
+ export default instance
@@ -1,22 +1,22 @@
1
- import { request } from './axios'
2
-
3
- export const demoMethod1 = (data: any) => {
4
- return request({
5
- url: 'demoMethod1',
6
- data
7
- })
8
- }
9
-
10
- export const demoMethod2 = (data: any) => {
11
- return request({
12
- url: 'demoMethod2',
13
- data
14
- })
15
- }
16
-
17
- export const demoMethod3 = (data: any) => {
18
- return request({
19
- url: 'demoMethod3',
20
- data
21
- })
22
- }
1
+ import { request } from './axios'
2
+
3
+ export const demoMethod1 = (data: any) => {
4
+ return request({
5
+ url: 'demoMethod1',
6
+ data
7
+ })
8
+ }
9
+
10
+ export const demoMethod2 = (data: any) => {
11
+ return request({
12
+ url: 'demoMethod2',
13
+ data
14
+ })
15
+ }
16
+
17
+ export const demoMethod3 = (data: any) => {
18
+ return request({
19
+ url: 'demoMethod3',
20
+ data
21
+ })
22
+ }
package/.dobot/index.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * as http from './http/http'
2
- export { DobotPlusApp } from './components/DobotPlusApp'
1
+ export * as http from './http/http'
2
+ export { DobotPlusApp } from './components/DobotPlusApp'
@@ -1,15 +1,15 @@
1
- import { PostMessageHandler } from './postMessageHandler'
2
- import { WebSocketHandler } from './websocketHandler'
3
- import './keyBoard'
4
- import { isInIframe } from '@dobot/utils/tool'
5
-
6
- let methodsHandler: any = undefined
7
- const postMessageHandler = new PostMessageHandler()
8
- // 根据环境判断
9
- if (isInIframe) {
10
- methodsHandler = postMessageHandler
11
- } else {
12
- methodsHandler = new WebSocketHandler()
13
- }
14
-
15
- export { methodsHandler, postMessageHandler }
1
+ import { PostMessageHandler } from './postMessageHandler'
2
+ import { WebSocketHandler } from './websocketHandler'
3
+ import './keyBoard'
4
+ import { isInIframe } from '@dobot/utils/tool'
5
+
6
+ let methodsHandler: any = undefined
7
+ const postMessageHandler = new PostMessageHandler()
8
+ // 根据环境判断
9
+ if (isInIframe) {
10
+ methodsHandler = postMessageHandler
11
+ } else {
12
+ methodsHandler = new WebSocketHandler()
13
+ }
14
+
15
+ export { methodsHandler, postMessageHandler }