Reputation: 7378
I'm developing a web application (precisely it's a Tizen web application), I got that 'undefined' error although I already defined the callback function serviceConnectionCallback
.
I'm new to javascript programming, hope you guys can help. Tks
Below is my code:
var serviceConnectionCallback = {
onconnect : onconnectFromPhone ,
onrequest : onRequest,
onerror : onerror
}
window.onload = function() {
//do something...
document.addEventListener("visibilitychange", pageVisibilityHandler, false);
};
function pageVisibilityHandler() {
if (document.hidden) {
console.log("hidden");
/*!!!!!!!!!!!!! PROBLEM HERE !!!!!!!!!!!!!!!!!!!!!!!!*/
webapis.sa.setServiceConnectionListener(serviceConnectionCallback);
} else {
console.log("visible");
}
}
Upvotes: 0
Views: 546
Reputation: 1426
When are you calling pageVisibilityHandler()
? The flow that I am using to reach setServiceConnectionListener
is as follows, starting from a connect()
method;
1. request an agent:
webapis.sa.requestSAAgent(onSuccess, onError);
2. set up the agents in onSuccess:
SAAgent = agents[0];
SAAgent.setPeerAgentFindListener(peerAgentFindCallback);
SAAgent.findPeerAgents();
3. set up the listeners:
SAAgent.setServiceConnectionListener(serviceConnectionCallback);
SAAgent.requestServiceConnection(peerAgent);
If you are skipping step 2, your local variable SAAgent
is never instantiated and you will get an undefined error. SAAgent is a local variable which you should have initialised as null
if you followed the guides.
Upvotes: 1