1

we want to use WAMP protocol to my server client applications. I have found Autobahn-js which implements The Web Application Messaging Protocol (WAMP). we would like to use QML for designing the frontend (thin client) and target Android, IOS, Windows Mobile and desktop platforms. Since Autobahn-js written in Javascript, I thought it would work. but unfortunately, it didn't.

Here is the following I did:

  • I have downloaded the Autobahn Js library from Github.

  • I have included all the files in my QML project.

  • import "lib/autobahn.js" as AutoBhan

  • Then comes the error qrc:/lib/autobahn.js:15: ReferenceError: require is not defined

upon googling I came to know that "The require() function is a core function of node.js which is part of the engine. It's not something language-specific just like the window object in browser-based Javascript is not something in the Javascript language. node.js actually is: a server-side JavaScript engine, which executes JavaScript files. It is not a framework which you could load into another engine like Qt". source.

Here is my question:

  1. How can I make/build the Autobahn Js library so that I can use autobahn in qml? which is actually making node.js functions running in qml.

  2. Tough there is C++ implementation, I am not convinced in using the C++ wrapper in qml because it depends on third parties like Boost.

  3. Is it possible to make JS library which depends on node.js functions in QML ? Please let me know. Thanks

FYI: I am using Crossbar.io as router

Community
  • 1
  • 1
vishnu
  • 363
  • 3
  • 20
  • AutobahnJS does not depend on anything Node.js-specific - but it was developed for either use in the browser or Node.js. A QML environment, which has its own JavaScript engine, was not considered. – gzost Mar 22 '17 at 18:21

2 Answers2

0

You have four options

  1. change the library so that it doesn't depend on anything nodejs specific
  2. extend the QML JavaScript engine so that it provides the nodejs specific extensions
  3. run nodejs via QProcess
  4. look at some of the projects that try to provide a C/C++ interface for embedding nodejs

However, if the protocol you are intending to use has a C/C++ implementation, using that is likely the best way forward.

Kevin Krammer
  • 5,159
  • 2
  • 9
  • 22
0

Try the browser version of AutobahnJS, not the NodeJS version.

If you only need WAMP inside QML, don't bother with C++ WAMP libraries (harder).

If you want to talk WAMP directly to your C++ stuff (within Qt), there are multiple C++ WAMP client libraries - however, I'm not sure how well these blend with Qt. Eg AutobahnC++ is Boost/ASIO based.

However, there was recently a post touching on this ..

oberstet
  • 21,353
  • 10
  • 64
  • 97
  • Thanks for your input. As you said I have downloaded the [browser version](https://github.com/crossbario/autobahn-js#browser-development) as js file and included and imported the js file in qml project. when I build it. Unimplemented code. ASSERT: "idom == referenceIdom" in file compiler\qv4ssa.cpp, line 4959 – vishnu Mar 20 '17 at 07:50
  • This doesn't seem to be an AutobahnJS issue, but a Qt one (the ASSERT is from within C++ code in Qt) - we can't do anything about this. Bug the Qt guys .. – oberstet Mar 20 '17 at 08:57
  • oka.y Before that is my procedure correct? I just downloaded the js file and included it. I didn't build it because i don't know how. Thanks – vishnu Mar 20 '17 at 08:59
  • yes, download from https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.js and include it (don't build it yourself .. no need to). this is the (non-mininized, uncompressed) browser version. it works in all browsers (even IE10 .. with fallbacks on IE9). if it doesn't work in Qt/QML embedded browser engine, this is none of our business. – oberstet Mar 20 '17 at 09:10
  • Thanks a lot for the confirmation. If this doesn't work with qml, then I would consider HTML5 as my frontend. – vishnu Mar 20 '17 at 09:16