WebAssembly / WASI

WebAssembly System Interface
Other
4.75k stars 243 forks source link

WebAssembly/WASI Native Messaging host #483

Closed guest271314 closed 2 years ago

guest271314 commented 2 years ago

Is it possible to use WebAssembly/WASI as a Native Messaging (https://developer.chrome.com/docs/apps/nativeMessaging) host?

I currently have working C++ code https://github.com/guest271314/captureSystemAudio/blob/master/native_messaging/capture_system_audio/capture_system_audio.cpp that I use to capture entire system audio output or specific device audio output using popen() and PulseAudio parec, send to the browser as JSON using the Native Messaging protocol https://developer.chrome.com/docs/apps/nativeMessaging/#native-messaging-host-protocol where the audio is passed to a MediaStreamTrackGenerator which can be streamed to peers using WebRTC and encoded to Opus in WebM container or MP3.

Is the above possible within the scope of WebAssembly/WASI?

sunfishcode commented 2 years ago

If this just needs the ability to read from stdin and write to stdout, then yes, that should work today.

guest271314 commented 2 years ago

I am using popen(). My attempts to compile to WASM so far have thrown errors on can't find iostream include and popon() is undefined.

guest271314 commented 2 years ago

WebAssembly Explorer did produce this .wat file. An error was generated concerning popen(). I am not sure how to run the file via wasmer, et al. when I connect to the host from the browser.

As a practical matter, I am not sure if it is even worth compiling to WASM when I can run the C++ code now.

capture_system_audio.wat.zip

sunfishcode commented 2 years ago

WASI does not yet support popen. If compiling C++ to native works for you, then there's probably not much value in compiling to Wasm.