Where is the bridge between javascript and C++ code in WebRTC?

246 views
Skip to first unread message

Ivan Hutomo

unread,
Oct 27, 2022, 11:01:34 PM10/27/22
to discuss-webrtc
Hello everyone,
I am trying to build custom WebRTC and add my custom frame encryptor.
I successfully built in android and it could work successfully. In android, we have JNI to become the bridge between java and C++. Like for example, finally it will call PeerConnection.java that connect to RTPSender.cc

But I wonder where is the bridge between javascript and c++, if I would to have the same WebRTC modification for electron, where I should start? Thank you.

Byoungchan Lee

unread,
Oct 28, 2022, 2:30:44 AM10/28/22
to discuss-webrtc
Electron builds Chromium from source, so you need to modify Chromium's third_party/blink/renderer/modules/peerconnection .

https://www.electronjs.org/blog/electron-internals-building-chromium-as-a-library

https://github.com/electron/electron/blob/ea6f873f979f9dea98006288ab143330beecffa8/DEPS#L70

However, I am wondering if your requirements are not met by the existing API.

Ivan Hutomo

unread,
Oct 28, 2022, 2:37:02 AM10/28/22
to discuss-webrtc
Yes, I plan to build Electron using electron-build-tools, then change third_party/webrtc there.
But I saw when we would initiate a peer connection in JS, we will type the code like this:

pc1 = new RTCPeerConnection(configuration);

Where does this RTCPeerConnection function start to call the code inside third_party/webrtc?

For example, in react-native-webrtc, it will start from 

PeerConnectionObserver.java -> PeerConnection.java (inside WebRTC) => JNI Bridge => PeerConnection.cc

Philipp Hancke

unread,
Oct 28, 2022, 2:45:19 AM10/28/22
to discuss...@googlegroups.com
any reason why you want to do that instead of using the insertable streams API as in https://webrtc.github.io/samples/src/content/insertable-streams/endtoend-encryption/
JS functions have to be async which made the somewhat different implementation necessary.


--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/4224d420-e0bb-4dad-b58b-8b14de814256n%40googlegroups.com.

Ivan Hutomo

unread,
Oct 28, 2022, 2:54:53 AM10/28/22
to discuss-webrtc
Last time I tried already Insertable Streams API, and implement encryption and decryption using WebAssembly. But then, my android app could not decrypt video that was encrypted through insertable streams, but it can decrypt video from another android app. The other way around, my website app could decrypt video from my android. Only my android could not decrypt video from insertable streams.

We already make sure that our encryption code is exactly the same as well as the encryption key and IV Key. Then after that, we come to the conclusion that maybe the package we encrypt through insertable streams is different from the package we encrypt using frame encryptor inside our android's webRTC. We try to solve this problem but still did not find the solution until 2 weeks. That's why we try to use the same customized webRTC for electron chromium, but this far actually becomes more complicated.

Any idea regarding this? Or do I need to do additional steps for insertable-streams? Thank you so much anyway for the discussion.

Ivan Hutomo

unread,
Oct 28, 2022, 3:03:15 AM10/28/22
to discuss-webrtc
Oh, also my website app could not decrypt video that was encrypted from another website app as well (encrypted using insertable stream). 

Ivan Hutomo

unread,
Nov 4, 2022, 2:02:07 AM11/4/22
to discuss-webrtc

Hello everyone, I would to add a custom set frame encryptor inside a self-build electron. I already tried insertable streams but it was not working together with my modified webrtc for android. So here I already tried this custom encryptor in low-level webrtc and its working. My problem now is how I could set my custom frame encryptor in higher-level code, so I could decide to set it from JavaScript.  I tried to add something here in the third_party/blink

new RTCPeerConnection() 

According to Standard WebRTC API
Including lib-jitsi-meet.js from Jitsi-Meet
They're using the following API

RTCPeerConnection
RTCRtpSender
RTCRtpReceiver

So,

Encrypt frames could be here in RTCRtpSender.
Decrypt frames could be here in RTCRtpReceiver.

third_party\blink\renderer\modules\peerconnection
rtc_rtp_receiver.cc
rtc_rtp_receiver.h
rtc_rtp_sender.cc
rtc_rtp_sender.h
rtc_rtp_transceiver.cc
rtc_rtp_transceiver.h

Now I tried to add my custom frame encryptor and decryptor to the corresponding webrtc's sender and corresponding webrtc's receiver. I am adding the code inside rtc_rtp_sender.cc something like below:

void RTCRtpSender::setFrameEncryptor(std::vector<uint8_t> new_keys) {
  rtc::scoped_refptr<webrtc::OctonFrameEncryptor> encryptor_(
      new webrtc::OctonFrameEncryptor(new_keys));
  sender_.get()->SetFrameEncryptor(encryptor_);
  // std::unique_ptr<RTCRtpSenderPlatform> sender_ -> SetFrameEncryptor(encryptor_);
}

But I could not get the correct corresponding webrtc's sender, always compile an error with something like this:

../../third_party/blink/renderer/modules/peerconnection/rtc_rtp_sender.cc(577,18): error: no member named 'SetFrameEncryptor' in 'blink::RTCRtpSenderPlatform'
  sender_.get()->SetFrameEncryptor(encryptor_);

Thank you everyone for helping
Reply all
Reply to author
Forward
0 new messages