peerdart_exp 0.0.3 copy "peerdart_exp: ^0.0.3" to clipboard
peerdart_exp: ^0.0.3 copied to clipboard

Simple peer-to-peer with WebRTC for Dart. PeerJS port for Flutter.

Highly experimental major clone of orignial PeerDart Package #

=> Credits to orignal authors , I'm simply striving to make it production ready :)

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 #

  • ✅ Alpha: Under heavy development
  • ✅ 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.).

Documentation / API Reference #

PeerServer #

License #

PeerDart is licensed under the MIT License.# peerdart_exp

4
likes
0
pub points
48%
popularity

Publisher

unverified uploader

Simple peer-to-peer with WebRTC for Dart. PeerJS port for Flutter.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

events_emitter, flutter_webrtc, http, uuid, web_socket_channel

More

Packages that depend on peerdart_exp