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

Realtime SocketIO support for json user input #820

Merged
merged 1 commit into from
Apr 28, 2020
Merged
Changes from all commits
Commits
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
18 changes: 12 additions & 6 deletions components/realtime/socketio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ export default {
ts: new Date().toLocaleTimeString(),
})
})
this.io.on("connect_error", error => {
this.io.on("connect_error", (error) => {
this.handleError(error)
})
this.io.on("reconnect_error", error => {
this.io.on("reconnect_error", (error) => {
this.handleError(error)
})
this.io.on("error", data => {
this.io.on("error", (data) => {
this.handleError()
})
this.io.on("disconnect", () => {
Expand Down Expand Up @@ -194,12 +194,18 @@ export default {
},
sendMessage() {
const eventName = this.communication.eventName
const message = this.communication.input
let message

try {
message = JSON.parse(this.communication.input)
} catch (err) {
message = this.communication.input
}

if (this.io) {
// TODO: support only one argument now
// maybe should support more argument
this.io.emit(eventName, message, data => {
this.io.emit(eventName, message, (data) => {
// receive response from server
this.communication.log.push({
payload: `[${eventName}] ${JSON.stringify(data)}`,
Expand All @@ -209,7 +215,7 @@ export default {
})

this.communication.log.push({
payload: `[${eventName}] ${message}`,
payload: `[${eventName}] ${JSON.stringify(message)}`,
source: "client",
ts: new Date().toLocaleTimeString(),
})
Expand Down