@@ -42,6 +42,7 @@ export class Session {
4242 private _baseSession : IBaseSession ;
4343 private _wampSession : WAMPSession ;
4444 private _idGen : SessionScopeIDGenerator = new SessionScopeIDGenerator ( ) ;
45+ private _onDisconnect ?: ( ) => Promise < void > ;
4546
4647 private _callRequests : Map < number , {
4748 resolve : ( value : Result ) => void ,
@@ -75,6 +76,7 @@ export class Session {
7576 constructor ( baseSession : IBaseSession ) {
7677 this . _baseSession = baseSession ;
7778 this . _wampSession = new WAMPSession ( baseSession . serializer ( ) ) ;
79+ this . _baseSession . setOnDisconnect ( async ( ) => await this . markDisconnected ( ) ) ;
7880
7981 ( async ( ) => {
8082 for ( ; ; ) {
@@ -84,6 +86,10 @@ export class Session {
8486 } ) ( ) ;
8587 }
8688
89+ setDisconnectCallback ( callback : ( ) => Promise < void > ) : void {
90+ this . _onDisconnect = callback ;
91+ }
92+
8793 private get _nextID ( ) : number {
8894 return this . _idGen . next ( ) ;
8995 }
@@ -219,13 +225,17 @@ export class Session {
219225 throw new ProtocolError ( wampErrorString ( message ) ) ;
220226 }
221227 } else if ( message instanceof Goodbye ) {
222- this . markDisconnected ( )
228+ await this . markDisconnected ( )
223229 } else {
224230 throw new ProtocolError ( `Unexpected message type ${ typeof message } ` ) ;
225231 }
226232 }
227233
228- private markDisconnected ( ) {
234+ private async markDisconnected ( ) {
235+ if ( this . _onDisconnect ) {
236+ await this . _onDisconnect ( ) ;
237+ }
238+
229239 if ( ! this . isConnected ( ) ) {
230240 return
231241 }
0 commit comments