Skip to content

Commit

Permalink
refactor: extract source size fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
grantjbutler committed Mar 13, 2022
1 parent b0577a7 commit e977068
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions packages/main/src/obs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,7 @@ export default class OBSSocket {
.filter(source => source.type == 'input' && source.name.includes(this._sourceFilter))
.map(source => source.name);
})
.then((sources) => {
return Promise.allSettled(sources.map(sourceName => {
return this._getSourceSize(sourceName)
.then(size => ({
name: sourceName,
width: size.width,
height: size.height,
}));
}));
})
.then(sources => {
return (sources.filter(source => source.status == 'fulfilled') as PromiseFulfilledResult<Source>[])
.map(source => source.value);
})
.then((sources) => this._getSizesOfSources(sources))
.then(sources => { this.sources = sources; });
}

Expand All @@ -220,6 +207,21 @@ export default class OBSSocket {
.then(scenes => { this.scenes = scenes; });
}

_getSizesOfSources(sourceNames: string[]): Promise<{name: string, width: number, height: number}[]> {
return Promise.allSettled(sourceNames.map(sourceName => {
return this._getSourceSize(sourceName)
.then(size => ({
name: sourceName,
width: size.width,
height: size.height,
}));
}))
.then(sources => {
return (sources.filter(source => source.status == 'fulfilled') as PromiseFulfilledResult<Source>[])
.map(source => source.value);
});
}

_getSourceSize(sourceName: string): Promise<{width: number, height: number}> {
// There's got to be a better way to determine the size of a source without screenshot it.
return this._screenshotSource(sourceName, ImageQuality.Worst)
Expand Down

0 comments on commit e977068

Please sign in to comment.