Ideas needed. Javascript+XPCOM+C++ add-on

。_饼干妹妹 提交于 2019-12-04 06:21:27

问题


So, there is a WebRTC inside Firefox and there is a convenient class for making RTC communication possible called RTCPeerConnection which can be instantiated and used from the JavaScript app. You can find some decent example of it on [1]. And here am I with my custom transport (if you're interested - [2]) would like to use it for RTC communication. Briefly, I need to "substitute" the transport layer of WebRTC engine by my custom transport while providing the same RTCPeerConnection-like JavaScript interface for the user. And preferably, it should not look like custom build of Firefox (no patches). So I've come up with the idea of extension, which will be written in C++ (since it need to be linked with WebRTC library and my custom transport library) and somehow will expose its interface to Javascript. And I've found XPCOM which, as I thought, can provide me this. So I've started to fight with out-dated and sparsed info on this topic and after 3 days of struggling finally ended up with builded add-on. Unfortunately, I can't access it from Javascript, because of Javascript's "Components.classes is undefined" error. And it seems that there is no way to access it at all. Or I'm wrong on that?

Here is Javascript:

function check()
{
console.debug("checking...");   

const {Cc,Ci,Cu} = require("chrome");
var rtc = Components.classes["@named-data.net/ndnrtc;1"].createInstance();
rtc = rtc.QueryInterface(Ci.ndINrtc);   

console.debug("rtc: "+rtc);
}

My component is visible with XPCOM Viewer addon and the code above I can execute in the console while empty page is open in Firefox.

Given all that, I would like to ask Firefox experts regarding possible approaches which I can take in order to implement my idea. Thank you in advance

1 https://apprtc.appspot.com/

2 http://named-data.net


回答1:


Finally, I've figured out one possible solution for that and describe it in my post



来源:https://stackoverflow.com/questions/17955147/ideas-needed-javascriptxpcomc-add-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!