0

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

peetonn
  • 2,942
  • 4
  • 32
  • 49
  • Are you using the addon-sdk to build your extension? – Filipe Silva Jul 30 '13 at 20:36
  • No, cause I think it's not enough - I don't need a GUI, and I need to link with C++ code. Or I can use it? – peetonn Jul 30 '13 at 22:01
  • I'm not saying to use it. It's just the "Components.classes" error that you got usually happens on the addon-sdk when people don't import "chrome". That's why i asked. I'm not sure i can be of much help for the rest, sorry – Filipe Silva Jul 30 '13 at 22:16
  • @peetonn Please show what *code* you've tried. You're mentioning an error that has nothing at all to do with XPCom. It's most likely just about how you're organising your JavaScript-side code. Please show your code! As for approaches, if you need to run platform-specific libraries, your options are `xpcom` and `js-ctypes`. ctypes is a much easier interface, but noone can help you without seeing some code. – David-SkyMesh Jul 31 '13 at 02:39
  • @peetonn: Your addon-side JavaScript code will have access to `Components.*`. See a `bootstrap` (XUL-less) example in my self-answered question: http://stackoverflow.com/questions/14055646/simplest-way-to-launch-firefox-drive-3rd-party-site-using-privileged-nsi-apis/14207718#14207718 – David-SkyMesh Jul 31 '13 at 02:42
  • @David-SkyMesh edited. thanks for the comment! with the bootstraped script, how can I reveal the object for a DOM so it can be accessible from the webpage JS? i've tried using `category JavaScript-navigator-property ndnrtc @named-data.net/ndnrtc;1` in manifest, but it exposes only wrapper XPCOM which should be queried for interface (like in code above `rtc.QueryInterface(Ci.INrtc)`). – peetonn Aug 01 '13 at 17:39
  • @peeton: The component loading code looks OK. where does that JavaScript *run*? If you're doing a bootstrap, Could you post your `install.rdf` and `bootstrap.js`? Otherwise, post a cut-down XPI somewhere that we can look at. – David-SkyMesh Aug 01 '13 at 22:58
  • Previously, this code run in a webpage. But now I've changed strategy a bit, will write a post on this later. You can check code here https://dl.dropboxusercontent.com/u/2131124/ndnrtc.zip Briefly: I've arranged new Javascript XPCOM component which acts like a wrapper for C++ XPCOM and exposes itself for DOM on window object via (Javascript-global-property and nsIDOMGlobalPropertyInitializer interface). This wrapper calls C++ XPCOM object. Now it works in Nightyl, but not in release Firefox for some reason... – peetonn Aug 02 '13 at 20:42
  • You're using an XPCOM C++ binary component. Those are version tagged and hence will only run in the version of Firefox (well, the platform actually) which it was compiled against (mozilla::Module::kVersion, http://hg.mozilla.org/mozilla-central/file/46b409b1fa04/xpcom/components/nsNativeComponentLoader.cpp#l188 ). Hence my suggestion in your other question to use js-ctypes instead if you need binaries. – nmaier Aug 05 '13 at 19:28

1 Answers1

2

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

peetonn
  • 2,942
  • 4
  • 32
  • 49