8 messages in com.googlegroups.google-gearsRe: [google-gears] Re: Network Detect...| From | Sent On | Attachments |
|---|---|---|
| Dimitri Glazkov | 02 Feb 2008 07:31 | |
| 하대환 | 02 Feb 2008 08:50 | |
| Aaron Boodman | 02 Feb 2008 10:03 | |
| Aaron Boodman | 02 Feb 2008 10:07 | |
| Dimitri Glazkov | 02 Feb 2008 11:22 | |
| Aaron Boodman | 02 Feb 2008 11:27 | |
| Aaron Boodman | 02 Feb 2008 11:47 | |
| 하대환 | 02 Feb 2008 17:59 |
| Subject: | Re: [google-gears] Re: Network Detection for Gears![]() |
|---|---|
| From: | Dimitri Glazkov (dimi...@gmail.com) |
| Date: | 02/02/2008 07:31:16 AM |
| List: | com.googlegroups.google-gears |
Since we're sharing connection monitoring code, here's mine from the tutorial (http://glazkov.com/blog/gears-asp-net-tutorial/)
http://code.google.com/p/glazkov-attic/source/browse/trunk/YourTimesheets/Scripts/monitor.js
:DG<
On Feb 2, 2008 6:31 AM, 하대환 <fatm...@gmail.com> wrote:
Good post and blog.
here's mine.
================== is server available? ===============================
var Available = function(onCallBack, offCallBack) { this.onCB = onCallBack; this.offCB = offCallBack;
this._worker = this.roll(); };
Available.prototype.roll = function() { return setInterval(this.bind(this.doCheck), "5000"); }
Available.prototype.regCallback = function(oncase, func) { if(oncase.toLowerCase == "online") this.onCB = func; else this.offCB = func; };
Available.prototype.discode = { 0: true, 500: true, 502: true, 503: true, 509: true };
Available.prototype._xhrCandidates = [ function() { return new XMLHttpRequest(); }, function() { return new ActiveXObject('Msxml2.XMLHTTP'); }, function() { return new ActiveXObject('Microsoft.XMLHTTP'); }, function() { return new ActiveXObject('Msxml2.XMLHTTP.4.0'); }, ];
Available.prototype.xhr = function() { if(!this.__xhr) { find_XMLHTTP: for(var i=0; i<this._xhrCandidates.length; i++) { try { this.__xhr = this._xhrCandidates[i](); break find_XMLHTTP; } catch(e) { } } }
return this.__xhr; };
Available.prototype.doCheck = function() { try { var url = location.protocol + "//" + location.hostname + "/" + new Date().getTime();
this.xhr().open('GET', url, false); this.xhr().send(null);
var callback = (this.xhr().status in this.discode) ? "offCB" : "onCB"; if(callback) this[callback](); } catch(e) { if(this._worker) clearInterval(this._worker); } };
Available.prototype.bind = function(func) { var scope = this; return function() { return func.apply(scope); } };
//=========== use ================
new Available( function() { // when on alert("online") }, function() { // when off alert("offline") } );
2008/2/2, dfalck <davi...@gmail.com>:
I found this to be a really good tutorial and source of ideas/ inspiration for detecting your network when going offline:
http://positionabsolute.net/blog/2007/09/google-gears-offline-detection.php




