VNAPNIC / flutter_nearby_connections

Flutter plugin support peer-to-peer connectivity and the discovery of nearby devices for Android vs IOS
https://pub.dev/packages/flutter_nearby_connections
BSD 2-Clause "Simplified" License
109 stars 72 forks source link

Can we share file using this? There is only method for sending message. #41

Open faizatflutter opened 2 years ago

abhay-s-rawat commented 2 years ago

Actually you can send file. For large files you have to read them which will consume more memory, I guess the maxed allowed packet size is 1mb so break your file into chunks and send which will save ram also.

abhay-s-rawat commented 2 years ago

I forgot to tell use jsonEncode/Decode for conversion of your message to string. I created function below for my project.I used webrct data channel.


    final Completer completer = Completer();
    int start = (currentChunkId - 1) * Config.webrtcDataChannelChunkSize;
    int end = currentChunkId * Config.webrtcDataChannelChunkSize;
    if (end > mainModel.offerModel.fileSize) {
      end = mainModel.offerModel.fileSize;
    }
    List<int> data = [];
    Stream<List<int>> dataStream = mainModel.file.openRead(start, end);
    dataStream.listen((List<int> event) {
      data.addAll(event);
    }, onDone: () async {
      DCTransferModel model = DCTransferModel(
        fileId: mainModel.offerModel.fileId,
        chunkId: currentChunkId,
        //data: data,
        data: base64Encode(gzip.encode(data)),
      );
      await _dataChannel!.send(RTCDataChannelMessage(model.toJson));
      mainModel.progress.value =
          currentChunkId / mainModel.offerModel.totalChunks;
      completer.complete();
    });
    return completer.future;
  }```
serzhikdnepr commented 2 years ago

I forgot to tell use jsonEncode/Decode for conversion of your message to string. I created function below for my project.I used webrct data channel.

@abhay-s-rawat Can you provide a more detailed example?

IPODG commented 2 years ago

Did anyone get this working?