2024-10-18 17:54:37 +08:00
|
|
|
import s from "apigo.cc/gojs/service"
|
2024-10-17 13:39:35 +08:00
|
|
|
import co from "apigo.cc/gojs/console"
|
|
|
|
|
|
|
|
function main() {
|
2024-10-18 17:54:37 +08:00
|
|
|
s.register({
|
2024-10-17 13:39:35 +08:00
|
|
|
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)
|
2024-10-17 13:39:35 +08:00
|
|
|
}
|
|
|
|
}, ({ client }) => {
|
2024-10-18 17:54:37 +08:00
|
|
|
co.info('ws connected', client.id)
|
|
|
|
s.dataSet('wsTest', client.id, client)
|
2024-10-17 13:39:35 +08:00
|
|
|
client.write('Hello, World!')
|
|
|
|
})
|
|
|
|
}
|