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

recompose readStream and play it afer sending via ipc #971

Closed
rafaelleru opened this issue Nov 5, 2016 · 6 comments
Closed

recompose readStream and play it afer sending via ipc #971

rafaelleru opened this issue Nov 5, 2016 · 6 comments

Comments

@rafaelleru
Copy link

@rafaelleru rafaelleru commented Nov 5, 2016

If I send every data of file as readStream throught ipc message, how I can play this data into client side of electron (the renderer procces reading this data from the live stream). I'm sending data like this:
readstream = file.createReadStream(); readstream.on('data', function(chunk){ ipc.send('play', data); }

so in the renderer I have a constant flow of data that I don't know how to recompose. Whats the better form for do this?

@xuset

This comment has been minimized.

Copy link

@xuset xuset commented Nov 5, 2016

You can use the render-media package to convert the stream into an audio/video element. That's what webtorrent uses for the file.appendTo and file.renderTo methods.

Alternatively, it may just be easier to run webtorrent in the browser side of electron, not the nodejs side, but depending on your use case this may not be an option.

Hope this helps!

@rafaelleru

This comment has been minimized.

Copy link
Author

@rafaelleru rafaelleru commented Nov 5, 2016

I just show your response and it's sound good but can you hel me a bit more with the recompose of the stream. I can not find any information about load the incomming chunk into a new stream on the renderer side.

@xuset

@xuset

This comment has been minimized.

Copy link

@xuset xuset commented Nov 6, 2016

@rafaelleru I'm not too familiar with streams, but it seems like you'll have to create a Readable stream on the render side, and when you receive the ipc data, send the data to the stream with stream.push(...)

@rafaelleru

This comment has been minimized.

Copy link
Author

@rafaelleru rafaelleru commented Nov 7, 2016

I'm still having problems with this because in the file object creation I can't make the render method to works. I'm trying to set the createReadableStream property to my stream of data, that I receibe from ipc but it gives me an excepcion that says it's undefined. My code looks like:

`
`ipc.on('addData',` (event, data) => {
    stream_data.push(data, 'utf8');
})

ipc.on('toPlay', (event, data) => {
    console.log('toPlay: ' + data[0]);
    var file = {
    name: data[0],
    createReadStream: function(){
        return stream_data;
    }
    }

    render.append(file, 'body', function(err, elem){
    if(err)
        return console.log('error appending file');

    return console.log(elem);
    });
})`

and vars are initialized in the begining of the jd file. @xuset any help with this¿

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jan 23, 2017

@rafaelleru I think the best way for you to accomplish what you're trying to do is to use torrent.createServer() to start an http server in the main process. Then you can just use IPC to send the server URL to the renderer process. Then you can set it as the src attribute on the video tag. This solution ensures that seeking is supported, since the tag will make a new HTTP request with the proper range headers, and it's a lot simpler than what you're trying to do right now. This is the approach that we use in WebTorrent Desktop, for what it's worth.

@feross feross closed this Jan 23, 2017
@lock

This comment has been minimized.

Copy link

@lock lock bot commented May 4, 2018

This thread has been automatically locked because it has not had recent activity. To discuss futher, please open a new issue.

@lock lock bot locked as resolved and limited conversation to collaborators May 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.