@adonisjs/websocket-packet

中文文档
1.0.6发布于 2018/03/14MITESM + CJS零依赖近 30 天下载 7361

Verify,create adonis websocket packets

原始使用文档
文档目录30 节
  1. Installation
  2. Node/Webpack
  3. CDN
  4. Constants
  5. Functions
  6. codes : Object
  7. fns
  8. isJoinPacket(packet) ⇒ Boolean
  9. isLeavePacket(packet) ⇒ Boolean
  10. isOpenPacket(packet) ⇒ Boolean
  11. isJoinAckPacket(packet) ⇒ Boolean
  12. isJoinErrorPacket(packet) ⇒ Boolean
  13. isLeaveAckPacket(packet) ⇒ Boolean
  14. isLeaveErrorPacket(packet) ⇒ Boolean
  15. isEventPacket(packet) ⇒ Boolean
  16. isPingPacket(packet) ⇒ Boolean
  17. isPongPacket(packet) ⇒ Boolean
  18. hasTopic(packet) ⇒ Boolean
  19. isValidJoinPacket() ⇒ Boolean
  20. isValidLeavePacket() ⇒ Boolean
  21. isValidEventPacket() ⇒ Boolean
  22. joinPacket(topic) ⇒ Object
  23. leavePacket(topic) ⇒ Object
  24. joinAckPacket(topic) ⇒ Object
  25. joinErrorPacket(topic, message) ⇒ Object
  26. leaveAckPacket(topic) ⇒ Object
  27. leaveErrorPacket(topic, message) ⇒ Object
  28. eventPacket(topic, event, data) ⇒ Object
  29. pingPacket() ⇒ Object
  30. pongPacket() ⇒ Object

Websocket packets

This library is used to create/validate the websocket packets used by AdonisJs.

If you are writing a Javascript client, this is the library you must use. When writing client libraries for other platforms, simply follow the docs and the code to create your implementations.

Travis

Installation

Node/Webpack

npm i --save @adonisjs/websocket-packet
const wsp = require('@adonisjs/websocket-packet')

// or
import wsp from '@adonisjs/websocket-packet'

console.log(wsp.codes)
wsp.isJoinPacket(packet)

CDN

<script src="https://unpkg.com/@adonisjs/websocket-packet"></script>
<script type="text/javascript">
  console.log(adonis.wsp.codes)
  console.log(adonis.wsp.isJoinPacket(packet))
</script>

Constants

codes : Object

Packet codes. The actual packet will have the numbers

fns

Fns to be exported

Functions

isJoinPacket(packet) ⇒ Boolean

Validates if packet code is a JOIN code.

isLeavePacket(packet) ⇒ Boolean

Validates if packet code is a LEAVE code.

isOpenPacket(packet) ⇒ Boolean

Validates if packet code is a OPEN code.

isJoinAckPacket(packet) ⇒ Boolean

Validates if packet code is a JOIN_ACK code.

isJoinErrorPacket(packet) ⇒ Boolean

Validates if packet code is a JOIN_ERROR code.

isLeaveAckPacket(packet) ⇒ Boolean

Validates if packet code is a LEAVE_ACK code.

isLeaveErrorPacket(packet) ⇒ Boolean

Validates if packet code is a LEAVE_ERROR code.

isEventPacket(packet) ⇒ Boolean

Validates if packet code is a EVENT code.

isPingPacket(packet) ⇒ Boolean

Validates if packet code is a PING code.

isPongPacket(packet) ⇒ Boolean

Validates if packet code is a PONG code.

hasTopic(packet) ⇒ Boolean

Finding if a packet has a topic.

isValidJoinPacket() ⇒ Boolean

Makes sure packet is a valid join packet. Do call isJoinPacket before calling this method.

isValidLeavePacket() ⇒ Boolean

Makes sure packet is a valid leave packet. Do call isLeavePacket before calling this method.

isValidEventPacket() ⇒ Boolean

Makes sure packet is a valid event packet. Do call isEventPacket before calling this method.

joinPacket(topic) ⇒ Object

Makes a join packet

leavePacket(topic) ⇒ Object

Makes a leave packet

joinAckPacket(topic) ⇒ Object

Makes join acknowledge packet

joinErrorPacket(topic, message) ⇒ Object

Makes join error packet

leaveAckPacket(topic) ⇒ Object

Makes leave packet

leaveErrorPacket(topic, message) ⇒ Object

Makes leave error packet

eventPacket(topic, event, data) ⇒ Object

Makes the event packet

pingPacket() ⇒ Object

Makes ping packet

pongPacket() ⇒ Object

Makes pong packet

codes : Object

Packet codes. The actual packet will have the numbers

Kind: global constant
Example

{
 OPEN: 0,
 JOIN: 1,
 LEAVE: 2,
 JOIN_ACK: 3,
 JOIN_ERROR: 4,
 LEAVE_ACK: 5,
 LEAVE_ERROR: 6,
 EVENT: 7,
 PING: 8,
 PONG: 9
}

fns

Fns to be exported

Kind: global constant

isJoinPacket(packet) ⇒ Boolean

Validates if packet code is a JOIN code.

Kind: global function

ParamType
packetObject

isLeavePacket(packet) ⇒ Boolean

Validates if packet code is a LEAVE code.

Kind: global function

ParamType
packetObject

isOpenPacket(packet) ⇒ Boolean

Validates if packet code is a OPEN code.

Kind: global function

ParamType
packetObject

isJoinAckPacket(packet) ⇒ Boolean

Validates if packet code is a JOIN_ACK code.

Kind: global function

ParamType
packetObject

isJoinErrorPacket(packet) ⇒ Boolean

Validates if packet code is a JOIN_ERROR code.

Kind: global function

ParamType
packetObject

isLeaveAckPacket(packet) ⇒ Boolean

Validates if packet code is a LEAVE_ACK code.

Kind: global function

ParamType
packetObject

isLeaveErrorPacket(packet) ⇒ Boolean

Validates if packet code is a LEAVE_ERROR code.

Kind: global function

ParamType
packetObject

isEventPacket(packet) ⇒ Boolean

Validates if packet code is a EVENT code.

Kind: global function

ParamType
packetObject

isPingPacket(packet) ⇒ Boolean

Validates if packet code is a PING code.

Kind: global function

ParamType
packetObject

isPongPacket(packet) ⇒ Boolean

Validates if packet code is a PONG code.

Kind: global function

ParamType
packetObject

hasTopic(packet) ⇒ Boolean

Finding if a packet has a topic.

Kind: global function

ParamType
packetObject

isValidJoinPacket() ⇒ Boolean

Makes sure packet is a valid join packet. Do call isJoinPacket before calling this method.

Kind: global function

isValidLeavePacket() ⇒ Boolean

Makes sure packet is a valid leave packet. Do call isLeavePacket before calling this method.

Kind: global function

isValidEventPacket() ⇒ Boolean

Makes sure packet is a valid event packet. Do call isEventPacket before calling this method.

Kind: global function

joinPacket(topic) ⇒ Object

Makes a join packet

Kind: global function
Throws:

  • Error If topic is not defined or not a string
ParamType
topicString

leavePacket(topic) ⇒ Object

Makes a leave packet

Kind: global function
Throws:

  • Error If topic is not defined or not a string
ParamType
topicString

joinAckPacket(topic) ⇒ Object

Makes join acknowledge packet

Kind: global function
Throws:

  • Error If topic is not defined or is not a string
ParamType
topicString

joinErrorPacket(topic, message) ⇒ Object

Makes join error packet

Kind: global function
Throws:

  • Error If topic is not defined or not a string
  • Error If message is not defined or not a string
ParamType
topicString
messageString

leaveAckPacket(topic) ⇒ Object

Makes leave packet

Kind: global function
Throws:

  • Error If topic is not defined or not a string
ParamType
topicString

leaveErrorPacket(topic, message) ⇒ Object

Makes leave error packet

Kind: global function
Throws:

  • Error If topic is not defined or not a string
  • Error If message is not defined or not a string
ParamType
topicString
messageString

eventPacket(topic, event, data) ⇒ Object

Makes the event packet

Kind: global function
Throws:

  • Error If topic is not defined or not a string
  • Error If event is not defined
  • Error If data is not defined
ParamType
topicString
eventString
dataMixed

pingPacket() ⇒ Object

Makes ping packet

Kind: global function

pongPacket() ⇒ Object

Makes pong packet

Kind: global function

版本与发布记录

@adonisjs/websocket-packet 共发布 7 个版本,首次发布于 2018/02/20;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.6latest2018/03/148 年前
1.0.52018/03/118 年前
1.0.42018/03/068 年前
1.0.32018/02/278 年前
1.0.22018/02/258 年前
1.0.12018/02/208 年前

关于 @adonisjs/websocket-packet 的常见问题

@adonisjs/websocket-packet 是什么?

Verify,create adonis websocket packets

如何安装 @adonisjs/websocket-packet?

在项目目录运行 npm install @adonisjs/websocket-packet,或使用 pnpm add / yarn add / bun add。

@adonisjs/websocket-packet 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/adonisjs__websocket-packet 是否存在。

@adonisjs/websocket-packet 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@adonisjs/websocket-packet 可以商用吗?

@adonisjs/websocket-packet 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@adonisjs/websocket-packet 的下载量有多少?

根据 npm 官方下载统计,@adonisjs/websocket-packet 在 2026/10/05 – 2026/11/03 这 30 天内被下载 7,361 次,日均约 245 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adonisjs/websocket-packet 还在维护吗?

最新版本 1.0.6 发布于 2018/03/14(8 年前);至今共发布 7 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/02/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。