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

Easy cross-platform WebRTC peer based mesh network for Flutter with a simple to implement signalling api.

WebRTC Mesh #

An easy cross-platform WebRTC mesh network api.

Features #

  • Cross-platform
  • Custom Signalling Server support (including Firestore)
  • Multiple Rooms
  • Data Channel streams
  • Automatic connection/disconnection handling

Usage #

Check the /example folder for a full example.

For a completed group chat example, check out WebRTCMesh-GC

A simple chat app example:

import 'package:flutter/material.dart';
import 'package:webrtc_mesh/webrtc_mesh.dart';

import 'firestore_signalling.dart';

class ChatScreen extends StatefulWidget {
  final String roomId;
  final WebRTCMesh webRTCMesh;

  ChatScreen({Key? key, required this.roomId})
      : webRTCMesh = WebRTCMesh<FirestoreSignalling>(
          roomID: 'roomId',
          signallingCreator: (roomId, localPeerID) =>
              FirestoreSignalling(roomId: roomId, localPeerID: localPeerID),
        ),
        super(key: key);

  @override
  State<ChatScreen> createState() => _ChatScreenState();
}

class _ChatScreenState extends State<ChatScreen> {
  final _messages = <Message>[];
  final TextEditingController _textController = TextEditingController();

  @override
  void dispose() {
    super.dispose();
    widget.webRTCMesh.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          Expanded(
            child: StreamBuilder<Message>(
              stream: widget.webRTCMesh.messageStream.stream,
              builder: (context, snapshot) {
                if (snapshot.hasError) {
                  return Center(
                    child: Text('Error: ${snapshot.error}'),
                  );
                }

                if (!snapshot.hasData) {
                  return const Center(
                    child: Text('No messages yet'),
                  );
                }

                _messages.add(snapshot.data!);

                return ListView.builder(
                  itemCount: _messages.length,
                  itemBuilder: (BuildContext context, int index) {
                    final message = _messages[index];
                    return ListTile(
                      title: Text(message.message ?? ''),
                      subtitle: Text(message.from),
                      trailing: Text(message.type),
                    );
                  },
                );
            )
          ),
        ],
      ),
    );
  }
}

Additional information #

This is an overview of the signalling for WebRTC Mesh network protocol.

WebRTC Signalling

5
likes
120
pub points
0%
popularity

Publisher

unverified uploader

Easy cross-platform WebRTC peer based mesh network for Flutter with a simple to implement signalling api.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

GPL-3.0 (LICENSE)

Dependencies

flutter, flutter_webrtc, uuid

More

Packages that depend on webrtc_mesh