@@ -890,19 +890,19 @@ function ActionClient(options) {
890
890
var receivedStatus = false ;
891
891
892
892
// create the topics associated with actionlib
893
- var feedbackListener = new Topic ( {
893
+ this . feedbackListener = new Topic ( {
894
894
ros : this . ros ,
895
895
name : this . serverName + '/feedback' ,
896
896
messageType : this . actionName + 'Feedback'
897
897
} ) ;
898
898
899
- var statusListener = new Topic ( {
899
+ this . statusListener = new Topic ( {
900
900
ros : this . ros ,
901
901
name : this . serverName + '/status' ,
902
902
messageType : 'actionlib_msgs/GoalStatusArray'
903
903
} ) ;
904
904
905
- var resultListener = new Topic ( {
905
+ this . resultListener = new Topic ( {
906
906
ros : this . ros ,
907
907
name : this . serverName + '/result' ,
908
908
messageType : this . actionName + 'Result'
@@ -926,7 +926,7 @@ function ActionClient(options) {
926
926
927
927
// subscribe to the status topic
928
928
if ( ! this . omitStatus ) {
929
- statusListener . subscribe ( function ( statusMessage ) {
929
+ this . statusListener . subscribe ( function ( statusMessage ) {
930
930
receivedStatus = true ;
931
931
statusMessage . status_list . forEach ( function ( status ) {
932
932
var goal = that . goals [ status . goal_id . id ] ;
@@ -939,7 +939,7 @@ function ActionClient(options) {
939
939
940
940
// subscribe the the feedback topic
941
941
if ( ! this . omitFeedback ) {
942
- feedbackListener . subscribe ( function ( feedbackMessage ) {
942
+ this . feedbackListener . subscribe ( function ( feedbackMessage ) {
943
943
var goal = that . goals [ feedbackMessage . status . goal_id . id ] ;
944
944
if ( goal ) {
945
945
goal . emit ( 'status' , feedbackMessage . status ) ;
@@ -950,7 +950,7 @@ function ActionClient(options) {
950
950
951
951
// subscribe to the result topic
952
952
if ( ! this . omitResult ) {
953
- resultListener . subscribe ( function ( resultMessage ) {
953
+ this . resultListener . subscribe ( function ( resultMessage ) {
954
954
var goal = that . goals [ resultMessage . status . goal_id . id ] ;
955
955
956
956
if ( goal ) {
@@ -980,6 +980,17 @@ ActionClient.prototype.cancel = function() {
980
980
this . cancelTopic . publish ( cancelMessage ) ;
981
981
} ;
982
982
983
+ /**
984
+ * Unsubscribe and unadvertise all topics associated with this ActionClient.
985
+ */
986
+ ActionClient . prototype . dispose = function ( ) {
987
+ this . goalTopic . unadvertise ( ) ;
988
+ this . cancelTopic . unadvertise ( ) ;
989
+ if ( ! this . omitStatus ) { this . statusListener . unsubscribe ( ) ; }
990
+ if ( ! this . omitFeedback ) { this . feedbackListener . unsubscribe ( ) ; }
991
+ if ( ! this . omitResult ) { this . resultListener . unsubscribe ( ) ; }
992
+ } ;
993
+
983
994
module . exports = ActionClient ;
984
995
985
996
} , { "../core/Message" :10 , "../core/Topic" :17 , "eventemitter2" :1 } ] , 6 :[ function ( require , module , exports ) {
@@ -2420,10 +2431,11 @@ function Topic(options) {
2420
2431
this . latch = options . latch || false ;
2421
2432
this . queue_size = options . queue_size || 100 ;
2422
2433
this . queue_length = options . queue_length || 0 ;
2434
+ this . reconnect_on_close = options . reconnect_on_close || true ;
2423
2435
2424
2436
// Check for valid compression types
2425
2437
if ( this . compression && this . compression !== 'png' &&
2426
- this . compression !== 'none' ) {
2438
+ this . compression !== 'none' ) {
2427
2439
this . emit ( 'warning' , this . compression +
2428
2440
' compression is not supported. No compression will be used.' ) ;
2429
2441
}
@@ -2435,6 +2447,27 @@ function Topic(options) {
2435
2447
}
2436
2448
2437
2449
var that = this ;
2450
+ if ( this . reconnect_on_close ) {
2451
+ this . callForSubscribeAndAdvertise = function ( message ) {
2452
+ that . ros . callOnConnection ( message ) ;
2453
+
2454
+ that . waitForReconnect = false ;
2455
+ that . reconnectFunc = function ( ) {
2456
+ if ( ! that . waitForReconnect ) {
2457
+ that . waitForReconnect = true ;
2458
+ that . ros . callOnConnection ( message ) ;
2459
+ that . ros . once ( 'connection' , function ( ) {
2460
+ that . waitForReconnect = false ;
2461
+ } ) ;
2462
+ }
2463
+ } ;
2464
+ that . ros . on ( 'close' , that . reconnectFunc ) ;
2465
+ } ;
2466
+ }
2467
+ else {
2468
+ this . callForSubscribeAndAdvertise = this . ros . callOnConnection ;
2469
+ }
2470
+
2438
2471
this . _messageCallback = function ( data ) {
2439
2472
that . emit ( 'message' , new Message ( data ) ) ;
2440
2473
} ;
@@ -2456,7 +2489,8 @@ Topic.prototype.subscribe = function(callback) {
2456
2489
if ( this . subscribeId ) { return ; }
2457
2490
this . ros . on ( this . name , this . _messageCallback ) ;
2458
2491
this . subscribeId = 'subscribe:' + this . name + ':' + ( ++ this . ros . idCounter ) ;
2459
- this . ros . callOnConnection ( {
2492
+
2493
+ this . callForSubscribeAndAdvertise ( {
2460
2494
op : 'subscribe' ,
2461
2495
id : this . subscribeId ,
2462
2496
type : this . messageType ,
@@ -2485,6 +2519,9 @@ Topic.prototype.unsubscribe = function(callback) {
2485
2519
if ( ! this . subscribeId ) { return ; }
2486
2520
// Note: Don't call this.removeAllListeners, allow client to handle that themselves
2487
2521
this . ros . off ( this . name , this . _messageCallback ) ;
2522
+ if ( this . reconnect_on_close ) {
2523
+ this . ros . off ( 'close' , this . reconnectFunc ) ;
2524
+ }
2488
2525
this . emit ( 'unsubscribe' ) ;
2489
2526
this . ros . callOnConnection ( {
2490
2527
op : 'unsubscribe' ,
@@ -2494,6 +2531,7 @@ Topic.prototype.unsubscribe = function(callback) {
2494
2531
this . subscribeId = null ;
2495
2532
} ;
2496
2533
2534
+
2497
2535
/**
2498
2536
* Registers as a publisher for the topic.
2499
2537
*/
@@ -2502,7 +2540,7 @@ Topic.prototype.advertise = function() {
2502
2540
return ;
2503
2541
}
2504
2542
this . advertiseId = 'advertise:' + this . name + ':' + ( ++ this . ros . idCounter ) ;
2505
- this . ros . callOnConnection ( {
2543
+ this . callForSubscribeAndAdvertise ( {
2506
2544
op : 'advertise' ,
2507
2545
id : this . advertiseId ,
2508
2546
type : this . messageType ,
@@ -2511,6 +2549,13 @@ Topic.prototype.advertise = function() {
2511
2549
queue_size : this . queue_size
2512
2550
} ) ;
2513
2551
this . isAdvertised = true ;
2552
+
2553
+ if ( ! this . reconnect_on_close ) {
2554
+ var that = this ;
2555
+ this . ros . on ( 'close' , function ( ) {
2556
+ that . isAdvertised = false ;
2557
+ } ) ;
2558
+ }
2514
2559
} ;
2515
2560
2516
2561
/**
@@ -2520,6 +2565,9 @@ Topic.prototype.unadvertise = function() {
2520
2565
if ( ! this . isAdvertised ) {
2521
2566
return ;
2522
2567
}
2568
+ if ( this . reconnect_on_close ) {
2569
+ this . ros . off ( 'close' , this . reconnectFunc ) ;
2570
+ }
2523
2571
this . emit ( 'unadvertise' ) ;
2524
2572
this . ros . callOnConnection ( {
2525
2573
op : 'unadvertise' ,
@@ -3047,6 +3095,16 @@ TFClient.prototype.unsubscribe = function(frameID, callback) {
3047
3095
}
3048
3096
} ;
3049
3097
3098
+ /**
3099
+ * Unsubscribe and unadvertise all topics associated with this TFClient.
3100
+ */
3101
+ TFClient . prototype . dispose = function ( ) {
3102
+ this . actionClient . dispose ( ) ;
3103
+ if ( this . currentTopic ) {
3104
+ this . currentTopic . unsubscribe ( ) ;
3105
+ }
3106
+ } ;
3107
+
3050
3108
module . exports = TFClient ;
3051
3109
3052
3110
} , { "../actionlib/ActionClient" :5 , "../actionlib/Goal" :7 , "../core/Service.js" :13 , "../core/ServiceRequest.js" :14 , "../math/Transform" :21 } ] , 26 :[ function ( require , module , exports ) {
0 commit comments