19 个版本
2.0.0-rc.0 | 2024 年 8 月 2 日 |
---|---|
2.0.0-beta.10 | 2024 年 7 月 31 日 |
2.0.0-beta.7 | 2024 年 5 月 30 日 |
2.0.0-beta.3 | 2024 年 3 月 21 日 |
2.0.0-alpha.0 | 2023 年 5 月 24 日 |
42 在 WebSocket 中
563 每月下载
57KB
304 行
将 WebSocket 服务器暴露给您的 Tauri 前端。
安装
此插件需要至少 1.75 的 Rust 版本
我们可以推荐三种一般的安装方法。
- 使用 crates.io 和 npm(最简单,需要您信任我们的发布管道已正常工作)
- 直接从 Github 使用 git 标签 / 修订哈希拉取源代码(最安全)
- 使用 Git 子模块将此仓库安装到您的 tauri 项目中,然后使用文件协议导入源代码(最安全,但使用不便)
通过将以下内容添加到您的 Cargo.toml
文件中安装核心插件
src-tauri/Cargo.toml
[dependencies]
tauri-plugin-websocket = "2.0.0-rc"
# alternatively with Git:
tauri-plugin-websocket = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
您可以使用您首选的 JavaScript 包管理器安装 JavaScript Guest 绑定
注意:由于大多数JavaScript包管理器无法从git单仓库安装包,我们为每个插件提供只读镜像。这使得安装选项2更易于使用。
pnpm add @tauri-apps/plugin-websocket
# or
npm add @tauri-apps/plugin-websocket
# or
yarn add @tauri-apps/plugin-websocket
# alternatively with Git:
pnpm add https://github.com/tauri-apps/tauri-plugin-websocket#v2
# or
npm add https://github.com/tauri-apps/tauri-plugin-websocket#v2
# or
yarn add https://github.com/tauri-apps/tauri-plugin-websocket#v2
用法
首先,您需要使用Tauri注册核心插件
src-tauri/src/main.rs
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_websocket::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
之后,所有插件的API都可通过JavaScript客座绑定使用
import WebSocket from "@tauri-apps/plugin-websocket";
const ws = await WebSocket.connect("wss://example.com");
await ws.send("Hello World");
await ws.disconnect();
贡献
接受PR。请在发起pull request之前务必阅读贡献指南。
合作伙伴
|
请访问我们的网站和Open Collective以获取赞助商的完整列表。
许可证
代码:© 2015 - 现在 - The Commons Conservancy的Tauri项目。
适用于适用的情况,MIT或MIT/Apache 2.0。
依赖项
~17–62MB
~1M SLoC