diff options
Diffstat (limited to 'sca-java-2.x/contrib/samples/stock-comet/src/main/webapp/js/org.apache.tuscany.sca.cometComponentContext.js')
-rw-r--r-- | sca-java-2.x/contrib/samples/stock-comet/src/main/webapp/js/org.apache.tuscany.sca.cometComponentContext.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/sca-java-2.x/contrib/samples/stock-comet/src/main/webapp/js/org.apache.tuscany.sca.cometComponentContext.js b/sca-java-2.x/contrib/samples/stock-comet/src/main/webapp/js/org.apache.tuscany.sca.cometComponentContext.js new file mode 100644 index 0000000000..c8dc19d15a --- /dev/null +++ b/sca-java-2.x/contrib/samples/stock-comet/src/main/webapp/js/org.apache.tuscany.sca.cometComponentContext.js @@ -0,0 +1,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); + } + } + } +}
\ No newline at end of file |