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

A way to send buffer in a stream #748

Closed
vj-abishek opened this issue Oct 19, 2020 · 4 comments
Closed

A way to send buffer in a stream #748

vj-abishek opened this issue Oct 19, 2020 · 4 comments

Comments

@vj-abishek
Copy link
Contributor

vj-abishek commented Oct 19, 2020

At the sender end, I'm using a package known as chunk-stream to chunk the data.

Sender

 fileReaderStream(FileList).pipe(chunk(16000)).pipe(peer);

My question:

Is there any way to listen for peer.on('stream') and access the data at the receiver end?
I need to receive the data in a stream, is that possible?

I'm transferring files in this example, not video/audio.

@jarretttaylor
Copy link

@vj-abishek You likely want to send the files over a DataChannel. These two responses may help guide you to a solution.
#409
#561

@vj-abishek
Copy link
Contributor Author

@jarretttaylor Do you know any package which converts TypedArray into a stream. Im gonna use streamSaver, which needs stream as an input.

@jarretttaylor
Copy link

@vj-abishek Unfortunately, we are well outside of my area of expertise, so I am likely not of much help. That being said, you might look into ReadableStream and see if it could be of some use.

@vj-abishek
Copy link
Contributor Author

vj-abishek commented Oct 21, 2020

Found a package which is used to share files.

Sender

import SimplePeerFiles from 'simple-peer-files'
const spf = new SimplePeerFiles()

  // peer is the SimplePeer object connection to receiver
spf.send(peer, 'myFileID', file).then(transfer => {
   transfer.on('progress', sentBytes => {
      console.log(sentBytes)
   })
    transfer.start()
})

Reciever

import SimplePeerFiles from 'simple-peer-files'
const spf = new SimplePeerFiles()

// peer is the SimplePeer object connection to sender
spf.receive(peer, 'myFileID').then(transfer => {
  transfer.on('progress', sentBytes => {
    console.log(sentBytes)
  })

  transfer.on('done', (file) => {
     console.log(URL.createObjectURL(file))
  });
})

Stream

spf.receive(peer, 'myFileID').then(transfer => {
 const fileStream = transfer.createReadStream()
// Do whatever you want with the stream
})

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

2 participants