@discordjs/uws

中文文档
11.149.1发布于 2018/10/25ZlibCommonJS零依赖近 30 天下载 3185

Tiny WebSockets

此软件包已被标记为弃用

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

原始使用文档
文档目录4 节
  1. This fork is for internal usage in the discord.js library o…
  2. We will provide no support to anyone relying or using it ou…
  3. Keep in mind
  4. Usage

Fork of uws bindings for discord.js

This fork is for internal usage in the discord.js library only.

We will provide no support to anyone relying or using it outside of our main project.














Original README

UWS IS NOT AN ELECTRON MODULE

uws is a replacement module for ws which allows, but doesn't guarantee (certainly not when paired with Socket.IO), significant performance and memory-usage improvements. This module is specifically only compatible with Node.js and is installed only like so:

  • uws can use node-gyp and can recompile itself at installation but does not require so.
  • npm installation never fails, but require('uws') will throw if all of the below points hold true:
    • There was no C++11 compiler available at installation.
    • Your system is not an official Tier 1 Node.js platform.

Keep in mind

You can't fix a clogged up system by only fixing part of the problem. Swapping to uws can have dramatical effects if your entire pipeline works well. Socket.IO, SocketCluster and other such mass bloat will not give you desired results as those projects already, from the start, are the bottleneck.

Read more about other horrible Node.js projects here

Usage

uws tries to mimic ws as closely as possible without sacrificing too much performance. In most cases you simply swap require('ws') with require('uws'):

var WebSocketServer = require('uws').Server;
var wss = new WebSocketServer({ port: 3000 });

function onMessage(message) {
    console.log('received: ' + message);
}

wss.on('connection', function(ws) {
    ws.on('message', onMessage);
    ws.send('something');
});
Deviations from ws

There are some important incompatibilities with ws though, we aim to be ~90% compatible but will never implement behavior that is deemed too inefficient:

  • Binary data is passed zero-copy as an ArrayBuffer. This means you need to copy it to keep it past the callback. It also means you need to convert it with Buffer.from(message) if you expect a Node.js Buffer.
  • webSocket._socket is not a net.Socket, it is just a getter function with very basic functionalities.
  • webSocket._socket.remote... might fail, you need to cache it at connection.
  • webSocket acts like an EventEmitter with one listener per event maximum.
  • webSocket.upgradeReq is only valid during execution of the connection handler. If you want to keep properties of the upgradeReq for the entire lifetime of the webSocket you better attach that specific property to the webSocket at connection.

版本与发布记录

@discordjs/uws 共发布 5 个版本,首次发布于 2018/08/23;过去 12 个月发布了 0 个版本。

版本发布日期距今
11.149.1latest2018/10/258 年前
11.149.02018/10/248 年前
10.149.02018/08/248 年前
10.14.02018/08/238 年前
0.1.02018/08/238 年前

关于 @discordjs/uws 的常见问题

@discordjs/uws 是什么?

Tiny WebSockets注意:该包已被作者标记为弃用——Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

如何安装 @discordjs/uws?

在项目目录运行 npm install @discordjs/uws,或使用 pnpm add / yarn add / bun add。

@discordjs/uws 支持 TypeScript 吗?

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

@discordjs/uws 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@discordjs/uws 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=6.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@discordjs/uws 可以商用吗?

@discordjs/uws 使用 Zlib 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。修改后的版本需明确标注,不得冒充原版。以上为概括,不构成法律意见,请以许可原文为准。

@discordjs/uws 的下载量有多少?

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

@discordjs/uws 还在维护吗?

最新版本 11.149.1 发布于 2018/10/25(8 年前);至今共发布 5 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/08/23。作者已将其标记为弃用,新项目建议寻找替代方案。