incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From macdo...@apache.org
Subject [5/5] git commit: Fixing network connection for Android
Date Tue, 28 Feb 2012 13:53:22 GMT
Fixing network connection for Android

The newtork code in common js seems to have been pulled from BB. This wont' work on Android.
Android expects that only the string indicating the type is returned to getInfo, instead of
an object.


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/c01d1e72
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/c01d1e72
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/c01d1e72

Branch: refs/heads/master
Commit: c01d1e729a83d578c5fbc5785f6e5aa97f5d9fb6
Parents: 73d34c3
Author: macdonst <simon.macdonald@gmail.com>
Authored: Mon Feb 27 16:15:32 2012 -0500
Committer: macdonst <simon.macdonald@gmail.com>
Committed: Tue Feb 28 08:51:30 2012 -0500

----------------------------------------------------------------------
 lib/plugin/network.js |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/c01d1e72/lib/plugin/network.js
----------------------------------------------------------------------
diff --git a/lib/plugin/network.js b/lib/plugin/network.js
index ccfe4a7..3234f12 100644
--- a/lib/plugin/network.js
+++ b/lib/plugin/network.js
@@ -4,15 +4,29 @@ var exec = require('cordova/exec'),
 var NetworkConnection = function () {
         this.type = null;
         this._firstRun = true;
+        this._timer = null;
+        this.timeout = 500;
 
         var me = this,
             channel = require('cordova/channel');
 
         this.getInfo(
             function (info) {
-                me.type = info.type;
-                if (typeof info.event !== "undefined") {
-                    cordova.fireWindowEvent(info.event);
+                me.type = info;
+                if (info === "none") {
+                    // set a timer if still offline at the end of timer send the offline
event
+                    me._timer = setTimeout(function(){
+                        me.type = type;
+                        cordova.fireWindowEvent("offline");
+                        me._timer = null;
+                        }, me.timeout);
+                } else {
+                    // If there is a current offline event pending clear it
+                    if (me._timer !== null) {
+                        clearTimeout(me._timer);
+                        me._timer = null;
+                    }
+                    cordova.fireWindowEvent("online");
                 }
 
                 // should only fire this once


Mime
View raw message