@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.
- package/.dobot/components/DobotPlusApp.tsx +78 -78
- package/.dobot/http/axios.ts +52 -52
- package/.dobot/http/http.ts +22 -22
- package/.dobot/index.ts +2 -2
- package/.dobot/protocol/methodsHandler.ts +15 -15
- package/.dobot/protocol/postMessageHandler.ts +289 -289
- package/.dobot/shim.d.ts +3 -3
- package/.dobot/store/actions/toolActions.ts +69 -69
- package/.dobot/store/reducers/index.ts +8 -8
- package/.dobot/store/reducers/toolReducer.ts +152 -152
- package/.dobot/store/types.ts +240 -240
- package/.dobot/template/default.tsx.mustache +19 -19
- package/.dobot/template/entry.css +25 -25
- package/.dobot/template/entry.tsx +53 -53
- package/.dobot/template/index.html +23 -23
- package/.dobot/template/index.scss +5 -5
- package/.dobot/utils/i18n.ts +31 -31
- package/.dobot/utils/mqtt.ts +61 -61
- package/.dobot/utils/rem.js +21 -21
- package/.dobot/utils/tool.ts +15 -15
- package/.eslintrc.cjs +18 -18
- package/.luarc.json +8 -8
- package/.vscode/Api.schema.json +103 -103
- package/.vscode/Blocks.schema.json +94 -94
- package/.vscode/Main.schema.json +42 -42
- package/.vscode/Script.schema.json +22 -22
- package/.vscode/Toolbar.schema.json +19 -19
- package/.vscode/extensions.json +8 -8
- package/.vscode/settings.json +51 -51
- package/Resources/i18n/client/de.json +11 -11
- package/Resources/i18n/client/en.json +11 -11
- package/Resources/i18n/client/es.json +11 -11
- package/Resources/i18n/client/hk.json +11 -11
- package/Resources/i18n/client/ja.json +11 -11
- package/Resources/i18n/client/ko.json +11 -11
- package/Resources/i18n/client/ru.json +11 -11
- package/Resources/i18n/client/zh.json +11 -11
- package/Resources/i18n/plugin/de.json +3 -3
- package/Resources/i18n/plugin/en.json +3 -3
- package/Resources/i18n/plugin/es.json +3 -3
- package/Resources/i18n/plugin/hk.json +3 -3
- package/Resources/i18n/plugin/ja.json +3 -3
- package/Resources/i18n/plugin/ko.json +3 -3
- package/Resources/i18n/plugin/ru.json +3 -3
- package/Resources/i18n/plugin/zh.json +3 -3
- package/configs/Blocks.json +21 -21
- package/configs/Main.json +5 -5
- package/configs/Scripts.json +7 -7
- package/configs/Toolbar.json +5 -5
- package/dpt.json +4 -4
- package/lua/control.lua +18 -18
- package/lua/daemon.lua +22 -22
- package/lua/httpAPI.lua +66 -66
- package/lua/userAPI.lua +51 -51
- package/lua/utils/mqtt.lua +16 -16
- package/lua/utils/num_convert.lua +41 -41
- package/lua/utils/tcp.lua +30 -30
- package/lua/utils/util.lua +30 -30
- package/package.json +58 -48
- package/project.json +3 -3
- package/tsconfig.json +26 -26
- package/ui/Blocks.tsx +5 -5
- package/ui/Main.tsx +31 -31
- 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
|
+
}
|
package/.dobot/http/axios.ts
CHANGED
|
@@ -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
|
package/.dobot/http/http.ts
CHANGED
|
@@ -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 }
|