(mis)Using Electron

 

 

 

on your server

Client - Server Network

P2P Network

Servers can crash

Peer networks

don't crash

Hello WebFlight

WebTorrent

P2P in the browser!

What we know

  • We can share files between browsers
  • Those files need to be torrent-able
  • We need a browser to start initial seeding

How to put a browser on our server?

Hello Electron 

Node.js

+ Chromium

 

Electron App Architecture

Browser

Renderer

Modules

Basic App Structure

test-app/
├── package.json
├── main.js
├── mystyles.css
└── index.html

main.js

const electron = require('electron')
const app = electron.app
const fs = require('fs')
const myFile = require('./myFile.txt')

const BrowserWindow = electron.BrowserWindow



function createWindow () {
  mainWindow = new BrowserWindow({
        width: 800, 
        height: 600, 
        webPreferences: { nodeenabled: false }
    })

  mainWindow.loadURL('file://' + __dirname + '/index.html') 
}



app.on('ready', createWindow)

Execute

$ electron myapp/

Main Process

Render process 1

Render process 2

Some downsides :-(

  • V8 compatibility between Node & Electron
  • Memory management
  • Security

Many projects

use Electron!

How WebFlight

uses Electron

(Electron Shell)

Original HTML

<!---original tag --->
<img id='large-image' src='/assets/media/img/bird1.jpg'>
<!---torrented tag --->
<img id='large-image' class='23897389asdfjkl9845'>

WebFlight's HTML

Electron's main.js seed script

  client.seed('/assets/media/img/bird1.jpg', function(torrent) {
      console.log('now seeding ', torrent.files[0].name)
    })


  client.seed('/assets/media/mov/birds-flying.mp4', function(torrent) {
      console.log('now seeding ', torrent.files[0].name)
    })

Electron as Child Process

const electron = require('electron-spawn')
const spawn = electron('/path/to/seedScript', {detached: true})

spawn.sdterr.on('error', (err) => {
  console.err('error spawning ', err.toString())
})

spawn.stdout.on('data', (data) => {
  console.log('seeding files ', data.toString())
})

Electron is a browser

with no sandbox!

Jared Fowler

@jared_fowler

     @10000highfives 

webflight.io

 

Thank you

Made with Slides.com