blob: c89c6ae0e8c4a7b46a1c029cc1cf76ce97300971 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
(function() {
window.UoSLive = {};
var busStopRequests = {};
var busStopCache = {};
UoSLive.getBusStopURL = function(busStop) {
var base = "http://bus.southampton.ac.uk/bus-stop/";
var url = base + busStop + ".json";
return url;
};
UoSLive.subscribeToBusStop = function(busStop, callback) {
if (busStop in busStopCache) {
var result = busStopCache[busStop];
if (result.timeFetched > (Date.now() - 60000)) {
callback(result);
}
}
var url = UoSLive.getBusStopURL(busStop);
var req = new Pollymer.Request();
busStopRequests[busStop] = req;
req.recurring = true;
req.on('finished', function(code, result, headers) {
result.timeFetched = Date.now();
busStopCache[busStop] = result;
callback(result);
});
req.on('error', function(reason) {
});
req.maxTries = -1;
req.maxDelay = 60000;
req.minDelay = 60000;
req.start('GET', url);
};
UoSLive.unsubscribeToBusStop = function(busStop) {
var req = busStopRequests[busStop];
req.abort();
}
})();
|