10-02-2012 06:05 AM - edited 10-02-2012 06:12 AM
I'm trying to use an event so that I can send debug statements from native and console.log them in js.
// index.htm (inside script tag)
function logCallback(message) { console.log("message: " + message); };
app.monitorLogs(logCallback);
// client.js
// register callback on client side
_self.monitorLogs = function (cb) {
window.webworks.event.add(_ID, "app.logEvent", cb);
};When the above line executes, the console outputs the following:
GET http://localhost:8472/1/add?eventName=%22app.logEvent%22 404 (OK) GET http://localhost:8472/1/add?eventName=%22app.logEv ent%22:1
The strange thing is, the events work perfectly OK despite this error message.
A couple of points of interest:
-The error is only presented when the windows.webworks.add line is exectued the first time
-The error does not occur at all when no callback is supplied eg.
monitorLogs();
Any help would be appreciated, as I'm not sure what the 404 is telling me.
Thanks.
Edit: I've just noticed that the example memory extension raises this error as well, is this considered normal?
Any explanation of why it occurs either way would be very interesting.
10-02-2012 07:07 AM
10-02-2012 07:12 AM
Ah, I see. Sure here it is. Note that "app" in the previous version has been replaced by "tcrpa".
var tcrpaJNext,
_event = require("../../lib/event");
module.exports = {
sayHelloServer: function (success, fail, args, env) {
try {
success(tcrpaJNext.sayHelloJNext());
} catch (e) {
fail(-1, e);
}
}
};
////////////////////////////////////////////////// /////////////////
// JavaScript wrapper for JNEXT plugin
////////////////////////////////////////////////// /////////////////
JNEXT.TCRPAJNext = function ()
{
var _self = this;
_self.sayHelloJNext = function () {
return JNEXT.invoke(_self._id, "sayHello");
};
_self.getId = function () {
return _self._id;
};
_self.init = function () {
// Specify the required module exported by the native side
if (!JNEXT.require("tcrpaJnext")) {
return false;
}
// Creates an object by using an acquired module and saves returned id
_self._id = JNEXT.createObject("tcrpaJnext.TCRPAExt");
if (!_self._id || _self._id === "") {
return false;
}
// Registers itself to be notified on events so that the onEvent method is called
JNEXT.registerEvents(_self);
};
// Events from the native side are passed as a string to this method (onEvent name mandatory)
_self.onEvent = function (strData) {
var arData = strData.split(" "),
strEventId = arData[0],
arg = arData[1];
_event.trigger("tcrpa.logEvent", strData);
};
_self._id = "";
_self.init();
};
tcrpaJNext = new JNEXT.TCRPAJNext();
10-02-2012 07:13 AM
Memory extension also seems to be missing registering of the events
Try this
In the client.js you need to call register events
https://github.com/blackberry/BB10-WebWorks-Framew
In the index.js you should register the action map with the eventing framework and have a corresponding register events method
https://github.com/blackberry/BB10-WebWorks-Framew
https://github.com/blackberry/BB10-WebWorks-Framew
And code to register with the eventing framework
https://github.com/blackberry/BB10-WebWorks-Framew
This should solve your issue
10-02-2012 07:34 AM
Thanks for the reply.
Could you point me to the documentation on how to write those methods, as I'm unsure of how to write the equivalents for my own code.
10-02-2012 01:54 PM
10-03-2012 10:24 AM
Thanks for your reply, it's really helped my progress with this.
I've now refactored my code into a format similar to the connection example.
Where should the :
addEventListener / removeEventListener (connectionEvents.js)
and
startEvents / stopEvents (connectionJNEXT.js)
functions be called?
10-03-2012 10:31 AM
addEventListener / removeEventListener
these are called automatically by the eventing framework. So when the user will call blackberry.event.addEventListener("yourEvent"...) it will call the addEventListener in your code.
startEvents / stopEvents
The addEventListener/removeEventListener should call startEvents and stopEvents as here-
https://github.com/blackberry/BB10-WebWorks-Framew
10-03-2012 11:54 AM - edited 10-03-2012 11:56 AM
<html>
<head>
<title>tc-rpa extension test</title>
<script type="text/javascript">
</script>
<script type="text/javascript" src="webworks-1.0.1.17.js"></script>
<script type="text/javascript">
function onLoad() {
document.addEventListener("webworksready", webWorksReady, false);
};
function logCallback(message) {
console.log("!!!!!!");
console.log("message: " + message);
};
function webWorksReady () {
blackberry.event.addEventListener("tcrpalogEvent") ;
};
function getHelloString() {
var str = tcrpa.sayHello();
alert(str);
};
</script>
</head>
<body onload="onLoad()" bgcolor="#FF9900">
<div align="center">
<br />
<button style="width:280px; height: 240px; font-size: 200%; background-color: lightgreen" onclick="getHelloString()">
Say Hello
</button>
</div>
</body>
</html>Call add event listener like this ^ ?
It looks like my StartEvents() C++ funciton is not being called.
Any chance you have an example application that uses the connection extension?
10-03-2012 12:05 PM