搜尋套件、儲存庫與 APP 分類

套件詳情v0.5.6

peerdart

適用於 Dart 的簡單點對點 WebRTC。Flutter 的 PeerJS 端口。

AndroidiOSmacOSWindowsLinux
近 30 天下載
481
喜歡數
78
Pub 分數
135

安裝套件

flutter pub add peerdart

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

peerdart 是一個 Dart 套件,可使用 WebRTC 實現簡單的點對點通訊,作為 PeerJS 的 Flutter 相容版本。它可在不需要中央伺服器進行路由的情況下,於裝置之間實時交換資料與媒體。專為低延遲連線設計,支援跨 Android、iOS、macOS、Windows 及 Linux 等多個平台的設備間直接通訊。適用於需要即時連接的應用,例如視訊通話、即時串流或協作工具。

適用情境

  • 即時視頻通話
  • 直播串流
  • 協作應用程式
  • 直接設備訊息
  • 基於 WebRTC 的聊天應用

主要特色

  • 基於 WebRTC 的點對點連接
  • 跨平台支援
  • 類似於 PeerJS 的簡單 API
  • 支援資料和媒體頻道
  • 自動 ICE/STUN 處理

適合對象

  • 在Flutter中構建即時應用的開發者
  • 需要直接設備通訊的項目
  • 針對多個作業系統的應用
  • 原型設計 WebRTC 功能
  • 低延遲的互動式體驗

使用建議

  • 需要網絡配置(防火牆/NAT)
  • 依賴信令伺服器進行連接設定
  • 有限的瀏覽器支援(僅限 Flutter)
  • 性能隨網路品質而變化
  • 可能需要TURN伺服器以實現NAT穿透

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

PeerDart: Simple peer-to-peer with WebRTC

PeerDart provides a complete, configurable, and easy-to-use peer-to-peer API built on top of WebRTC, supporting both data channels and media streams.

PeerDart mirrors the design of peerjs. Find the documentation here..

Status

  • [x] Alpha: Under heavy development
  • [x] Public Alpha: Ready for testing. But go easy on us, there will be bugs and missing functionality.
  • [ ] Public Beta: Stable. No breaking changes expected in this version but possible bugs.
  • [ ] Public: Production-ready

Live Example

Here's an example application that uses both media and data connections: Example

Setup

Create a Peer

final Peer peer = Peer("pick-an-id");
// You can pick your own id or omit the id if you want to get a random one from the server.

Data connections

Connect

const conn = peer.connect("another-peers-id");

conn.on("open").listen((name) {
    conn.send("hi!");
})

Receive

peer.on<DataConnection>("connection").listen((connection) {

    // On peer closed.
    conn.on("close").listen((event) {
        setState(() {
            connected = false;
        });
    });

    // ....
})

Media calls

Call

final mediaStream = await navigator.mediaDevices
        .getUserMedia({"video": true, "audio": false});

    final conn = peer.call("peerId", mediaStream);

    // Do some stuff with stream
    conn.on<MediaStream>("stream").listen((event) {
      _remoteRenderer.srcObject = event;
      _localRenderer.srcObject = mediaStream;

      setState(() {
        inCall = true;
      });
    });
});

Answer

peer.on<MediaConnection>("call").listen((call) async {
    final mediaStream = await navigator.mediaDevices
        .getUserMedia({"video": true, "audio": false});

    call.answer(mediaStream);


    // on peer closed
    call.on("close").listen((event) {
        setState(() {
            inCall = false;
        });
    });

    // Get peer stream
    call.on<MediaStream>("stream").listen((event) {
        _localRenderer.srcObject = mediaStream;
        _remoteRenderer.srcObject = event;

        setState(() {
            inCall = true;
        });
    });
});

More examples

See more at example.

Support

Works both on mobile and web browsers (Chrome tested.).

Links

Documentation / API Reference
PeerServer

License

PeerDart is licensed under the MIT License.

所屬分類

依賴

依賴清單 5 項

原始碼儲存庫

使用此套件的專案