-
Notifications
You must be signed in to change notification settings - Fork 19
/
app.js
127 lines (108 loc) · 2.99 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
const {
BrowserWindow,
app,
components,
ipcMain
} = require('electron');
const fs = require('fs');
// TESTING PRODUCTION
let index = './index';
if (!fs.existsSync(index)) {
//DEV
index = './api/index';
}
let downstreamInstance;
const downstreamElectron = require(index);
let example = 'main';
process.argv.forEach(function (val, index, array) {
let params = val.split('=', 2);
if (!Array.isArray(params) || params.length < 2) {
return;
}
if (params[0] === 'example') {
example = params[1];
}
});
const exampleFile = `file://${__dirname}/examples/${example}/index.html`;
const path = require('path');
// default value of allowRendererProcessReuse false is deprecated
app.allowRendererProcessReuse = true;
function createWindow () {
// eslint-disable-next-line no-process-env
let appDir = path.dirname(process.mainModule.filename) + '/';
// head request parameter test
let useHeadRequest = true;
// let useHeadRequest = false;
downstreamInstance = downstreamElectron.init({
appDir: appDir,
numberOfManifestsInParallel: 2,
useHeadRequests: useHeadRequest
});
const win = new BrowserWindow({
width: 1200,
height: 700,
resizable: true,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
plugins: true,
nodeIntegration: true,
// NOTE: !WARNING! use with caution it allows app to download content
// from any URL
webSecurity: false
}
});
win.loadURL(exampleFile);
win.webContents.openDevTools();
}
function onWillQuit () {
downstreamInstance.stop();
}
app.whenReady().then(async () => {
await components.whenReady();
console.log('components ready:', components.status());
createWindow();
});
app.on('will-quit', onWillQuit);
app.on('window-all-closed', () => {
console.log('window-all-closed');
app.quit();
});
function playVideo (link, offlineSessionId, config) {
let playerWindow = new BrowserWindow({
width: 860,
height: 600,
show: true,
resizable: true,
webPreferences: {
plugins: true,
preload: path.join(__dirname, 'player/preload.js'),
// NOTE: !WARNING! use with caution it allows app to download content
// from any URL
webSecurity: false
}
});
const playerUrl = `file://${__dirname}/player/index.html`;
playerWindow.loadURL(playerUrl);
playerWindow.webContents.openDevTools();
playerWindow.webContents.on('did-finish-load', function (evt, args) {
playerWindow.webContents.send('utilsAPI', 'startPlaybackStream', {
url: link,
configuration: config,
offlineSessionId: offlineSessionId
});
});
}
ipcMain.on('utilsAPI', (event, message, ...args) => {
if (message === 'playVideo') {
playVideo(...args);
}
});
ipcMain.handle('utilsAPI', (event, message, ...args) => {
if (message === 'prepareTestFiles') {
var videoPath = args[0];
var audioPath = args[1];
return [
fs.readFileSync(videoPath).buffer,
fs.readFileSync(audioPath).buffer];
}
});