phecda-server-ws
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

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"]
}

Readme

Keywords

Package Sidebar

Install

npm i phecda-server-ws

Weekly Downloads

0

Version

2.0.0

License

MIT

Unpacked Size

30.6 kB

Total Files

13

Last publish

Collaborators

  • fgsreally