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

Electron renderTo #1068

Closed
memeone opened this issue Mar 2, 2017 · 2 comments
Closed

Electron renderTo #1068

memeone opened this issue Mar 2, 2017 · 2 comments

Comments

@memeone
Copy link

@memeone memeone commented Mar 2, 2017

I'm trying to render a torrent to a browser window in electron. I am running webtorrent in the main process and accessing it through a remote. When trying to render to my browserwindow with this code running in the render thread (the browserwindow)

var {remote} = require('electron');
var main = remote.require('./src/index.js');

var ipc = require('electron').ipcRenderer;
var file;

ipc.on('openFile' , function(event , magnet){
	console.log(magnet);
	var torrent = main.webtorrent.get(magnet);
	console.log(torrent);
	file = torrent.files[0];
	file.renderTo('#player')
});

Main thread code:

var WebTorrent = require('webtorrent');
var client = new WebTorrent();
...
exports.openviewer = (magnet) => {
  win_viewer = new BrowserWindow({width: 1280, height: 720});

  win_viewer.loadURL(url.format({
    pathname: path.join(__dirname, '/views/viewer.html'),
    protocol: 'file:',
    slashes: true
  }));

  win_viewer.webContents.on('dom-ready', () => {
    win_viewer.webContents.send('openFile' , magnet);
  });


  win_viewer.on('close', () => {
    win_viewer = null;
  });
  exports.win_viewer = win_viewer;
};

Error emitted in the render thread:

Uncaught Error: Could not call remote function ''. Check that the function signature is correct. Underlying error: browser-only method
Error: Could not call remote function ''. Check that the function signature is correct. Underlying error: browser-only method
    at callFunction (/usr/local/lib/node_modules/electron/dist/resources/electron.asar/browser/rpc-server.js:235:11)
    at EventEmitter.<anonymous> (/usr/local/lib/node_modules/electron/dist/resources/electron.asar/browser/rpc-server.js:342:5)
    at emitMany (events.js:127:13)
    at EventEmitter.emit (events.js:201:7)
    at WebContents.<anonymous> (/usr/local/lib/node_modules/electron/dist/resources/electron.asar/browser/api/web-contents.js:231:13)
    at emitTwo (events.js:106:13)
    at WebContents.emit (events.js:191:7)
@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Mar 7, 2017

I doubt that Electron's remote package will work correctly in this case. A better way (and what we do in WebTorrent Desktop) is to use torrent.createServer().

If you call torrent.createServer() in your main process, then you can just add a <video> tag in the renderer that points to the local http server which will serve the video.

<!-- Plays the first file in the torrent -->
<video src="http://localhost:<port>/0" />
@feross feross closed this Mar 7, 2017
@lock

This comment has been minimized.

Copy link

@lock lock bot commented May 3, 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 3, 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
2 participants
You can’t perform that action at this time.