Skip to content

Commit

Permalink
MQTT client handles client_properties (#944)
Browse files Browse the repository at this point in the history
* extend the details tuple for the mqtt client to have client_properties and more

---------

Co-authored-by: Jon Börjesson <[email protected]>
  • Loading branch information
kickster97 and spuun authored Feb 14, 2025
1 parent a0bd78d commit 7b8ea56
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
20 changes: 15 additions & 5 deletions src/lavinmq/mqtt/client.cr
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,17 @@ module LavinMQ

def details_tuple
{
vhost: @broker.vhost.name,
user: @user.name,
protocol: "MQTT",
client_id: @client_id,
connected_at: @connected_at,
vhost: @broker.vhost.name,
user: @user.name,
protocol: "MQTT 3.1.1",
client_id: @client_id,
name: @name,
connected_at: @connected_at,
state: state,
ssl: @connection_info.ssl?,
tls_version: @connection_info.ssl_version,
cipher: @connection_info.ssl_cipher,
client_properties: NamedTuple.new,
}.merge(stats_details)
end

Expand Down Expand Up @@ -167,6 +173,10 @@ module LavinMQ
@waitgroup.wait
end

def state
@closed ? "closed" : (@broker.vhost.flow? ? "running" : "flow")
end

def force_close
close_socket
end
Expand Down
20 changes: 9 additions & 11 deletions static/js/connections.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@ Table.renderTable('table', tableOptions, function (tr, item, all) {
if (all) {
const connectionLink = document.createElement('a')
connectionLink.href = `connection#name=${encodeURIComponent(item.name)}`
if (item.client_properties.connection_name) {
connectionLink.appendChild(document.createElement('span')).textContent = item.name
connectionLink.appendChild(document.createElement('br'))
connectionLink.appendChild(document.createElement('small')).textContent = item.client_properties.connection_name
} else {
connectionLink.textContent = item.name
}
connectionLink.appendChild(document.createElement('span')).textContent = item.name
connectionLink.appendChild(document.createElement('br'))
connectionLink.appendChild(document.createElement('small')).textContent = item.client_properties.connection_name
Table.renderCell(tr, 0, item.vhost)
Table.renderCell(tr, 1, connectionLink)
Table.renderCell(tr, 2, item.user)
Expand All @@ -37,11 +33,13 @@ Table.renderTable('table', tableOptions, function (tr, item, all) {
Table.renderCell(tr, 9, item.channel_max, 'right')
Table.renderCell(tr, 10, item.timeout, 'right')
const clientDiv = document.createElement('span')
if (item?.client_properties) {
clientDiv.textContent = `${item.client_properties.product} / ${item.client_properties.platform || ''}`
clientDiv.appendChild(document.createElement('br'))
clientDiv.appendChild(document.createElement('small')).textContent = item.client_properties.version
if (item.client_properties.product) {
clientDiv.textContent = `${item.client_properties.product || ''} / ${item.client_properties.platform || ''}`
} else {
clientDiv.textContent = item.client_properties.platform || ''
}
clientDiv.appendChild(document.createElement('br'))
clientDiv.appendChild(document.createElement('small')).textContent = item.client_properties.version
Table.renderCell(tr, 11, clientDiv)
Table.renderCell(tr, 12, new Date(item.connected_at).toLocaleString(), 'center')
}
Expand Down

0 comments on commit 7b8ea56

Please sign in to comment.