phecda-server-ws
v2.0.0
Published
provide ws function to phecda-server
Downloads
7
Readme
phecda-server-ws
support using ws
in phecda-server
install
npm i phecda-server-ws
quick start
create a controller to expose
import { Arg, Ctx } from 'phecda-server'
import { On, Ws, type WsContext } from 'phecda-server-ws'
@Ws()
export class TestWs {
@Ctx
context: WsContext
@On
add(@Arg data: { name: string }) {
this.context.broadcast('test', data)
}
}
bind ws and start server
import { WSGenerator, bind } from 'phecda-server-ws'
import { Factory } from 'phecda-server'
import { WebSocketServer } from 'ws'
import { TestWs } from './test.ws'
const data = await Factory([TestWs], {
generators: [new WSGenerator()],
})
const server = new WebSocketServer({ port: 3001 })
bind(server, data)
if you use ps
runtime , update the config file(ps.json
)
{
"resolve": [
{
"source": "ws",
"importer": "client",
"path": ".ps/ws.js"
}
],
"moduleFile": ["ws"]
}