From d9b62c7dc10257fd64d38167bc36608e563cd14b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Ka=C5=BAmierczak?= Date: Mon, 16 Sep 2024 10:20:05 +0200 Subject: [PATCH] refactor --- demos/utils/gst.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/demos/utils/gst.ts b/demos/utils/gst.ts index 3a37ad7b7..269405a7c 100644 --- a/demos/utils/gst.ts +++ b/demos/utils/gst.ts @@ -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 ` + @@ -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 {