Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/development' into feat-beam-li…
Browse files Browse the repository at this point in the history
…st-filter-style
  • Loading branch information
Rohan Bansal committed Nov 7, 2024
2 parents 11703e5 + 0a52246 commit f146b8c
Show file tree
Hide file tree
Showing 9 changed files with 323 additions and 14 deletions.
11 changes: 11 additions & 0 deletions beam/config/api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,16 @@
"docModel": {
"enabled": true,
"projectFolderUrl": "https://github.com/agritheory/stonecrop/tree/development/beam"
},

"messages": {
"extractorMessageReporting": {
// Disable this validation at your own risk: Processing an incorrect file type
// may lead to other errors. Function bodies may incorrectly get emitted in the
// .d.ts rollup.
"ae-wrong-input-file-type": {
"logLevel": "none"
}
}
}
}
1 change: 1 addition & 0 deletions beam/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"test:ui": "vitest --ui"
},
"dependencies": {
"mqtt": "^5.10.1",
"onscan.js": "^1.5.2",
"vue": "^3.5.6"
},
Expand Down
41 changes: 41 additions & 0 deletions beam/src/composables/mqtt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import mqtt, { type MqttClient, type IClientOptions } from 'mqtt'
import { onMounted, onUnmounted, ref } from 'vue'

interface IMqttStream extends IClientOptions {
topics?: string[]
}

export const useMqttStream = (options?: IMqttStream) => {
const client = ref<MqttClient>(null)
const messages = ref<Record<string, string[]>>({})

onMounted(() => {
client.value = mqtt.connect(options)

if (!options.topics) {
options.topics = ['#']
}

for (const topic of options.topics) {
client.value.subscribe(topic, err => {
if (err) {
throw err
}
})
}

client.value.on('message', (topic, message) => {
if (!messages.value[topic]) {
messages.value[topic] = []
}

messages.value[topic].push(message.toString())
})
})

onUnmounted(() => {
client.value.end()
})

return { messages }
}
2 changes: 2 additions & 0 deletions beam/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Navbar from '@/components/Navbar.vue'
import ScanInput from '@/components/ScanInput.vue'
import SplitColumn from '@/components/SplitColumn.vue'
import ToggleArrow from '@/components/ToggleArrow.vue'
import { useMqttStream } from '@/composables/mqtt'
import 'themes/beam.css'

/**
Expand Down Expand Up @@ -75,4 +76,5 @@ export {
SplitColumn,
ToggleArrow,
install,
useMqttStream,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@stonecrop/beam",
"comment": "add MQTT stream composable",
"type": "patch"
}
],
"packageName": "@stonecrop/beam"
}
4 changes: 4 additions & 0 deletions common/config/rush/browser-approved-packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@
"name": "monaco-editor",
"allowedCategories": [ "prototype" ]
},
{
"name": "mqtt",
"allowedCategories": [ "prototype" ]
},
{
"name": "node-sass",
"allowedCategories": [ "prototype" ]
Expand Down
Loading

0 comments on commit f146b8c

Please sign in to comment.