update readme

multipeer_ios
Prerak Mann 5 years ago
parent baffb9816c
commit f08cfbc963

@ -1,10 +1,20 @@
# nearby_connections # nearby_connections
An android flutter plugin for the Nearby Connections API An **android** flutter plugin for the Nearby Connections API
[![pub package](https://img.shields.io/pub/v/nearby_connections.svg)](https://pub.dartlang.org/packages/nearby_connections) [![pub package](https://img.shields.io/pub/v/nearby_connections.svg)](https://pub.dartlang.org/packages/nearby_connections)
## Getting Started ## Table of Content
* [Setup](#setup)
* [Work Flow](#Work%20Flow)
* [Advertise For connections](#Advertise%20for%20connection)
* [Discover Advertisers](#Discover%20Advertisers)
* [Request Connection](#Request%20Connection)
* [Accept Connection](#Accept%20Connection)
* [Sending Data](#Sending%20Data)
* [Senging Bytes Payload](#Sending%20Bytes%20Payload)
## Setup
### Set Permissions ### Set Permissions
Add these to AndroidManifest.xml Add these to AndroidManifest.xml
@ -28,11 +38,11 @@ bool a = await Nearby().checkPermissions()
Nearby().askPermission() Nearby().askPermission()
``` ```
### Working Flow ## Work Flow
The working flow is similar to the [android nearby connections library](https://developers.google.com/nearby/connections/overviewoverview) The work flow is similar to the [android nearby connections library](https://developers.google.com/nearby/connections/overviewoverview)
#### Advertise for connection ### Advertise for connection
```dart ```dart
try { try {
bool a = await Nearby().startAdvertising( bool a = await Nearby().startAdvertising(
@ -52,7 +62,7 @@ try {
// platform exceptions like unable to start bluetooth or insufficient permissions // platform exceptions like unable to start bluetooth or insufficient permissions
} }
``` ```
#### Discover Advertisers ### Discover Advertisers
```dart ```dart
try { try {
bool a = await Nearby().startDiscovery( bool a = await Nearby().startDiscovery(
@ -69,11 +79,14 @@ try {
// platform exceptions like unable to start bluetooth or insufficient permissions // platform exceptions like unable to start bluetooth or insufficient permissions
} }
``` ```
#### Start and Stop Discovery ### Stopping Advertising and Discovery
```dart ```dart
Nearby().stopAdvertising(); Nearby().stopAdvertising();
Nearby().stopDiscovery(); Nearby().stopDiscovery();
// endpoints already discovered will still be available to connect
// even after stopping discovery
// You should stop discovery once you have found the intended advertiser
// this will reduce chances for disconnection
``` ```
### Request Connection ### Request Connection
```dart ```dart
@ -94,7 +107,7 @@ try{
// called if request was invalid // called if request was invalid
} }
``` ```
#### Accept Connections ### Accept Connection
```dart ```dart
Nearby().acceptConnection( Nearby().acceptConnection(
id, id,
@ -103,7 +116,8 @@ Nearby().acceptConnection(
}, },
); );
``` ```
### Sending Payload ## Sending Data
### Sending Bytes Payload
```dart ```dart
Nearby().sendPayload(endpointId, bytes_array); Nearby().sendPayload(endpointId, bytes_array);

@ -4,6 +4,11 @@ import 'dart:typed_data';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
/// **P2P_CLUSTER** - best for small payloads and multiplayer games
///
/// **P2P_STAR** - best for medium payloads, higher bandwidth than cluster
///
/// **P2P_POINT_TO_POINT** - single connection, very high bandwidth
enum Strategy { P2P_CLUSTER, P2P_STAR, P2P_POINT_TO_POINT } enum Strategy { P2P_CLUSTER, P2P_STAR, P2P_POINT_TO_POINT }
enum Status { CONNECTED, REJECTED, ERROR } enum Status { CONNECTED, REJECTED, ERROR }
@ -17,7 +22,7 @@ typedef void OnEndpointFound(
typedef void OnEndpointLost(String endpointId); typedef void OnEndpointLost(String endpointId);
typedef void OnPayloadReceived(String endpointId, Uint8List bytes); typedef void OnPayloadReceived(String endpointId, Uint8List bytes);
// typedef void OnPayloadTransferUpdate();
/// The NearbyConnection class /// The NearbyConnection class
/// ///
/// Only one instance is maintained /// Only one instance is maintained
@ -330,7 +335,7 @@ class Nearby {
/// ///
/// [endPointName] is userNickName of requester /// [endPointName] is userNickName of requester
/// ///
/// [authenticationToken] is useful to check the connection security /// [authenticationToken] can be used to check the connection security
/// it must be same on both devices /// it must be same on both devices
class ConnectionInfo { class ConnectionInfo {
String endpointName, authenticationToken; String endpointName, authenticationToken;

Loading…
Cancel
Save