service/tests/api/ws.js

20 lines
549 B
JavaScript
Raw Permalink Normal View History

2024-10-18 17:54:37 +08:00
import s from "apigo.cc/gojs/service"
import co from "apigo.cc/gojs/console"
function main() {
2024-10-18 17:54:37 +08:00
s.register({
method: 'WS', path: '/ws',
onMessage: ({ client, type, data }) => {
client.writeMessage(type, data)
},
2024-10-18 17:54:37 +08:00
onClose: ({ client }) => {
co.info('ws closed', client.id)
s.dataRemove('wsTest', client.id)
}
}, ({ client }) => {
2024-10-18 17:54:37 +08:00
co.info('ws connected', client.id)
s.dataSet('wsTest', client.id, client)
client.write('Hello, World!')
})
}