-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0512da
commit 3215e27
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
"use strict"; | ||
|
||
define(['ably', 'shared_helper', 'async'], function(Ably, helper, async) { | ||
var exports = {}, | ||
closeAndFinish = helper.closeAndFinish, | ||
monitorConnection = helper.monitorConnection, | ||
// Ably.Realtime.ConnectionManager not defined in node | ||
availableHttpTransports = typeof Ably.Realtime.ConnectionManager === 'undefined' ? Ably.Realtime.Defaults.httpTransports : Object.keys(Ably.Realtime.ConnectionManager.httpTransports); | ||
|
||
|
||
exports.setupConnectivity = function(test) { | ||
test.expect(1); | ||
helper.setupApp(function(err) { | ||
if(err) { | ||
test.ok(false, helper.displayError(err)); | ||
} else { | ||
test.ok(true, 'app set up'); | ||
} | ||
test.done(); | ||
}); | ||
}; | ||
|
||
/* | ||
* Connect with available http transports; internet connectivity check should work | ||
*/ | ||
exports.http_connectivity_check = function(test) { | ||
test.expect(availableHttpTransports.length); | ||
try { | ||
var connectivity_test = function(transports) { | ||
return function(cb) { | ||
var realtime = helper.AblyRealtime({transports: transports}); | ||
/* Not strictly necessary to connect before doing connectivity check, | ||
* but it's a simple way to get a reference to the transport */ | ||
realtime.connection.on('connected', function() { | ||
//console.log("Transport " + transports + " connected, trying connectivity check"); | ||
var transport = realtime.connection.connectionManager.activeProtocol.transport.constructor; | ||
transport.checkConnectivity(function(err, res) { | ||
//console.log("Transport " + transports + " connectivity check returned ", err, res) | ||
if(err) | ||
cb(err, realtime); | ||
test.ok(res, 'Connectivity check for ' + transports); | ||
cb(null, realtime); | ||
}) | ||
}); | ||
monitorConnection(test, realtime); | ||
}; | ||
}; | ||
async.parallel( | ||
availableHttpTransports.map(function(transport) { | ||
return connectivity_test([transport]); | ||
}), | ||
function(err, realtimes) { | ||
if(err) { | ||
console.log("errrrr", err) | ||
test.ok(false, helper.displayError(err)); | ||
} | ||
closeAndFinish(test, realtimes); | ||
} | ||
); | ||
} catch(e) { | ||
test.ok(false, 'connection failed with exception: ' + e.stack); | ||
closeAndFinish(test, realtime); | ||
} | ||
}; | ||
|
||
return module.exports = helper.withTimeout(exports); | ||
}); |