https://github.com/windmillcode/peerdart
Peerjs Dart implementation
https://github.com/windmillcode/peerdart
Last synced: 11 months ago
JSON representation
Peerjs Dart implementation
- Host: GitHub
- URL: https://github.com/windmillcode/peerdart
- Owner: WindMillCode
- License: mit
- Created: 2024-05-27T13:53:23.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-17T20:17:34.000Z (over 1 year ago)
- Last Synced: 2025-05-07T19:58:17.805Z (11 months ago)
- Language: Go
- Size: 514 KB
- Stars: 7
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://peerjs.com/docs).
* supports socketio connections
* sends chunks based on maxMessageSize from local and remote session descriptions
## Status
- [x] Alpha: Under heavy development
- [x] Public Alpha: Ready for testing. But go easy on us, there will be bugs and missing functionality.
- [x] Public Beta: Stable. No breaking changes expected in this version but possible bugs. (media is public alpha)
- [ ] Public: Production-ready
## Setup
**Create a Peer**
```dart
final Peer peer = Peer(options:PeerOptions(
// debug: LogLevel.All,
));
final Peer peer = Peer(options:PeerOptions(
// debug: LogLevel.All,
clientType: "socketio",
host: "[YOUR SERVER DOMAIN]",
port: 9000,
secure: true));
```
## Data connections
**Connect**
```dart
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**
```dart
if (peer?.id == null) {
peer = Peer(options: APPENV.peerdart);
wait peer!.init();
}
peer!.on("connection", (DataConnection? conn) {
conn?.on("data", (dynamic data) async {
})
})
```
## Support
Works on android
## Reference
| Property | Type | Default Value | Description |
|-----------------|---------------------------------------------------------------------------|----------------------------------------|-----------------------------------------------------------------------------|
| `debug` | `LogLevel?` | `LogLevel.Disabled` | Log level for debugging. |
| `host` | `String?` | `util.CLOUD_HOST` | Host address of the PeerServer. |
| `port` | `int?` | `util.CLOUD_PORT` | Port on which the PeerServer is running. |
| `path` | `String?` | `"/"` | Path to the PeerServer. |
| `key` | `String?` | `Peer.DEFAULT_KEY` | API key for the PeerServer. |
| `token` | `String?` | `randomToken()` | Token used for authentication. |
| `config` | `dynamic` | `util.defaultConfig` | Configuration options for the RTC connection. |
| `secure` | `bool?` | `true` | Whether the connection should be secure (https/wss). |
| `pingInterval` | `int?` | `null` | Interval for sending ping messages to keep the connection alive. |
| `referrerPolicy`| `String?` | `"strict-origin-when-cross-origin"` | Referrer policy for the HTTP requests. |
| `clientType` | `"websocket" \| "socketio"` | `"websocket"` | Type of client to use for the connection. |
| `logFunction` | `void Function(LogLevel logLevel, dynamic args)?` | `null` | Custom log function. |
| `serializers` | `Map` | `{}` | Custom serializers for different data connection types. |
## Links
### [Documentation / API Reference](https://peerjs.com/docs/)
### [PeerServer](https://github.com/Judimax/peerjs-server/tree/PR-socketio-support)
## License
PeerDart is licensed under the [MIT License](./LICENSE).