Hi Jeremy,
I tried and implemented what you said as follows, please let me know in case am still making it wrong.
Taking the eventHandlers implementation from YahooFinance Widget defined eventHandlers.
CODE
EventHandlers = {
onNetworkRestored:function()
{
log("##### restored network!");
},
onNetworkConnectionReconnect: function()
{
log("##### Reconnects!");
},
messageHandler: function(event){
log("##### in Message Handler!");
if (event.payload.key == 'noNetwork') {
log("##### in no network Handler!");
if (event.payload.value) {
log("##### in network is down!");
// network down
this.networkWasDown = true;
KONtx.HostEventManager.send("setIcons", ['noNetwork']);
if (!this.noNetworkDialog) {
var self = this;
this.noNetworkDialog = new KONtx.dialogs.Alert({
title: 'Network!',
message: 'Network not available.',
buttons: [{
label: 'OK',
callback: function(){
log("Exiting to dock!");
self.noNetworkDialog = null;
KONtx.HostEventManager.send("exitToDock");
}
}]
});
}
this.noNetworkDialog.show();
}
else {
log("##### in network is up!");
// network up
if (this.networkWasDown) {
this.networkWasDown = false;
KONtx.HostEventManager.send("setIcons", '');
if (this.noNetworkDialog && this.noNetworkDialog.show.call) {
this.noNetworkDialog.hide();
this.noNetworkDialog = null;
}
}
}
}
}
}
Mine init.js file
CODE
EventHandlers.messageHandler.subscribeTo(KONtx.messages,KONtx.messages.eventType,EventHandlers);
EventHandlers.onNetworkRestored.subscribeTo(KONtx.application,['onNetworkRestored'],EventHandlers);
EventHandlers.onNetworkConnectionReconnect.subscribeTo(KONtx.application,['onNetworkConnectionReconnect'],EventHandlers);
then a common function which is used by whole widget to call API has been made like this:
CODE
callAPI: function(){
var i = 0;
for (var param in this.params) {
if (this.params.hasOwnProperty(param)) {
if (i == 0) {
this.url.fullUrl = this.url().baseAddress + param + '=' + this.params[param];
}
else
this.url.fullUrl = this.url.fullUrl + '&' + param + '=' + this.params[param];
i++;
}
}
var u = new URL();
u.location = this.url.fullUrl;
log('Full URL is:' + this.url.fullUrl);
var response = u.fetch();
this.jsonResponse = response;
if (BIGFlix.Format.contains(response, "Could not load URL")) {
log("######Am setting networkRequestFailed true");
KONtx.application.setNetworkRequestFailed(true);
}
else {
log("######Am setting networkRequestFailed false");
KONtx.application.setNetworkRequestFailed(false);
}
},
I looked at the core/application.js of Framework and found that in the list of Subscribable events the following are there:
CODE
var subscribeableApplicationEvents = [
'onActivateBackButton',
'onActivateHomeButton',
'onActivateFavButton',
'onActivateSettingsButton',
'onActivateSnippet',
'onLoadView',
'onUnloadView',
'onShowView',
'onHideView',
'onSelectView',
'onUnselectView',
'getSnippetConfs',
'onDialogCancelled',
'onDialogDone',
'onApplicationStartup',
'onApplicationShutdown',
'onLoadProfile',
'onUnloadProfile',
'onWidgetKeyPress',
'onPlayControlKeyPress',
'onViewChangeInitiated',
'onCountryCodeChanged',
'onYahooLoginChanged',
'getProfileSnippetConfs',
];
I could not see the log generated when I am out of network or reconnect it, what else needs to be done for the same?
Thanks,
Ashish Jain