Skip to content

Commit

Permalink
feat(web): fully synchronized create connection form
Browse files Browse the repository at this point in the history
  • Loading branch information
Red-Asuka authored and ysfscream committed Sep 17, 2022
1 parent bc999a3 commit fc4001f
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 72 deletions.
19 changes: 12 additions & 7 deletions web/src/lang/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ export default {
ja: '遺言',
},
strictValidateCertificate: {
zh: '严格证书验证',
en: 'Strict validate Certificate',
zh: 'SSL 安全',
en: 'SSL Secure',
ja: 'SSL証明書',
},
willTopic: {
Expand Down Expand Up @@ -324,11 +324,6 @@ export default {
en: 'Content Type',
ja: '遺言詳細情報',
},
isUTF8Data: {
zh: '是否为 UTF-8 编码数据',
en: 'is UTF-8 Encoded Data',
ja: 'UTF-8エンコードデータフラグ',
},
duplicateName: {
zh: '该名称已存在,请重新命名!',
en: 'Duplicate name. Please rename it!',
Expand All @@ -339,6 +334,16 @@ export default {
en: 'Quick selection of created connection configurations',
ja: '作成された接続構成を早めに選択することができます',
},
clientIdWithTimeTip: {
zh: '在连接时附加时间戳到 ClientID,以防止重复的连接',
en: 'Append a timestamp to the ClientID at connection time to prevent duplicate connections',
ja: '重複接続を防ぐために、ClientIDにタイムスタンプを追加します',
},
secureTip: {
zh: '是否验证服务端证书链和地址名称',
en: "Whether a client verifies the server's certificate chain and host name",
ja: "Whether a client verifies the server's certificate chain and host name",
},
publishMsg: {
zh: '发送消息',
en: 'Publish message',
Expand Down
7 changes: 6 additions & 1 deletion web/src/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ declare global {

type CertType = '' | 'server' | 'self'

type MqttVersion = '3.1.1' | '5.0'

enum ProtocolOption {
ws = 'ws',
wss = 'wss',
Expand Down Expand Up @@ -269,6 +271,8 @@ declare global {
name: string
clean: boolean
protocol?: Protocol
createAt: string
updateAt: string
host: string
port: number
keepalive: number
Expand All @@ -280,7 +284,7 @@ declare global {
path: string
certType?: CertType
ssl: boolean
mqttVersion: '3.1.1' | '5.0'
mqttVersion: MqttVersion
unreadMessageCount: number
messages: MessageModel[]
pushProps: PushPropertiesModel
Expand All @@ -292,5 +296,6 @@ declare global {
}
will?: WillModel
properties?: ClientPropertiesModel
clientIdWithTime?: boolean
}
}
20 changes: 13 additions & 7 deletions web/src/utils/mqttUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ const getClientOptions = (record: ConnectionModel): IClientOptions => {
reconnectPeriod, // reconnectPeriod = 0 disabled automatic reconnection in the client
will,
rejectUnauthorized,
// clientIdWithTime,
clientIdWithTime,
} = record
const protocolVersion = mqttVersionDict[mqttVersion as '3.1.1' | '5.0']
const protocolVersion = mqttVersionDict[mqttVersion]
const options: IClientOptions = {
clientId,
keepalive,
Expand All @@ -52,10 +52,10 @@ const getClientOptions = (record: ConnectionModel): IClientOptions => {
}
options.connectTimeout = time.convertSecondsToMs(connectTimeout)
// Append timestamp to MQTT client id
// if (clientIdWithTime) {
// const clickIconTime = Date.parse(new Date().toString())
// options.clientId = `${options.clientId}_${clickIconTime}`
// }
if (clientIdWithTime) {
const clickIconTime = Date.parse(new Date().toString())
options.clientId = `${options.clientId}_${clickIconTime}`
}
// Auth
if (username !== '') {
options.username = username
Expand Down Expand Up @@ -141,6 +141,8 @@ export const getMQTTProtocol = (data: ConnectionModel): Protocol => {
export const getDefaultRecord = (): ConnectionModel => {
return {
clientId: getClientId(),
createAt: time.getNowDate(),
updateAt: time.getNowDate(),
name: '',
clean: true,
protocol: 'ws',
Expand All @@ -155,7 +157,7 @@ export const getDefaultRecord = (): ConnectionModel => {
port: 8083,
ssl: false,
certType: '',
rejectUnauthorized: false,
rejectUnauthorized: true,
ca: '',
cert: '',
key: '',
Expand All @@ -177,6 +179,9 @@ export const getDefaultRecord = (): ConnectionModel => {
willDelayInterval: undefined,
messageExpiryInterval: undefined,
contentType: '',
responseTopic: '',
correlationData: undefined,
userProperties: undefined,
},
},
properties: {
Expand All @@ -190,6 +195,7 @@ export const getDefaultRecord = (): ConnectionModel => {
authenticationMethod: undefined,
authenticationData: undefined,
},
clientIdWithTime: false,
}
}

Expand Down
Loading

0 comments on commit fc4001f

Please sign in to comment.