Merge pull request #828 from jinyus/wsockdev
This commit is contained in:
@@ -45,6 +45,8 @@
|
|||||||
v-model="communication.input"
|
v-model="communication.input"
|
||||||
:readonly="!connectionState"
|
:readonly="!connectionState"
|
||||||
@keyup.enter="connectionState ? sendMessage() : null"
|
@keyup.enter="connectionState ? sendMessage() : null"
|
||||||
|
@keyup.up="connectionState ? walkHistory('up') : null"
|
||||||
|
@keyup.down="connectionState ? walkHistory('down') : null"
|
||||||
/>
|
/>
|
||||||
</li>
|
</li>
|
||||||
<div>
|
<div>
|
||||||
@@ -80,6 +82,7 @@ export default {
|
|||||||
log: null,
|
log: null,
|
||||||
input: "",
|
input: "",
|
||||||
},
|
},
|
||||||
|
currentIndex: -1, //index of the message log array to put in input box
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -104,7 +107,7 @@ export default {
|
|||||||
]
|
]
|
||||||
try {
|
try {
|
||||||
this.socket = new WebSocket(this.url)
|
this.socket = new WebSocket(this.url)
|
||||||
this.socket.onopen = event => {
|
this.socket.onopen = (event) => {
|
||||||
this.connectionState = true
|
this.connectionState = true
|
||||||
this.communication.log = [
|
this.communication.log = [
|
||||||
{
|
{
|
||||||
@@ -118,10 +121,10 @@ export default {
|
|||||||
icon: "sync",
|
icon: "sync",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.socket.onerror = event => {
|
this.socket.onerror = (event) => {
|
||||||
this.handleError()
|
this.handleError()
|
||||||
}
|
}
|
||||||
this.socket.onclose = event => {
|
this.socket.onclose = (event) => {
|
||||||
this.connectionState = false
|
this.connectionState = false
|
||||||
this.communication.log.push({
|
this.communication.log.push({
|
||||||
payload: this.$t("disconnected_from", { name: this.url }),
|
payload: this.$t("disconnected_from", { name: this.url }),
|
||||||
@@ -133,7 +136,7 @@ export default {
|
|||||||
icon: "sync_disabled",
|
icon: "sync_disabled",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.socket.onmessage = event => {
|
this.socket.onmessage = (event) => {
|
||||||
this.communication.log.push({
|
this.communication.log.push({
|
||||||
payload: event.data,
|
payload: event.data,
|
||||||
source: "server",
|
source: "server",
|
||||||
@@ -177,6 +180,37 @@ export default {
|
|||||||
})
|
})
|
||||||
this.communication.input = ""
|
this.communication.input = ""
|
||||||
},
|
},
|
||||||
|
walkHistory(direction) {
|
||||||
|
const clientMessages = this.communication.log.filter((msg) => msg.source === "client")
|
||||||
|
const length = clientMessages.length
|
||||||
|
switch (direction) {
|
||||||
|
case "up":
|
||||||
|
if (length > 0 && this.currentIndex !== 0) {
|
||||||
|
//does nothing if message log is empty or the currentIndex is 0 when up arrow is pressed
|
||||||
|
if (this.currentIndex === -1) {
|
||||||
|
this.currentIndex = length - 1
|
||||||
|
this.communication.input = clientMessages[this.currentIndex].payload
|
||||||
|
} else if (this.currentIndex === 0) {
|
||||||
|
this.communication.input = clientMessages[0].payload
|
||||||
|
} else if (this.currentIndex > 0) {
|
||||||
|
this.currentIndex = this.currentIndex - 1
|
||||||
|
this.communication.input = clientMessages[this.currentIndex].payload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case "down":
|
||||||
|
if (length > 0 && this.currentIndex > -1) {
|
||||||
|
if (this.currentIndex === length - 1) {
|
||||||
|
this.currentIndex = -1
|
||||||
|
this.communication.input = ""
|
||||||
|
} else if (this.currentIndex < length - 1) {
|
||||||
|
this.currentIndex = this.currentIndex + 1
|
||||||
|
this.communication.input = clientMessages[this.currentIndex].payload
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user