diff --git a/rocon_web_common/www/example/listener.html b/rocon_web_common/www/example/listener.html index 184849b..096e5cc 100644 --- a/rocon_web_common/www/example/listener.html +++ b/rocon_web_common/www/example/listener.html @@ -8,18 +8,18 @@ - + -
+Check your Web Console for Information(hit F12 in google chrome).
name : ' + message["name"] +'
'); + $("#masterinfopanel").append(''); + $("#masterinfopanel").append('name : ' + message.name +'
'); $("#masterinfopanel").append('master_url : ' + gUrl +'
'); - $("#masterinfopanel").append('description : ' + message["description"] +'
'); + $("#masterinfopanel").append('description : ' + message.description +'
'); }); } }); @@ -304,7 +353,7 @@ function getRoles() { uri : 'rocon:/*/*/*/' + browser }); ros.getServicesForType('rocon_interaction_msgs/GetRoles', function(service_name){ - if (service_name !== undefined || service_name.length > 0){ + if (service_name !== undefined && service_name.length > 0){ callService(ros, service_name[0], 'rocon_interaction_msgs/GetRoles', request, function(result) { for (var i = 0; i < result.roles.length; i++) { gListRoles.push(result.roles[i]); @@ -348,10 +397,14 @@ function getInteractions(selectedRole) { uri : 'rocon:/*/*/*/' + browser }); ros.getServicesForType('rocon_interaction_msgs/GetInteractions', function(service_name){ - if (service_name !== undefined || service_name.length > 0){ + if (service_name !== undefined && service_name.length > 0){ callService(ros, service_name[0], 'rocon_interaction_msgs/GetInteractions', request, function(result) { for (var i = 0; i < result.interactions.length; i++) { - gListInteractions.push(result.interactions[i]); + var interaction = result.interactions[i]; + if (interaction.hasOwnProperty('pairing')){ + interaction['is_paired_type'] = true; + } + gListInteractions.push(interaction); } displayInteractions(); }); @@ -442,7 +495,15 @@ function prepareWebappUrl(interaction, baseUrl) { * @param {interaction} interaction */ function displayDescription(interaction) { - $("#startappBtn").show(); + $("#startInteractionBtn").show(); + $("#stopInteractionBtn").show(); + if (checkIsRunningInteraction(interaction) === false){ + $("#stopInteractionBtn").attr('disabled',true); + } + else{ + $("#stopInteractionBtn").attr('disabled',false); + } + stopAllInteractionsBtnCtrl(); $("#descriptionpanel").append('name : ' + interaction["name"] + '
display_name : ' + interaction["display_name"] + '
'); @@ -461,6 +522,23 @@ function displayDescription(interaction) { $("#descriptionpanel").append('parameters : ' + interaction["parameters"] + '
'); } +/** + * Event function when item in role list and interaction list is clicked + * + * @function listItemSelect +*/ +function checkIsRunningInteraction(interaction){ + var targetHash = interaction.hash; + var isRunning = false; + for (var i = 0 ; i < gRunningInteractions.length ; i ++){ + if (gRunningInteractions[i].interaction_hash === targetHash){ + isRunning = true; + break; + } + } + return isRunning; +} + /** * Event function when item in role list and interaction list is clicked * @@ -499,56 +577,145 @@ function listItemSelect() { var index = $(this).attr('id').charAt($(this).attr('id').length - 1); gFinalUrl = classifyInteraction(gListInteractions[index]); gFinalHash = gListInteractions[index].hash; + gFinalIsPairedType = gListInteractions[index].is_paired_type; displayDescription(gListInteractions[index]); }); } /** * Check whether a new window is closed or not every time. - * If it is closed, the check function is also stopped. + * When it is closed, the check function is also stopped. * * @function checkRunningInteraction */ function checkRunningInteraction (window_handler, window_key){ if (window_handler.closed === true){ - for (i = 0 ; i < gRunningInteractions.length ; i ++){ + for (var i = 0 ; i < gRunningInteractions.length ; i ++){ if (gRunningInteractions[i].hasOwnProperty(window_key) === true){ clearInterval(gRunningInteractions[i][window_key]); gRunningInteractions.splice(i, 1); publishRemoconStatus(); - } } } } /** - * Event function when 'Start App' button is clicked + * Event function when 'Start Interaction' button is clicked * - * @function startApp + * @function startInteraction */ -function startApp() { - $("#startappBtn").hide(); - $("#startappBtn").click(function () { +function startInteraction() { + $("#startInteractionBtn").click(function () { var finalUrl = gFinalUrl; var finalHash = gFinalHash; var runningInteraction = {} var id = uuid(); + var request = new ROSLIB.ServiceRequest({ + remocon : gRemoconName, + hash : finalHash + }); + ros.getServicesForType('rocon_interaction_msgs/RequestInteraction', function(service_name){ + if (service_name !== undefined && service_name.length > 0){ + callService(ros, service_name[0], 'rocon_interaction_msgs/RequestInteraction', request, function(result){ + if (result.error_code === 0){ //https://raw.githubusercontent.com/robotics-in-concert/rocon_msgs/indigo/rocon_app_manager_msgs/msg/ErrorCodes.msg + (function(){ + if (finalUrl !== null){ + var new_window = window.open(finalUrl); + runningInteraction['window_handler'] = new_window; + runningInteraction[id] = setInterval(function(){ + checkRunningInteraction(new_window, id); + }, 1000); + } + runningInteraction['interaction_hash'] = finalHash; + gRunningInteractions.push(runningInteraction); + publishRemoconStatus(); + if (gFinalIsPairedType === true){ + gPairing = finalHash; + } + })(); + //button ctrl + $("#stopInteractionBtn").attr('disabled',false); + stopAllInteractionsBtnCtrl(); + } + else{ + alert('interaction request rejected [' + result.message + ']'); + } + }); + } + }); + }); +} - if (finalUrl == null) { - alert("not available on this platform"); - return; +/** + * Event function when 'Stop Interaction' button is clicked + * + * @function stopInteraction +*/ +function stopInteraction() { + $("#stopInteractionBtn").click(function () { + var finalHash = gFinalHash; + stopInteractions(finalHash); + $("#stopInteractionBtn").attr('disabled',true); + }); + +} + +/** + * Event function when 'Stop All Interactions' button is clicked + * + * @function stopAllInteractions +*/ +function stopAllInteractions() { + $("#stopAllInteractionsBtn").click(function () { + var RunningInteractions = $.extend([] , gRunningInteractions); //deep copy + for (var i = 0 ; i < RunningInteractions.length ; i ++){ + stopInteractions(RunningInteractions[i].interaction_hash); } - var new_window = window.open(finalUrl); - runningInteraction['interaction_hash'] = finalHash; - runningInteraction[id] = setInterval(function(){ - checkRunningInteraction(new_window, id); - }, 1000); - gRunningInteractions.push(runningInteraction); - publishRemoconStatus(); + $("#stopInteractionBtn").attr('disabled',true); }); } +/** + * Stop interaction with interaction hash. + * + * @function stopInteractions +*/ +function stopAllInteractionsBtnCtrl(){ + if(gRunningInteractions.length > 0){ + $("#stopAllInteractionsBtn").attr('disabled', false); + } + else{ + $("#stopAllInteractionsBtn").attr('disabled', true); + $("#stopInteractionBtn").attr('disabled', true); + } +} + +/** + * Stop interaction with interaction hash. + * + * @function stopInteractions +*/ + +function stopInteractions(interactionHash) { + for (var i = 0 ; i < gRunningInteractions.length ; i ++){ + if (gRunningInteractions[i].interaction_hash === interactionHash){ + if (gRunningInteractions[i].hasOwnProperty('window_handler') === true){ + var window_handler = gRunningInteractions[i].window_handler; + if (window_handler.closed === false){ + window_handler.close(); + } + } + gRunningInteractions.splice(i, 1); + publishRemoconStatus(); + if(gPairing !== null){ + gPairing = null; + } + } + } + stopAllInteractionsBtnCtrl(); +} + /** * Initialize all lists * @@ -589,7 +756,8 @@ function initRoleList() { function initInteractionList() { gListInteractions = []; $("#interactions_listgroup").children().remove(); - $("#startappBtn").hide(); + $("#startInteractionBtn").hide(); + $("#stopInteractionBtn").hide(); } /** @@ -599,7 +767,8 @@ function initInteractionList() { */ function initDescriptionList() { $("#descriptionpanel").children().remove(); - $("#startappBtn").hide(); + $("#startInteractionBtn").hide(); + $("#stopInteractionBtn").hide(); } /**