mirror of
https://github.com/streamwall/streamwall.git
synced 2025-12-06 01:45:37 -05:00
Simplify view loading (hopefully more consistent page visibility)
This commit is contained in:
@@ -36,7 +36,6 @@ export interface StreamWindowEventMap {
|
|||||||
export default class StreamWindow extends EventEmitter<StreamWindowEventMap> {
|
export default class StreamWindow extends EventEmitter<StreamWindowEventMap> {
|
||||||
config: StreamWindowConfig
|
config: StreamWindowConfig
|
||||||
win: BrowserWindow
|
win: BrowserWindow
|
||||||
offscreenWin: BrowserWindow
|
|
||||||
backgroundView: WebContentsView
|
backgroundView: WebContentsView
|
||||||
overlayView: WebContentsView
|
overlayView: WebContentsView
|
||||||
views: Map<number, ViewActor>
|
views: Map<number, ViewActor>
|
||||||
@@ -70,13 +69,6 @@ export default class StreamWindow extends EventEmitter<StreamWindowEventMap> {
|
|||||||
})
|
})
|
||||||
this.win = win
|
this.win = win
|
||||||
|
|
||||||
const offscreenWin = new BrowserWindow({
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
show: false,
|
|
||||||
})
|
|
||||||
this.offscreenWin = offscreenWin
|
|
||||||
|
|
||||||
const backgroundView = new WebContentsView({
|
const backgroundView = new WebContentsView({
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
preload: path.join(__dirname, 'layerPreload.js'),
|
preload: path.join(__dirname, 'layerPreload.js'),
|
||||||
@@ -146,7 +138,7 @@ export default class StreamWindow extends EventEmitter<StreamWindowEventMap> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createView() {
|
createView() {
|
||||||
const { win, offscreenWin } = this
|
const { win } = this
|
||||||
assert(win != null, 'Window must be initialized')
|
assert(win != null, 'Window must be initialized')
|
||||||
const { backgroundColor } = this.config
|
const { backgroundColor } = this.config
|
||||||
const view = new WebContentsView({
|
const view = new WebContentsView({
|
||||||
@@ -154,6 +146,7 @@ export default class StreamWindow extends EventEmitter<StreamWindowEventMap> {
|
|||||||
preload: path.join(__dirname, 'mediaPreload.js'),
|
preload: path.join(__dirname, 'mediaPreload.js'),
|
||||||
nodeIntegration: false,
|
nodeIntegration: false,
|
||||||
contextIsolation: true,
|
contextIsolation: true,
|
||||||
|
backgroundThrottling: false,
|
||||||
partition: 'persist:session',
|
partition: 'persist:session',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -171,7 +164,6 @@ export default class StreamWindow extends EventEmitter<StreamWindowEventMap> {
|
|||||||
id: viewId,
|
id: viewId,
|
||||||
view,
|
view,
|
||||||
win,
|
win,
|
||||||
offscreenWin,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -21,13 +21,11 @@ const viewStateMachine = setup({
|
|||||||
id: number
|
id: number
|
||||||
view: WebContentsView
|
view: WebContentsView
|
||||||
win: BrowserWindow
|
win: BrowserWindow
|
||||||
offscreenWin: BrowserWindow
|
|
||||||
},
|
},
|
||||||
|
|
||||||
context: {} as {
|
context: {} as {
|
||||||
id: number
|
id: number
|
||||||
win: BrowserWindow
|
win: BrowserWindow
|
||||||
offscreenWin: BrowserWindow
|
|
||||||
view: WebContentsView
|
view: WebContentsView
|
||||||
pos: ViewPos | null
|
pos: ViewPos | null
|
||||||
content: ViewContent | null
|
content: ViewContent | null
|
||||||
@@ -85,23 +83,19 @@ const viewStateMachine = setup({
|
|||||||
},
|
},
|
||||||
|
|
||||||
offscreenView: ({ context }) => {
|
offscreenView: ({ context }) => {
|
||||||
const { view, win, offscreenWin } = context
|
const { view, win } = context
|
||||||
// It appears necessary to initialize the browser view by adding it to a window and setting bounds. Otherwise, some streaming sites like Periscope will not load their videos due to RAFs not firing.
|
win.contentView.addChildView(view, 0) // Insert below background (so hidden by background)
|
||||||
// TODO: Is this still necessary with WebContentsView?
|
|
||||||
win.contentView.removeChildView(view)
|
|
||||||
offscreenWin.contentView.addChildView(view)
|
|
||||||
view.setBounds(win.getBounds())
|
view.setBounds(win.getBounds())
|
||||||
},
|
},
|
||||||
|
|
||||||
positionView: ({ context }) => {
|
positionView: ({ context }) => {
|
||||||
const { pos, view, win, offscreenWin } = context
|
const { pos, view, win } = context
|
||||||
|
|
||||||
if (!pos) {
|
if (!pos) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
offscreenWin.contentView.removeChildView(view)
|
win.contentView.addChildView(view, win.contentView.children.length - 2) // Insert below overlay but above background
|
||||||
win.contentView.addChildView(view, 1) // Insert at index 1 above default view and so overlay remains on top
|
|
||||||
view.setBounds(pos)
|
view.setBounds(pos)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -147,24 +141,16 @@ const viewStateMachine = setup({
|
|||||||
} else {
|
} else {
|
||||||
wc.loadURL(content.url)
|
wc.loadURL(content.url)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
// Force page visibility
|
|
||||||
wc.capturePage(undefined, { stayAwake: true })
|
|
||||||
} catch (err) {
|
|
||||||
console.warn('Error calling capturePage:', err)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
}).createMachine({
|
}).createMachine({
|
||||||
id: 'view',
|
id: 'view',
|
||||||
initial: 'empty',
|
initial: 'empty',
|
||||||
context: ({ input: { id, view, win, offscreenWin } }) => ({
|
context: ({ input: { id, view, win } }) => ({
|
||||||
id,
|
id,
|
||||||
view,
|
view,
|
||||||
win,
|
win,
|
||||||
offscreenWin,
|
|
||||||
pos: null,
|
pos: null,
|
||||||
content: null,
|
content: null,
|
||||||
options: null,
|
options: null,
|
||||||
|
|||||||
Reference in New Issue
Block a user