#websocket-server #tauri-plugin #tauri-app #front-end #expose #protocols #secure

sys tauri-plugin-websocket

将 WebSocket 服务器暴露给您的 Tauri 前端

19 个版本

2.0.0-rc.02024 年 8 月 2 日
2.0.0-beta.102024 年 7 月 31 日
2.0.0-beta.72024 年 5 月 30 日
2.0.0-beta.32024 年 3 月 21 日
2.0.0-alpha.02023 年 5 月 24 日

42WebSocket

Download history 44/week @ 2024-04-24 153/week @ 2024-05-01 20/week @ 2024-05-08 19/week @ 2024-05-15 39/week @ 2024-05-22 340/week @ 2024-05-29 37/week @ 2024-06-05 59/week @ 2024-06-12 28/week @ 2024-06-19 137/week @ 2024-06-26 88/week @ 2024-07-03 135/week @ 2024-07-10 53/week @ 2024-07-17 61/week @ 2024-07-24 321/week @ 2024-07-31 119/week @ 2024-08-07

563 每月下载

Apache-2.0 OR MIT

57KB
304

plugin-websocket

将 WebSocket 服务器暴露给您的 Tauri 前端。

安装

此插件需要至少 1.75 的 Rust 版本

我们可以推荐三种一般的安装方法。

  1. 使用 crates.io 和 npm(最简单,需要您信任我们的发布管道已正常工作)
  2. 直接从 Github 使用 git 标签 / 修订哈希拉取源代码(最安全)
  3. 使用 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之前务必阅读贡献指南。

合作伙伴

CrabNebula

请访问我们的网站Open Collective以获取赞助商的完整列表。

许可证

代码:© 2015 - 现在 - The Commons Conservancy的Tauri项目。

适用于适用的情况,MIT或MIT/Apache 2.0。

依赖项

~17–62MB
~1M SLoC