Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
wkazmierczak committed Sep 16, 2024
1 parent 8d343bc commit d9b62c7
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions demos/utils/gst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function gstStreamWebcam(ip: string, port: number, displayOutput: boolean
: ['v4l2src', 'x264enc', 'tune=zerolatency bitrate=2000 speed-preset=superfast'];

const plugins = [gstWebcamSource, 'videoconvert', gstEncoder, 'rtph264pay', 'udpsink'];
checkGstPlugins(plugins);
void checkGstPlugins(plugins);

const gstCommand =
`gst-launch-1.0 -v ` +
Expand All @@ -29,14 +29,16 @@ export function gstStreamWebcam(ip: string, port: number, displayOutput: boolean
return spawn('bash', ['-c', gstCommand], { displayOutput });
}

function checkGstPlugins(plugins: string[]) {
plugins.forEach(plugin => {
void isGstPluginAvailable(plugin).then(isAvailable => {
if (!isAvailable) {
throw Error(`Gstreamer plugin: ${plugin} is not available.`);
}
});
});
async function checkGstPlugins(plugins: string[]) {
await Promise.all(
plugins.map(async plugin => {
await isGstPluginAvailable(plugin).then(isAvailable => {
if (!isAvailable) {
throw Error(`Gstreamer plugin: ${plugin} is not available.`);
}
});
})
);
}

function isGstPluginAvailable(pluginName: string): Promise<boolean> {
Expand Down

0 comments on commit d9b62c7

Please sign in to comment.