跳到内容
Tauri

@tauri-apps/plugin-websocket

默认

构造函数

new default()
new default(id, listeners): default
参数
参数类型
idnumber
listenersSet<(arg) => void>
返回

默认

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/websocket/guest-js/index.ts#L63

属性

属性类型定义于
idnumberSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/websocket/guest-js/index.ts#L60

方法

addListener()
addListener(cb): () => void
参数
参数类型
cb(arg) => void
返回

函数

返回

void

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/websocket/guest-js/index.ts#L92

disconnect()
disconnect(): Promise<void>
返回

Promise<void>

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/websocket/guest-js/index.ts#L119

send()
send(message): Promise<void>
参数
参数类型
messagestring | number[] | Message
返回

Promise<void>

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/websocket/guest-js/index.ts#L100

connect()
static connect(url, config?): Promise<default>
参数
参数类型
urlstring
config?ConnectionConfig
返回

Promise<default>

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/websocket/guest-js/index.ts#L68

接口

CloseFrame

属性

属性类型定义于
codenumberSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/websocket/guest-js/index.ts#L48
reasonstringSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/websocket/guest-js/index.ts#L49

ConnectionConfig

属性

属性类型描述定义于
acceptUnmaskedFrames?boolean当设置为 true 时,服务器将接受并处理来自客户端的未掩码帧。根据 RFC 6455,服务器必须在这种情况下关闭与客户端的连接,但是,似乎有一些流行的库正在发送未掩码帧,忽略了 RFC。默认情况下,此选项设置为 false,即根据 RFC 6455。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/websocket/guest-js/index.ts#L35
headers?HeadersInit附加的连接请求标头。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/websocket/guest-js/index.ts#L39
maxFrameSize?number | "none"单个传入消息帧的最大大小。字符串“none”表示没有大小限制。该限制是针对帧负载,不包括帧头。默认值为 16 MiB,对于所有正常用例来说应该足够大,但又足够小,可以防止恶意用户占用内存。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/websocket/guest-js/index.ts#L31
maxMessageSize?number | "none"传入消息的最大大小。字符串“none”表示没有大小限制。默认值为 64 MiB,对于所有正常用例来说应该足够大,但又足够小,可以防止恶意用户占用内存。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/websocket/guest-js/index.ts#L27
maxWriteBufferSize?number写入缓冲区最大大小(字节)。设置此值可以在写入缓冲区因写入错误而填满时提供背压。默认值是无限制。注意:只有在写入底层流失败时,写入缓冲区才会超过 write_buffer_size 累积。因此,如果您没有观察到写入错误,写入缓冲区就不会填满。注意:应始终至少为 write_buffer_size + 1 条消息,并且可能需要更多,具体取决于错误处理策略。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/websocket/guest-js/index.ts#L23
readBufferSize?number读取缓冲区容量。默认值为 128 KiB。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/websocket/guest-js/index.ts#L11
writeBufferSize?number写入缓冲区在将数据写入底层流之前要达到的目标最小大小。默认值为 128 KiB。如果设置为 0,则每条消息都将立即写入底层流。通常,允许它们缓冲一点会更优化,因此默认值为该值。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/websocket/guest-js/index.ts#L16

MessageKind<T, D>

类型参数

类型参数
T
D

属性

属性类型定义于
dataDSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/websocket/guest-js/index.ts#L44
typeTSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/websocket/guest-js/index.ts#L43

类型别名

Message

type Message:
| MessageKind<"Text", string>
| MessageKind<"Binary", number[]>
| MessageKind<"Ping", number[]>
| MessageKind<"Pong", number[]>
| MessageKind<"Close", CloseFrame | null>;

Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/websocket/guest-js/index.ts#L52


© 2025 Tauri 贡献者。CC-BY / MIT