1- import { AMQPBaseClient , VERSION , MIN_FRAME_SIZE } from "./amqp-base-client.js"
1+ import { AMQPBaseClient , VERSION } from "./amqp-base-client.js"
22import { AMQPView } from "./amqp-view.js"
33import { AMQPError } from "./amqp-error.js"
44import { AMQPChannel } from "./amqp-channel.js"
@@ -19,7 +19,7 @@ interface AMQPWebSocketInit {
1919}
2020
2121/**
22- * WebSocket client for AMQP 0-9-1 servers
22+ * WebSocket client for AMQP 0-9-1 servers.
2323 */
2424export class AMQPWebSocketClient extends AMQPBaseClient {
2525 readonly url : string
@@ -49,7 +49,7 @@ export class AMQPWebSocketClient extends AMQPBaseClient {
4949 username = "guest" ,
5050 password = "guest" ,
5151 name ?: string ,
52- frameMax = MIN_FRAME_SIZE ,
52+ frameMax = 8192 ,
5353 heartbeat = 0 ,
5454 logger ?: Logger | null ,
5555 ) {
@@ -72,6 +72,10 @@ export class AMQPWebSocketClient extends AMQPBaseClient {
7272 * Establish a AMQP connection over WebSocket
7373 */
7474 override connect ( ) : Promise < AMQPBaseClient > {
75+ this . framePos = 0
76+ this . frameSize = 0
77+ this . channels = [ new AMQPChannel ( this , 0 ) ]
78+
7579 const socket = new WebSocket ( this . url )
7680 this . socket = socket
7781 socket . binaryType = "arraybuffer"
@@ -85,25 +89,29 @@ export class AMQPWebSocketClient extends AMQPBaseClient {
8589 if ( ! this . closed ) {
8690 const err = new AMQPError ( ev . toString ( ) , this )
8791 this . closed = true
88- // Close all channels and their consumers when there's an error
8992 this . channels . forEach ( ( ch ) => ch ?. setClosed ( err ) )
9093 this . channels = [ new AMQPChannel ( this , 0 ) ]
9194 this . onerror ( err )
95+ this . ondisconnect ?.( err )
96+ this . socket = undefined
9297 }
9398 } )
9499 socket . addEventListener ( "close" , ( ev : CloseEvent ) => {
95100 const clientClosed = this . closed
96101 this . closed = true
97102 if ( ! ( ev . wasClean && clientClosed ) ) {
98103 const err = new AMQPError ( `connection not cleanly closed (${ ev . code } )` , this )
99- // Close all channels and their consumers when connection is lost
100104 this . channels . forEach ( ( ch ) => ch ?. setClosed ( err ) )
101105 this . channels = [ new AMQPChannel ( this , 0 ) ]
102106 this . onerror ( err )
107+ if ( ! clientClosed ) {
108+ this . ondisconnect ?.( err )
109+ }
103110 } else {
104111 this . channels . forEach ( ( ch ) => ch ?. setClosed ( ) )
105112 this . channels = [ new AMQPChannel ( this , 0 ) ]
106113 }
114+ this . socket = undefined
107115 } )
108116 socket . send ( new Uint8Array ( [ 65 , 77 , 81 , 80 , 0 , 0 , 9 , 1 ] ) )
109117 } )
@@ -194,3 +202,5 @@ export class AMQPWebSocketClient extends AMQPBaseClient {
194202}
195203
196204export { AMQPBaseClient , AMQPChannel , AMQPConsumer , AMQPError , AMQPMessage , AMQPQueue , AMQPView , VERSION }
205+ export { AMQPSession } from "./amqp-session.js"
206+ export type { AMQPSessionOptions } from "./amqp-session.js"
0 commit comments