windmillcode_peerdart 1.5.4031

SDKflutter
Platformandroidioswindowslinuxmacos

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

Windmillcode 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 (planned) media streams.

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

  • supports socketio connections
  • sends chunks based on maxMessageSize from local and remote session descriptions

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. (media is public alpha)
  • Public: Production-ready

Setup

Create a Peer

<!-- for development -->
final Peer peer = Peer(options:PeerOptions(
      // debug: LogLevel.All,
));
<!-- for production -->
final Peer peer = Peer(options:PeerOptions(
      // debug: LogLevel.All,
      clientType: "socketio",
      host: "[YOUR SERVER DOMAIN]",
      port: 9000,
      secure: true));

Data connections

Connect

var peer;
if (peer?.id == null) {
    peer = Peer(options: APPENV.peerdart);
    wait peer!.init();
}

var conn = webrtc.connect(res.data.result["sender_peer_id"]);
conn.on("open",(data) async {
    conn.send("hi!");
})

Receive

if (peer?.id == null) {
    peer = Peer(options: APPENV.peerdart);
    wait peer!.init();
}
peer!.on("connection", (DataConnection? conn) {
    conn?.on("data", (dynamic data) async {
        <!-- work with your data -->
    })
})

Support

Works on android

Reference

PropertyTypeDefault ValueDescription
debugLogLevel?LogLevel.DisabledLog level for debugging.
hostString?util.CLOUD_HOSTHost address of the PeerServer.
portint?util.CLOUD_PORTPort on which the PeerServer is running.
pathString?"/"Path to the PeerServer.
keyString?Peer.DEFAULT_KEYAPI key for the PeerServer.
tokenString?randomToken()Token used for authentication.
configdynamicutil.defaultConfigConfiguration options for the RTC connection.
securebool?trueWhether the connection should be secure (https/wss).
pingIntervalint?nullInterval for sending ping messages to keep the connection alive.
referrerPolicyString?"strict-origin-when-cross-origin"Referrer policy for the HTTP requests.
clientType"websocket" | "socketio""websocket"Type of client to use for the connection.
logFunctionvoid Function(LogLevel logLevel, dynamic args)?nullCustom log function.
serializersMap<String, DataConnection Function(String peerId, Peer provider, dynamic options)>{}Custom serializers for different data connection types.

Documentation / API Reference

PeerServer

License

PeerDart is licensed under the MIT License.