FLUTTER ECOSYSTEM

MuhammedKpln/peerdart

适用于 Dart 的简单点对点 WebRTC。PeerDart 与 peerjs 的设计保持一致。

peerdart 项目封面
Stars
82
Forks
37
最近推送(UTC)
2025年4月10日
项目状态
未归档
Muhammed Kaplan GitHub avatar
GITHUB User

Muhammed Kaplan ↗

Stockholm, Sweden官方网站 ↗
语言DartCMakeC++RubyHTMLSwiftCKotlinObjective-C

技术话题

此仓库发布的插件

使用的依赖

依赖清单 8 项

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

展开 / 收起项目 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.