Git Product home page Git Product logo

peerdart's Introduction

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", null, (ev,_) => {
	conn.send("hi!");
});

Receive

peer.on("connection", null, (ev, _) => {
	conn.on("data", null, (event, _) => {
		// Will print 'hi!'
		console.log(event.eventData);
	});
	conn.on("open", null, () => {
		conn.send("hello!");
	});
});

Media calls

Call

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

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

    conn.on("stream", null, (ev, _) {
        _localRenderer.srcObject = ev.eventData as MediaConnection
        // Do some stuff with stream
});

Answer

peer.on("call", null, (ev, context) async {
    final call = ev.eventData as MediaConnection;
    final mediaStream = await navigator.mediaDevices
        .getUserMedia({"video": true, "audio": false});

    call.answer(mediaStream);

    call.on("stream", null, (ev, _) async {
    _localRenderer.srcObject = mediaStream;
    _remoteRenderer.srcObject = ev.eventData as MediaStream

    // Do some stuff.
    });
});

Support

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

Links

License

PeerDart is licensed under the MIT License.

peerdart's People

Contributors

muhammedkpln avatar

Stargazers

Roman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.