@lytejs/ws
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

Websocket Plus

This provides an HTTP similar API for using Websockets in Node/Browser.

Example

// Sending Message
const wsp = new WebSocket(socket)
wsp.client.post('/friend-request', { body: {
  userId: 'johndoe'
}})


// Receiving Message
const wsp = new WebSocket(socket)
wsp.router.post('/friend-request', (req, res) => {
  const userId = req.data.userId
  wsp.client.post('/friend-request', {
    body: {
      senderId: socket.id
    },
    socketId: userId
  })
})

// Receiving Message on the receiver browser

const wsp = new WebSocket(socket)
wsp.router.post('/friend-request', (req, res) => {
  const userId = req.data.userId
  // Show friend request popup using req.data
  res.status(200)
})

Template

Readme

Keywords

none

Package Sidebar

Install

npm i @lytejs/ws

Weekly Downloads

0

Version

1.0.5

License

ISC

Unpacked Size

44 kB

Total Files

17

Last publish

Collaborators

  • bugwheels94