vpeer 0.1.0 copy "vpeer: ^0.1.0" to clipboard
vpeer: ^0.1.0 copied to clipboard

A peer-to-peer with WebRTC

VPeer: A peer-to-peer with WebRTC #

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

It the design of peerjs. Find the documentation here.

Usage #

Create a Peer

final Peer peer = Peer("random-gen-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;
        });
    });
});

Support #

Works on mobile and chrome browsers.

License #

Licensed under the MIT License.

0
likes
130
points
0
downloads

Publisher

verified publishervieaura.com

Weekly Downloads

A peer-to-peer with WebRTC

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

events_emitter, flutter_webrtc, http, uuid, web_socket_channel

More

Packages that depend on vpeer