service/tests/api/ws.js
2024-10-18 17:54:37 +08:00

20 lines
549 B
JavaScript

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