summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/contrib/samples/comet-webapp/src/main/webapp/js/org.apache.tuscany.sca.cometComponentContext.js
blob: c8dc19d15aba5d32d15158c32e53a2b1c7e20ff0 (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
// TODO: Try isolating functional code one piece at a time by using it like in the inital version
var tuscanyComet = {
	connectedEndpoint : null,
	connect : function(transport) {
		$.atmosphere.subscribe(document.location.toString() + 'tuscany-comet',
				this.callback, 
				$.atmosphere.request = {
					transport : transport
				});
		this.connectedEndpoint = $.atmosphere.response;
	},
	callAsync : function(url, callbackMethod) {
		this.connectedEndpoint.push(document.location.toString()
				+ 'tuscany-comet/' + url,
				null, 
				$.atmosphere.request = {
					method : 'POST',
					data : 'callback=' + callbackMethod.name
				});
	},
	callback : function(response) {
		var data = response.responseBody;
		if (data.indexOf('#') != -1) {
			var callbackMethod = data.substring(0, data.indexOf('#'));
			data = data.substring(data.indexOf('#') + 1);
			eval(callbackMethod + '("' + data + '");');
		}
	}
};

// To be generated
var cometComponentContext = {
	c1 : {
		TemperatureService : {
			getTemperatureCelsius : function(callbackMethod) {
				tuscanyComet.callAsync('c1/TemperatureService/getTemperatureCelsius', callbackMethod);
			},
			getTemperatureFahrenheit : function(callbackMethod) {
				tuscanyComet.callAsync('c1/TemperatureService/getTemperatureFahrenheit', callbackMethod);
			}
		},
		HumidityService : {
			getHumidity : function(callbackMethod) {
				tuscanyComet.callAsync('c1/HumidityService/getHumidity', callbackMethod);
			}
		}
	},
	c2 : {
		PrecipitationService : {
			getPrecipitation : function(callbackMethod) {
				tuscanyComet.callAsync('c2/PrecipitationService/getPrecipitation', callbackMethod);
			}
		}
	}
}