File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,7 @@ function session_per_connection(conn) {
82
82
'get_session' : function ( ) {
83
83
if ( ! ssn ) {
84
84
ssn = conn . create_session ( ) ;
85
+ ssn . observers . on ( 'session_close' , function ( ) { ssn = null ; } ) ;
85
86
ssn . begin ( ) ;
86
87
}
87
88
return ssn ;
Original file line number Diff line number Diff line change @@ -410,6 +410,7 @@ var Session = function (connection, local_channel) {
410
410
this . links = { } ; // map by name
411
411
this . options = { } ;
412
412
Object . defineProperty ( this , 'error' , { get : function ( ) { return this . remote . end ? this . remote . end . error : undefined ; } } ) ;
413
+ this . observers = new EventEmitter ( ) ;
413
414
} ;
414
415
Session . prototype = Object . create ( EventEmitter . prototype ) ;
415
416
Session . prototype . constructor = Session ;
@@ -436,6 +437,7 @@ Session.prototype._reconnect = function() {
436
437
437
438
Session . prototype . dispatch = function ( name ) {
438
439
log . events ( '[%s] Session got event: %s' , this . connection . options . id , name ) ;
440
+ EventEmitter . prototype . emit . apply ( this . observers , arguments ) ;
439
441
if ( this . listeners ( name ) . length ) {
440
442
EventEmitter . prototype . emit . apply ( this , arguments ) ;
441
443
return true ;
Original file line number Diff line number Diff line change @@ -693,4 +693,32 @@ describe('miscellaneous', function() {
693
693
} ) ;
694
694
client . connect ( listener . address ( ) as any ) . open_receiver ( ) ;
695
695
} ) ;
696
+
697
+ it ( 'handles session close' , function ( done : Function ) {
698
+ var closed_session = false ;
699
+ var outgoing = [ 'one' , 'two' ] as any ;
700
+ var incoming = [ ] as any ;
701
+ server . on ( 'sender_open' , function ( context : rhea . EventContext ) {
702
+ context . sender ! . send ( { subject :outgoing . shift ( ) } as rhea . Message ) ;
703
+ } ) ;
704
+ server . once ( 'accepted' , function ( context : rhea . EventContext ) {
705
+ closed_session = true ;
706
+ context . session ! . close ( ) ;
707
+ } ) ;
708
+ client . on ( 'session_close' , function ( context : rhea . EventContext ) {
709
+ context . connection . open_receiver ( ) ;
710
+ } ) ;
711
+ client . on ( 'message' , function ( context : rhea . EventContext ) {
712
+ incoming . push ( context . message ! . subject ) ;
713
+ if ( incoming . length == 2 ) {
714
+ context . connection . close ( ) ;
715
+ }
716
+ } ) ;
717
+ client . on ( 'connection_close' , function ( context : rhea . EventContext ) {
718
+ assert . deepEqual ( incoming , [ 'one' , 'two' ] ) ;
719
+ done ( ) ;
720
+ } ) ;
721
+ var conn = client . connect ( { port : ( listener . address ( ) as any ) . port , id : 'client' } ) ;
722
+ conn . open_receiver ( ) ;
723
+ } ) ;
696
724
} ) ;
You can’t perform that action at this time.
0 commit comments