Skip to content

Commit

Permalink
Merge pull request #34 from jaguardo/remove_listeners
Browse files Browse the repository at this point in the history
Remove listeners
  • Loading branch information
flynneva authored Apr 29, 2021
2 parents 2884d16 + 0127553 commit 1c715f7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-standard": "^4.0.1",
"gh-pages": "^2.2.0",
"microbundle-crl": "^0.13.10",
"microbundle-crl": "^0.13.11",
"npm-run-all": "^4.1.5",
"prettier": "^2.0.4",
"react": "^16.13.1",
Expand Down
25 changes: 24 additions & 1 deletion src/components/ROS.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function useROS() {
}
}
ros.listeners.push(newListener);
console.log('Listener created');
console.log('Listener ' + newListener.name + ' created');
return newListener;
}

Expand Down Expand Up @@ -105,17 +105,40 @@ function useROS() {
ros.ROS.close();
setROS(ros => ({ ...ros, isConnected: false }));
setROS(ros => ({ ...ros, topics: [] }));
setROS(ros => ({ ...ros, listeners: [] }));
} catch (e) {
console.log(e);
}
console.log('Disconnect Requested');
}

const removeAllListeners = () =>{
for(var mlistener in ros.listeners){
ros.listeners[mlistener].removeAllListeners();
}
setROS(ros => ({ ...ros, listeners: [] }));
}

function removeListener (listener){
for(var mlistener in ros.listeners){
if(listener.name === ros.listeners[mlistener].name){
console.log('Listener: ' + listener.name + ' is removed')
ros.listeners.splice(mlistener,1)
listener.removeAllListeners();
return
}
}
console.log('Listener: ' + listener + ' is not a listener')
}

return {
toggleConnection,
changeUrl,
getTopics,
createListener,
toggleAutoconnect,
removeAllListeners,
removeListener,
ros: ros.ROS,
isConnected: ros.isConnected,
autoconnect: ros.autoconnect,
Expand Down

0 comments on commit 1c715f7

Please sign in to comment.