This plugin allows Flutter apps to use WebRTC DataChannel to establish P2P connection and exchange text messages.
Plugin dependency:
webrtc_data_channel: "^0.1.0"
WebRTC Android dependency:
rootProject.allprojects {
repositories {
maven {
url "https://google.bintray.com/webrtc"
}
}
}
dependencies {
api 'org.webrtc:google-webrtc:1.0.22672'
}
WebRTC iOS dependency:
pod 'GoogleWebRTC', '1.1.22642'
import 'package:webrtc_data_channel/webrtc_data_channel.dart';
// create DataChannel and connect to room
WebRTCDataChannel _dataChannel = new WebRTCDataChannel();
_dataChannel.connect(_roomUrl, _roomId);
// listen for messages
_receivedMessages = _dataChannel.listenMessages()
.listen((String message) {
// handle message
});
// send message
_dataChannel.sendMessage(message);
// disconnect from room
_dataChannel.disconnect();
This plugin use webrtc/apprtc as room server and signal server,
you can use https://appr.tc/
or deploy it yourself, I've a Docker image for it,
piasy/apprtc-server.
git clone https://github.com/Piasy/webrtc_data_channel
flutter create -t plugin webrtc_data_channel
cd webrtc_data_channel/example/ios && pod install