Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update @alcalzone/release-script-plugin-iobroker requirement from ^3.5.9 to ^3.6.0 #79

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 53 additions & 42 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function MQTTServer(adapter, states) {
cb();
cb = null;
}
}, 2000);
}, 5000);
}
if (server) {
tasks++;
Expand Down Expand Up @@ -571,28 +571,28 @@ function MQTTServer(adapter, states) {
*/
function pattern2RegEx(pattern) {
pattern = convertTopic2id(pattern, true, adapter.config.prefix, adapter.namespace);
pattern = pattern.replace(/#/g, '*');
if (pattern === '#') {
return '.*';
}
if (pattern === '+') {
return '[^.]*';
}
pattern = pattern.replace(/\$/g, '\\$');
pattern = pattern.replace(/\^/g, '\\^');

if (pattern !== '*') {
if (pattern[0] === '*' && pattern[pattern.length - 1] !== '*') {
pattern += '$';
}
if (pattern[0] !== '*' && pattern[pattern.length - 1] === '*') {
pattern = '^' + pattern;
}
if (pattern[0] === '+') {
pattern = '^[^.]*' + pattern.substring(1);
}
if (pattern[pattern.length - 1] === '+') {
pattern = pattern.substring(0, pattern.length - 1) + '[^.]*$';
}
} else {
return '.*';
if (pattern.length > 2 && (
(pattern[0] === '#' && pattern[1] !== '.') ||
(pattern[0] === '+' && pattern[1] !== '.') ||
(pattern[pattern.length - 1] === '#' && pattern[pattern.length - 2] !== '.') ||
(pattern[pattern.length - 1] === '+' && pattern[pattern.length - 2] !== '.'))) {
return '';
}
pattern = '^' + pattern + '$';
pattern = pattern.replace(/#/g, '*');
pattern = pattern.replace(/\./g, '\\.');
pattern = pattern.replace(/\\\.\*/g, '\\..*');
if (pattern[1] === '*') {
pattern = '^.' + pattern.substring(1);
}
pattern = pattern.replace(/\\\.\*/g, '(\\..*)?');
pattern = pattern.replace(/\+/g, '[^.]*');
return pattern;
}
Expand Down Expand Up @@ -860,7 +860,7 @@ function MQTTServer(adapter, states) {
}

if (adapter.config.debug) {
adapter.log.debug(`Client [${client.id}] received publish package ${JSON.stringify(packet)}`);
adapter.log.debug(`Client [${client.id}] received publish ${packet.messageId} ${JSON.stringify(packet)}`);
}

if (persistentSessions[client.id]) {
Expand All @@ -872,19 +872,21 @@ function MQTTServer(adapter, states) {
client.puback({messageId: packet.messageId});
} else if (packet.qos === 2) {
const pack = client._messages && client._messages.find(e => e.messageId === packet.messageId);
if (pack) {
if (pack && packet.dup === false) {
// duplicate message => ignore
adapter.log.info(`Client [${client.id}] Ignored duplicate message with ID: ${packet.messageId}`);
return;
} else if (pack) {
client.pubrec({messageId: packet.messageId});
return;
} else {
packet.ts = Date.now();
packet.cmd = 'pubrel';
packet.cmd = 'pubrec';
packet.count = 0;
client._messages = client._messages || [];
client._messages.push(packet);

client.pubrec({messageId: packet.messageId});
return;
// return;
}
}

Expand All @@ -899,19 +901,28 @@ function MQTTServer(adapter, states) {
}

if (adapter.config.debug) {
adapter.log.debug(`Client [${client.id}] received pubrec package ${JSON.stringify(packet)}`);
adapter.log.debug(`Client [${client.id}] received pubrec ${packet.messageId} ${JSON.stringify(packet)}`);
}

if (persistentSessions[client.id]) {
persistentSessions[client.id].lastSeen = Date.now();
}

let pos = -1;
// remove this message from queue
const frame = client._messages && client._messages.find(e => e.messageId === packet.messageId);
if (frame) {
if (client._messages) {
pos = client._messages.findIndex(e => e.messageId === packet.messageId);
}
if (pos !== -1) {
client._messages.splice(pos, 1);
packet.ts = Date.now();
packet.cmd = 'pubrel';
packet.count = 0;
client._messages = client._messages || [];
client._messages.push(packet);
client.pubrel({messageId: packet.messageId});
} else {
adapter.log.info(`Client [${client.id}] Received pubrec on ${client.id} for unknown messageId ${packet.messageId}`);
adapter.log.info(`Client [${client.id}] Received pubrec for unknown messageId ${packet.messageId}`);
}
});

Expand All @@ -923,7 +934,7 @@ function MQTTServer(adapter, states) {
}

if (adapter.config.debug) {
adapter.log.debug(`Client [${client.id}] received pubcomp package ${JSON.stringify(packet)}`);
adapter.log.debug(`Client [${client.id}] received pubcomp ${packet.messageId} ${JSON.stringify(packet)}`);
}

if (persistentSessions[client.id]) {
Expand All @@ -950,7 +961,7 @@ function MQTTServer(adapter, states) {
}

if (adapter.config.debug) {
adapter.log.debug(`Client [${client.id}] received pubrel package ${JSON.stringify(packet)}`);
adapter.log.debug(`Client [${client.id}] received pubrel ${packet.messageId} ${JSON.stringify(packet)}`);
}

if (persistentSessions[client.id]) {
Expand All @@ -959,13 +970,12 @@ function MQTTServer(adapter, states) {

// remove this message from queue
let pos = -1;
// remove this message from queue
if (client._messages) {
pos = client._messages.findIndex(e => e.messageId === packet.messageId);
}
if (pos !== -1) {
client.pubcomp({messageId: packet.messageId});
await receivedTopic(client._messages[pos], client);
// await receivedTopic(client._messages[pos], client);
client._messages.splice(pos, 1);
} else {
adapter.log.info(`Client [${client.id}] Received pubrel for unknown message ID: ${packet.messageId}`);
Expand All @@ -979,7 +989,7 @@ function MQTTServer(adapter, states) {
}

if (adapter.config.debug) {
adapter.log.debug(`Client [${client.id}] received puback package ${JSON.stringify(packet)}`);
adapter.log.debug(`Client [${client.id}] received puback ${JSON.stringify(packet)}`);
}

if (persistentSessions[client.id]) {
Expand All @@ -988,12 +998,10 @@ function MQTTServer(adapter, states) {

// remove this message from queue
let pos = -1;
// remove this message from queue
if (client._messages) {
pos = client._messages.findIndex(e => e.messageId === packet.messageId);
}
if (pos !== -1) {
adapter.log.debug(`Client [${client.id}] Received puback for ${client.id} message ID: ${packet.messageId}`);
client._messages.splice(pos, 1);
} else {
adapter.log.info(`Client [${client.id}] Received puback for unknown message ID: ${packet.messageId}`);
Expand Down Expand Up @@ -1198,7 +1206,9 @@ function MQTTServer(adapter, states) {
const message = clients[clientId]._messages[m];
if (now - message.ts >= adapter.config.retransmitInterval) {
if (message.count > adapter.config.retransmitCount) {
adapter.log.warn(`Client [${clientId}] Message ${message.messageId} deleted after ${message.count} retries`);
if (message.cmd !== 'pubrec') {
adapter.log.warn(`Client [${clientId}] ${message.cmd} Id ${message.messageId} deleted after ${message.count} retries`);
}
clients[clientId]._messages.splice(m, 1);
continue;
}
Expand All @@ -1207,14 +1217,15 @@ function MQTTServer(adapter, states) {
message.count++;
message.ts = now;
try {
adapter.log.debug(`Client [${clientId}] Resend for ${message.cmd} message topic: ${message.topic}, payload: ${message.payload}`);
if (message.cmd === 'publish') {
message.dup = true;
clients[clientId].publish(message);
} else if (message.cmd === 'pubrel') {
clients[clientId].pubrec({
messageId: message.messageId
});
adapter.log.info(`Client [${clientId}] Resend #${message.count} ${message.cmd}, message ${message.messageId}, topic: ${message.topic}, payload: ${message.payload}`);
} else if (message.cmd === 'pubrec') {
// adapter.log.debug(`${message.cmd} timeout, #${message.messageId}, topic: ${message.topic}, payload: ${message.payload}`);
} else if (message.cmd === 'pubrel') {
clients[clientId].pubrel({messageId: message.messageId});
adapter.log.info(`Client [${clientId}] Resend #${message.count} ${message.cmd}, message ${message.messageId}, topic: ${message.topic}, payload: ${message.payload}`);
}
} catch (e) {
adapter.log.warn(`Client [${clientId}] Cannot publish message: ${e}`);
Expand Down Expand Up @@ -1273,7 +1284,7 @@ function MQTTServer(adapter, states) {
config.port = 1883;
}
config.retransmitInterval = config.retransmitInterval || 2000;
config.retransmitCount = config.retransmitCount || 10;
config.retransmitCount = config.retransmitCount || 4;
if (config.storeClientsTime === undefined) {
config.storeClientsTime = 1440;
} else {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
},
"devDependencies": {
"@alcalzone/release-script": "^3.5.9",
"@alcalzone/release-script-plugin-iobroker": "^3.5.9",
"@alcalzone/release-script-plugin-iobroker": "^3.6.0",
"@alcalzone/release-script-plugin-license": "^3.5.9",
"@iobroker/adapter-dev": "^1.2.0",
"@iobroker/legacy-testing": "^0.1.1",
"eslint": "^8.39.0"
"@iobroker/legacy-testing": "^0.3.6",
"eslint": "^8.41.0"
},
"bugs": {
"url": "https://github.com/ioBroker/ioBroker.mqtt/issues"
Expand Down