mafintosh / hypervision

P2P Television

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

'Go live' does not work on windows.

vibern0 opened this issue · comments

I had other problems, I dont know if it's related or not to #32
I inserted an win.webContents.openDevTools() to see the output when I click on Go live and the error was Uncaught Error: route 'C:/broadcast' did not match. So I went to home.js (line 38) and changed to ./brodcast, then the error was Uncaught Error: route 'C:/Users/*/Documents/GitHub/hypervision/broadcast' did not match. So, again I changed to ./components/broadcast and the error is the same, just different directory Uncaught Error: route 'C:/Users/*/Documents/GitHub/hypervision/components/broadcast' did not match. I even tried to change to ./components/broadcast.js but I got nothing.

Great stuff. Any plans soon to support WIN?

commented

@obernardovieira @gjovanov thanks for you patience with this. I'm going to try spinning up a Windows installation very soon and attempt to fix this issue for you! :)

One possible way to fix the routes I came across is intercepting file:// requests, removing the file: identifier, and normalizing the path to remove the duplicate slashes. So file:///broadcast ends up becoming /broadcast and choo can match it. Here's app.js with the changes:

var electron = require('electron')
var path = require('path')

var win = null
var app = electron.app
var BrowserWindow = electron.BrowserWindow

app.on('ready', function () {
  console.log('The application is ready.')

  const PROTOCOL = 'file'
  electron.protocol.interceptFileProtocol(PROTOCOL, (request, callback) => {

      // Strip protocol
      let url = request.url.substr(PROTOCOL.length + 1)

      // Build complete path for node require function
      url = path.join(__dirname, url)

      // Removes duplicate slashes
      url = path.normalize(url)

      callback({path: url})
  })

  win = new BrowserWindow({
    width: 854,
    height: 650,
    minWidth: 550,
    minHeight: 200
  })

  // win.loadURL('file://' + path.join(__dirname, 'index.html'))
  win.loadURL('file://' + '/index.html')

  win.on('close', function () {
    win = null
  })
})

I had the same issue as @obernardovieira and the solution by @gwbutler didn't fix it (Windows 10, Chrome v67).

It looks as though Choo already intercepts electron file paths, but the regex in nanorouter doesn't account for Windows adding the drive letter so /broadcast returns as C:/broadcast etc

Changing the regex in node_modules\nanorouter\index.js to capture the drive letter worked for me:

previous:
var electron = '^(file:\/\/|\/)(.*\.html?\/?)?'
new:
var electron = '^(file:(\/\/|\/)|\/C:)(.*\.html?\/?)?'

This match is only checked when isLocalFile is true so I assume it won't break anything elsewhere in nanorouter but either way it seems to get the job done here (between two instances of hypervision on the same computer, anyway, I haven't checked remote peers yet...)

Confirming that the fix by @cihapus works for me as well on a new hypervision instance (also Windows 10, Chrome v67). I tweaked it a little to account for different drive letters: var electron = '^(file:\/\/|\/([A-Z]:)?)(.*\.html?\/?)?'