From fae4b3e4096ccb20bf485b2d244472862ffcad51 Mon Sep 17 00:00:00 2001 From: YuShifan <894402575bt@gmail.com> Date: Sun, 9 Oct 2022 14:16:48 +0800 Subject: [PATCH] refactor(connection): clean session -> clean start on mqtt5 --- src/lang/common.ts | 7 +++ src/lang/connections.ts | 7 --- src/utils/mqttUtils.ts | 14 ++++-- src/views/connections/ConnectionForm.vue | 59 +++++++++++++++--------- src/views/connections/ConnectionInfo.vue | 2 +- 5 files changed, 56 insertions(+), 33 deletions(-) diff --git a/src/lang/common.ts b/src/lang/common.ts index ff271c92d..7664e7949 100644 --- a/src/lang/common.ts +++ b/src/lang/common.ts @@ -244,4 +244,11 @@ export default { ja: '複製', hu: 'Másol', }, + neverExpire: { + zh: '永不过期', + en: 'Never Expire', + tr: 'Süresiz', + ja: '期限なし', + hu: 'Soha ne járjon le', + }, } diff --git a/src/lang/connections.ts b/src/lang/connections.ts index a1edb2a28..1543678e9 100644 --- a/src/lang/connections.ts +++ b/src/lang/connections.ts @@ -265,13 +265,6 @@ export default { ja: '接続タイムアウト', hu: 'Kapcsolat időtúlléps', }, - cleanSession: { - zh: '清除会话', - en: 'Clean Session', - tr: 'Temiz Oturum', - ja: 'セッションクリア', - hu: 'Munkamenet törlése', - }, autoReconnect: { zh: '自动重连', en: 'Auto Reconnect', diff --git a/src/utils/mqttUtils.ts b/src/utils/mqttUtils.ts index efa2c5a3d..e775fbcc8 100644 --- a/src/utils/mqttUtils.ts +++ b/src/utils/mqttUtils.ts @@ -5,11 +5,19 @@ import time from '@/utils/time' import { getSSLFile } from '@/utils/getFiles' import _ from 'lodash' -const setMQTT5Properties = (option: ClientPropertiesModel) => { +const setMQTT5Properties = ({ clean, properties: option }: ConnectionModel) => { if (option === undefined) { return undefined } const properties: ClientPropertiesModel = _.cloneDeep(option) + if (properties.sessionExpiryInterval === null && !clean) { + /** + Clean Start set True and Session Expiry Interval set 0, the server MUST delete any Session State it holds for the Client + Clean Start set False and Session Expiry Interval set 4294967295, the server MUST NOT delete any Session State it holds for the Client + Non-standard usage, user-friendly only, remember that Clean Start needs to be used with sessionExpiryInterval In MQTT 5.0 + **/ + properties.sessionExpiryInterval = 4294967295 + } return Object.fromEntries(Object.entries(properties).filter(([_, v]) => v !== null && v !== undefined)) } @@ -66,7 +74,7 @@ const getClientOptions = (record: ConnectionModel): IClientOptions => { } // MQTT Version if (protocolVersion === 5 && record.properties) { - const properties = setMQTT5Properties(record.properties) + const properties = setMQTT5Properties(record) if (properties && Object.keys(properties).length > 0) { options.properties = properties } @@ -188,7 +196,7 @@ export const getDefaultRecord = (): ConnectionModel => { }, }, properties: { - sessionExpiryInterval: undefined, + sessionExpiryInterval: 0, receiveMaximum: undefined, maximumPacketSize: undefined, topicAliasMaximum: undefined, diff --git a/src/views/connections/ConnectionForm.vue b/src/views/connections/ConnectionForm.vue index fceb15d3e..9d4a65854 100644 --- a/src/views/connections/ConnectionForm.vue +++ b/src/views/connections/ConnectionForm.vue @@ -236,6 +236,16 @@ + + + + + + + + + +
({{ $t('common.unitS') }})
- - - - - - - - - - - - - + @@ -302,24 +300,25 @@ - - - - - - + + + - - + + +