Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
faizatflutter opened this issue Apr 6, 2022 · 4 comments

Comments

@faizatflutter
Copy link

No description provided.

@abhay-s-rawat
Copy link

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
Copy link

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
Copy link

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
Copy link

IPODG commented Sep 12, 2022

Did anyone get this working?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants