no-proprietary-codecs.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Verifies that Electron cannot play a video that uses proprietary codecs
  2. //
  3. // This application should be run with the ffmpeg that does not include
  4. // proprietary codecs to ensure Electron uses it instead of the version
  5. // that does include proprietary codecs.
  6. const {app, BrowserWindow, ipcMain} = require('electron')
  7. const path = require('path')
  8. const url = require('url')
  9. const MEDIA_ERR_SRC_NOT_SUPPORTED = 4
  10. const FIVE_MINUTES = 5 * 60 * 1000
  11. let window
  12. app.once('ready', () => {
  13. window = new BrowserWindow({
  14. show: false
  15. })
  16. window.loadURL(url.format({
  17. protocol: 'file',
  18. slashed: true,
  19. pathname: path.resolve(__dirname, 'asar', 'video.asar', 'index.html')
  20. }))
  21. ipcMain.on('asar-video', (event, message, error) => {
  22. if (message === 'ended') {
  23. console.log('Video played, proprietary codecs are included')
  24. app.exit(1)
  25. return
  26. }
  27. if (message === 'error' && error === MEDIA_ERR_SRC_NOT_SUPPORTED) {
  28. app.exit(0)
  29. return
  30. }
  31. console.log(`Unexpected response from page: ${message} ${error}`)
  32. app.exit(1)
  33. })
  34. setTimeout(() => {
  35. console.log('No IPC message after 5 minutes')
  36. app.exit(1)
  37. }, FIVE_MINUTES)
  38. })