-
-
Notifications
You must be signed in to change notification settings - Fork 376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Native Messaging signaling server #544
Comments
This is a bit out of the libdatachannel scope, but there is no portable way to do so in C/C++, you have to use However, a portable C++ program could be made to read stdin and send in a Data Channel. You would then pipe |
How to do that?
Should I close this issue? |
No, it's OK.
After connecting the Data Channel (like in the examples), you need to do something like this: const std::size_t bufferSize = 4096;
std::byte buffer[bufferSize];
while(std::cin.good()) {
// Read from stdin
std::cin.read(buffer, bufferSize);
std::size_t count = std::cin.gcount();
if(count == 0)
break; // end of file
// Send in the Data Channel
dc->send(buffer, count);
}
dc->close(); |
Would I place that in libdatachannel/examples/copy-paste/offerer.cpp Lines 112 to 122 in 0975afa
Again, I have no experience with C++. Which part is the STDOUT from one of the answers at the SO question linked?
There is no EOF. No file is being read. The stream is live output of what you hear output to speakers and headphones. |
Thinking about it, what you want to do is quite tricky, you can't just drag-and-drop some code into an example. For instance, how do you plan to pass the WebRTC signaling messages back-and-forth to the C++ process in order to open the Data Channel? If you have no experience in C or C++, I'd recommend aiortc, a WebRTC Python library.
End-of-file happens when stdin is closed, e.g. when |
Here I use clipboard as signaling server https://gist.github.com/guest271314/04a539c00926e15905b86d05138c113c, here an The expected flow is user clicks extension icon the browser WebRTC recv-only data channel is constructed, the C++ data channel is constructed as send-only and shell script is executed piping output to the data channel, necessary signaling occurs via appropriate means, when browser side closes the data channel, shell script terminates, C++data channel terminates. I should be able to repeat that procedure multiple times, ideally without ever writing to a file. |
Technically, I can. I can also write to and read from files if that would be simpler. On the browser side I can read (static) local files listed in Thus I can read the send-only SDP of C++data channel. I could also use the Native Messaging host to write the browser recv-only SDP which C++side reads. Where I have no knowledge in C++ is where to pipe the data to the data channel. I looked at aioquic. Your library appears to be self-contained and minimal in size. In lieu of closing the issue, if you have/find the spare time perhaps you could add an example of streaming STDOUT from a |
I had no experience with Python either until I began experimenting with (Ideally I would just use Native Messaging (12MB when running) directly at any origin, however that (currently) is restricted by Chromium source code ungoogled-software/ungoogled-chromium#1800, or something like Kagami didwith Have a great day. |
Sure, if you can adapt the signaling then that's fine.
Yes thanks, I tried to make it that way.
It would look like this: #include <stdexcept>
#include <stdio.h>
[...]
const char *command = "parec";
File *file = popen(command, "r");
if (!file)
throw std::runtime_error("popen failed");
try {
const std::size_t bufferSize = 4096;
std::byte buffer[bufferSize];
size_t count;
while((count = fread(buffer, 1, bufferSize, file)) > 0)
dc->send(buffer, count);
} catch(const std::exception &e) {
std::cerr << e.what() << std::endl;
}
pclose(file); |
Thanks. I'll need a few days to try C++. I got to
which throws
I could not locate a solution for this at #37. |
To compile with GnuTLS, you need headers for both GnuTLS and its dependency Nettle. On Ubuntu or Debian you can install them with:
|
This is quickly becoming expensive. We are already at 1GB for libdatachannel folder. I am basically trying to determine if the Nonetheless I will test libdatachannel later today or tomorrow. |
The whole source repository with submodules, git history, media examples, and temporary compilation objects may grow around 500MB, but the final compiled library (typically Note the biggest thing in the repository is actually the git history of the json submodule, which you don't need. Therefore, you can reduce the size under 200MB by recreating a fresh clone and fetching the submodules with
|
I installed nettle.
Still throwing error
|
What is your OS? How did you install nettle? You could use the main build method with CMake if the Makefile does not work for you. |
Linux 5.4.0-42-lowlatency. This built your library
websocket.cpp, websocketserver.cpp were built anyway. I'll begin experimenting. |
|
Is the examples/web example complete? I built again with I can use the |
Is it on Ubuntu? I can't reproduce neither on Debian nor on Arch Linux.
This is expected, the build goes through everything irrelevant of the flags for the sake of simplicity but the corresponding code is not compiled if disabled.
The web example is just a web page with an equivalent JS client that you can use to connect to the libdatachannel one. Please refer to the corresponding README.md file to run it in a browser. Also, note that like the libdatachannel client example, it requires one of the example signaling servers to be running. |
Yes, Ubuntu (studio). Note, I'm pretty sure the
No (Python) when I run we get
for with The ports are mismatched as well
though we are running on What happens when you try to run the /web example with signaling-server.py on your machine? I'll try to adapt the copy-paste code. |
You don't need to copy anything to build, just run the programs from examples.
You must install the websockets Python module:
The ports are not mismatched: the HTTP server serves pages to the browser on port 8080, but the signaling server listens on port 8000. Of course it breaks since you changed the port to the wrong one. In the first place, the signaling server needs to be properly started, and then, don't change the signaling server port. |
That should be in the documentation. Right now I'm trying to adapt C++ copy-paste and just use Native Messaging host https://stackoverflow.com/a/26583974 instead of installing more packages. |
Using Native Messaging I should be able to do something like
where everything needed, including the while loop that writes to data channel is in one (1) compiled offerer program. |
This is what I have so far based on https://stackoverflow.com/q/68170912 nm.cpp
nm_cpp.json
manifest.json
background.js which we use here just for ability to call Native Messaging host from "service worker" DevTools inspected window at chrome://extensions
Navigate to chrome://extensions, toggle "Developer mode", click "Load unpacked", then substitute the generated ID in nm_cpp.json for then
Notice that we do not need to install anything. Or execute the program at terminal. The program is executed by Chromium when
Where I am not progressing is when the initial empty object message is sent, given the C++ copy-paste example, the local description should be sent to the extension, read the remote description, read/write candidates. |
You entered the local identifier as remote identifier, which is expected to fail as you can't connect a WebRTC Peer Connection to itself (peers take asymmetrical roles similar to client and server). You need to connect to another peer, for instance a second tab on 127.0.0.1:8080 or a libdatachannel example client. |
Did you set I can't see the error on the screenshot. If the error is |
Yes,
|
From what I can see on your screenshot, the DataChannel opened correctly then might have been closed. Again, I can't read the error on the screenshot. |
If I recollect accurate, the channel ready state is not open. Though it should be. You should be able to reproduce the experiment yourself. |
For my use cases I cannot really reconcile setting up and using a dedicated signaling server and
I am just trying to avoid using an |
It looks like your answerer calls On answerer side, you want to set up the
I'm OK to help but I don't have time to debug your own code, sorry.
You don't actually need a WebSocket, it's just a protocol commonly used for large-scale signaling. Here, you just need a way to pass the SDP offer and get the SDP answer back (You don't have to transmit candidates separately if you wait for |
That is the key and what I will try later today or tomorrow.
Thanks for your time and effort so far. Should I close this now to take this issue off of your plate? |
I am currently using Native Messaging to stream system audio output ("What-U-Hear") to the browser.
Reading examples/signaling-server-python and examples/copy-paste I should be able to incorporate the pattern into https://github.com/guest271314/captureSystemAudio/blob/master/native_messaging/capture_system_audio/capture_system_audio.py without using
WebSocket
.The issue with my current approach is I have to insert an
<iframe>
into the arbitrary web page to keep the Native Messaging connection active becauseServiceWorker
becomes inactive in 5 minutes and 15-30 seconds. I would prefer to not use an<iframe>
at all.WebRTC can be executed on any web page.
I have no experience with C++. I do not know how to substitute Python's
subprocess
to execute a shell command, in this case PulseAudio'sparec
and stream STDOUT from that command to the data channel, terminating the command when the data channel is closed on the client (browser) side. I read https://stackoverflow.com/questions/478898/how-do-i-execute-a-command-and-get-the-output-of-the-command-within-c-using-po today, though I am curious how you would achieve that requirement?Thanks in advance.
The text was updated successfully, but these errors were encountered: