Merge pull request #795 from konradkalemba/master

Listen to all events in socket.io connection
This commit is contained in:
Liyas Thomas
2020-04-21 06:34:19 +05:30
committed by GitHub
3 changed files with 14516 additions and 14506 deletions

View File

@@ -78,6 +78,7 @@
<script> <script>
import { socketioValid } from "~/functions/utils/valid" import { socketioValid } from "~/functions/utils/valid"
import io from "socket.io-client" import io from "socket.io-client"
import wildcard from "socketio-wildcard"
export default { export default {
components: { components: {
@@ -119,6 +120,8 @@ export default {
try { try {
this.io = new io(this.url) this.io = new io(this.url)
// Add ability to listen to all events
wildcard(io.Manager)(this.io)
this.io.on("connect", () => { this.io.on("connect", () => {
this.connectionState = true this.connectionState = true
this.communication.log = [ this.communication.log = [
@@ -133,9 +136,10 @@ export default {
icon: "sync", icon: "sync",
}) })
}) })
this.io.on("message", data => { this.io.on("*", ({ data }) => {
const [eventName, message] = data
this.communication.log.push({ this.communication.log.push({
payload: data, payload: `[${eventName}] ${message ? JSON.stringify(message) : ""}`,
source: "server", source: "server",
ts: new Date().toLocaleTimeString(), ts: new Date().toLocaleTimeString(),
}) })

29013
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -44,6 +44,7 @@
"nuxt-i18n": "^6.9.1", "nuxt-i18n": "^6.9.1",
"paho-mqtt": "^1.1.0", "paho-mqtt": "^1.1.0",
"socket.io-client": "^2.3.0", "socket.io-client": "^2.3.0",
"socketio-wildcard": "^2.0.0",
"v-tooltip": "^2.0.3", "v-tooltip": "^2.0.3",
"vue-virtual-scroll-list": "^1.4.7", "vue-virtual-scroll-list": "^1.4.7",
"vuefire": "^2.2.2", "vuefire": "^2.2.2",