Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Developer
peardox
Posts: 1,229
Registered: ‎03-20-2011
My Device: Playbook, Z10 LE, Dev Alpha B, 2x Dev Alpha C
My Carrier: 3, Orange, Vodafone
Accepted Solution

Can't find variable: webworks (Sensors)

This is wierd... It doesn't hurt anything - it just bugs me

 

Running my app on a Z10 with Web Inspector enabled I'm getting a repeated error (lots of times) logged on startup - then WebWorksReady kicks in and they stop

 

Looking at the debug they refer to webworks.event.trigger('devicecompass', ......

 

The compass works fine and it's initialization is wrapped in a function called after webworks has loaded

 

I wonder if the sensors feature is loading something before WW is ready?

 

Happens on Dev Alpha C with 10.1.0.1485 as well but not as many errors (slower device? Beta OS?)




Click the like button if you find my posts useful!
Please use plain text.
BlackBerry Development Advisor
anzor_b
Posts: 164
Registered: ‎09-24-2012
My Device: White BlackBerry 10
My Carrier: Bell

Re: Can't find variable: webworks (Sensors)

Hi peardox,

 

Are you referring to the sensors sample, or an app of your own?

Please use plain text.
Developer
peardox
Posts: 1,229
Registered: ‎03-20-2011
My Device: Playbook, Z10 LE, Dev Alpha B, 2x Dev Alpha C
My Carrier: 3, Orange, Vodafone

Re: Can't find variable: webworks (Sensors)

My own app - GPS + Compass on a map with AJAX data transfer




Click the like button if you find my posts useful!
Please use plain text.
BlackBerry Development Advisor
twindsor
Posts: 795
Registered: ‎07-15-2008
My Device: Z10
My Carrier: Bell

Re: Can't find variable: webworks (Sensors)

Are you making any calls to blackberry.event.addEventListener('devicecompass', callback) before the webworksready event fires?

Tim Windsor
Application Development Advisor II
Please use plain text.
Developer
peardox
Posts: 1,229
Registered: ‎03-20-2011
My Device: Playbook, Z10 LE, Dev Alpha B, 2x Dev Alpha C
My Carrier: 3, Orange, Vodafone

Re: Can't find variable: webworks (Sensors)

Nope - it's all wrapped in a function ripped from the example

 

function startBBCompass() {
	// Start listening to the compass sensor with a delay feedback of 1000 microseconds 
	blackberry.sensors.setOptions("devicecompass", { delay: comp_freq });
	   
	// Start the event listener for the sensors callback
	blackberry.event.addEventListener("devicecompass", compassCallback);
	   
	// Set the sensor to work in the background and use batching mode
	blackberry.sensors.setOptions("devicecompass", { background: true, batching: true });
	}

 

This is called from start() which is in turn called via webworksready

 

Comment out the call to start - no errors + the worlds most useless app

 

Put it back in... errors

 

Compass also keeps changing it's mind where North is - it drifts




Click the like button if you find my posts useful!
Please use plain text.
BlackBerry Development Advisor
twindsor
Posts: 795
Registered: ‎07-15-2008
My Device: Z10
My Carrier: Bell

Re: Can't find variable: webworks (Sensors)

Very strange. What if you combine your setOptions calls together and call it before adding the listener?

Tim Windsor
Application Development Advisor II
Please use plain text.
Developer
peardox
Posts: 1,229
Registered: ‎03-20-2011
My Device: Playbook, Z10 LE, Dev Alpha B, 2x Dev Alpha C
My Carrier: 3, Orange, Vodafone

Re: Can't find variable: webworks (Sensors)

Same thing

 

Got a breakpoint on the combined setOptions line so it's not even hit the handler

 

Tested on both Z10 10.0.9.2373 and Dev Alpha C 10.1.0.1485




Click the like button if you find my posts useful!
Please use plain text.
BlackBerry Development Advisor
twindsor
Posts: 795
Registered: ‎07-15-2008
My Device: Z10
My Carrier: Bell

Re: Can't find variable: webworks (Sensors)

I'm not reproducing this in my sample app. Could you include a full sample here?

Tim Windsor
Application Development Advisor II
Please use plain text.
Developer
peardox
Posts: 1,229
Registered: ‎03-20-2011
My Device: Playbook, Z10 LE, Dev Alpha B, 2x Dev Alpha C
My Carrier: 3, Orange, Vodafone

Re: Can't find variable: webworks (Sensors)

Right - I've thrown together a single-file compass-only app-test that just displays compass heading

 

I've left in all the device info gathering just in case

 

If you compile this up and stick it on a device then set a breakpoint on the setOptions line you'll see things trying to happen before they're meant to

 

As I mention, it all works OK - I'm just bugged by the errors

 

One rather long message...

 

config.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" 
        xmlns:rim="http://www.blackberry.com/ns/widgets" 
        version="1.0.0.31" id="com.peardox.proximiti" xml:lang="en">
	
	<author rim:copyright="2011" email="someone@somewhere.com" href="http://www.peardox.com">Peardox</author>
	<name>Proximiti</name>
	<icon src="icon.png"/>
	<content src="index.html"/>
	<description>Location</description>
	
	<rim:permissions> 
	<!-- Location -->
		<rim:permit>read_geolocation</rim:permit> 
		<rim:permit>access_location_services</rim:permit>
		
	<!-- uuid + IMEI -->
		<rim:permit>read_device_identifying_information</rim:permit>
	</rim:permissions>
	
	<!-- Basic App stuff -->
	<feature id="blackberry.app" required="true" version="1.0.0.0"/>

	<!-- Compass -->
	<feature id="blackberry.sensors" />

	<!-- uuid + IMEI -->
	<feature id="blackberry.identity" />

	<!-- Docs say this is needed but BBWP don't find it -->
	<feature id="blackberry.identity.phone" />
	
	<!-- Device Caps -->
	<feature id="blackberry.system" />
	
	<!-- Keep Alive -->
	<feature id="community.preventsleep" required="true" version="1.0.0.0" />
	
	<access uri="*" subdomains="true" />
	<access uri="http://peardox.com" subdomains="true" />
	<access uri="http://192.168.0.31" subdomains="true" />
	<access uri="https://googleapis.com" subdomains="true" />
	<access uri="https://gstatic.com" subdomains="true" />

</widget>

 

index.html

<!DOCTYPE html>
<html>
<head>
<title>Proximiti</title>

<script type="text/javascript" src="script/jquery.1.9.1.min.js"></script>
<script type="text/javascript" src="local:///chrome/webworks.js"></script>

<script type="text/javascript">
	var comp_freq = 250; 	// Compass Frequency
	var dpr = false;
	
	if(typeof window.devicePixelRatio != 'undefined') // Does device support devicePixelRatio?
		{
		dpr = window.devicePixelRatio;
		}
	
	var meta = document.createElement("meta");
	meta.setAttribute('name','viewport');
	if(dpr) // Set up the right meta
		{
		meta.setAttribute('content','initial-scale='+ (1/window.devicePixelRatio) + ',user-scalable=no');
		}
	else
		{
		dpr = 1;
		meta.setAttribute('content','user-scalable=no,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,width=device-height,width=device-height');
		}
		
	document.getElementsByTagName('head')[0].appendChild(meta); // Inject meta

function JQLoaded() { // Called by JQ's ready
	document.addEventListener("webworksready", onWebworksReady, false);
	}
	
function onWebworksReady() {
	blackberry.event.addEventListener("pause", onPause);
	start();
	}
	
function onPause()
	{
	alert("The app is about to be paused.");
	}

// Create a callback to handle each sensor
function compassCallback(data) {
	if(data) {
		var dir = data.value;
		
		if(data.isFaceDown) {
			dir = Math.abs(180 - dir);
			}
	
		heading = Math.floor(dir);
		$('#compasstxt').html(heading  + '&deg;');
		}
	}

function startBBCompass() {
	// Start listening to the compass sensor with a delay feedback of 1000 microseconds 
	blackberry.sensors.setOptions("devicecompass", { delay: comp_freq, background: true, batching: true });
	   
	// Start the event listener for the sensors callback
	blackberry.event.addEventListener("devicecompass", compassCallback);
	  
	}
	
function getBBDeviceInfo() {
	devcaps = new Object();

	devcaps.aver = blackberry.app.version;	
	devcaps.hwid = blackberry.system.hardwareId;
	devcaps.uuid = blackberry.identity.uuid;

	devcaps.name = blackberry.system.name;
	devcaps.osver = blackberry.system.softwareVersion;
	
	devcaps.imei = blackberry.identity.IMEI;
	devcaps.gps = blackberry.system.hasCapability("location.gps");
	
	devcaps.touch = blackberry.system.hasCapability("input.touch");

	devcaps.lang = blackberry.system.language;
	devcaps.regn = blackberry.system.region;
	
	if(devcaps) {
		data = { rtype	: 1,
				 aver 	: devcaps.aver,
				 hwid 	: devcaps.hwid,
				 name 	: devcaps.name,
				 osver 	: devcaps.osver,
				 uuid 	: devcaps.uuid,
				 imei 	: devcaps.imei,
				 gps 	: devcaps.gps,
				 touch 	: devcaps.touch,
				 name 	: devcaps.name,
				 regn 	: devcaps.regn,
				 user	: 'fred',
				 pass	: 'pass'
				 };
				 
//		send_data(data);
		}
	}
	
function start()
	{	
	if(typeof(community) != 'undefined') {
		community.preventsleep.setPreventSleep(true);
		}
	getBBDeviceInfo();
	startBBCompass();
	}
	
$(document).ready(function() {
	JQLoaded();
	});
	
</script>
</head>
<body>
	<div id="compasstxt" style="font-size: 96px"></div>
</body>
</html>

 

 

 

 

 

 




Click the like button if you find my posts useful!
Please use plain text.
BlackBerry Development Advisor
twindsor
Posts: 795
Registered: ‎07-15-2008
My Device: Z10
My Carrier: Bell

Re: Can't find variable: webworks (Sensors)

This is a minor bug that my colleague, Anzor, found recently too. 

 

We're planning to submit an issue, but you're welcome to do so on the public issue tracker and we'll escalate it internally.

 

As far as I can see, you don't get error messages thrown unless you do a CTRL+r in WebInspector. We think it's because the listeners aren't being detached, or not detached soon enough, when you do that refresh.

Tim Windsor
Application Development Advisor II
Please use plain text.