Skip to content

Commit 9a422b3

Browse files
committed
refactor: use MIN_FRAME_SIZE constant instead of magic number 8192
1 parent d305cd6 commit 9a422b3

3 files changed

Lines changed: 7 additions & 6 deletions

File tree

src/amqp-base-client.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { AMQPView } from "./amqp-view.js"
66
import type { Logger } from "./types.js"
77

88
export const VERSION = "3.4.1"
9+
export const MIN_FRAME_SIZE = 8192
910

1011
/**
1112
* Base class for AMQPClients.
@@ -50,7 +51,7 @@ export abstract class AMQPBaseClient {
5051
password: string,
5152
name?: string,
5253
platform?: string,
53-
frameMax = 8192,
54+
frameMax = MIN_FRAME_SIZE,
5455
heartbeat = 0,
5556
channelMax = 0,
5657
logger?: Logger | null,
@@ -69,7 +70,7 @@ export abstract class AMQPBaseClient {
6970
this.onerror = (error: AMQPError) => {
7071
this.logger?.error("amqp-client connection closed", error.message)
7172
}
72-
if (frameMax < 8192) throw new Error("frameMax must be 8192 or larger")
73+
if (frameMax < MIN_FRAME_SIZE) throw new Error(`frameMax must be ${MIN_FRAME_SIZE} or larger`)
7374
this.frameMax = frameMax
7475
if (heartbeat < 0) throw new Error("heartbeat must be positive")
7576
this.heartbeat = heartbeat

src/amqp-socket-client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AMQPBaseClient } from "./amqp-base-client.js"
1+
import { AMQPBaseClient, MIN_FRAME_SIZE } from "./amqp-base-client.js"
22
import { AMQPChannel } from "./amqp-channel.js"
33
import { AMQPError } from "./amqp-error.js"
44
import type { AMQPTlsOptions } from "./amqp-tls-options.js"
@@ -33,7 +33,7 @@ export class AMQPClient extends AMQPBaseClient {
3333
const username = decodeURIComponent(u.username) || "guest"
3434
const password = decodeURIComponent(u.password) || "guest"
3535
const name = u.searchParams.get("name") || ""
36-
const frameMax = parseInt(u.searchParams.get("frameMax") || "8192")
36+
const frameMax = parseInt(u.searchParams.get("frameMax") || MIN_FRAME_SIZE.toString())
3737
const heartbeat = parseInt(u.searchParams.get("heartbeat") || "0")
3838
const channelMax = parseInt(u.searchParams.get("channelMax") || "0")
3939
const platform = `${process.release.name} ${process.version} ${process.platform} ${process.arch}`

src/amqp-websocket-client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AMQPBaseClient, VERSION } from "./amqp-base-client.js"
1+
import { AMQPBaseClient, VERSION, MIN_FRAME_SIZE } from "./amqp-base-client.js"
22
import { AMQPView } from "./amqp-view.js"
33
import { AMQPError } from "./amqp-error.js"
44
import { AMQPChannel } from "./amqp-channel.js"
@@ -49,7 +49,7 @@ export class AMQPWebSocketClient extends AMQPBaseClient {
4949
username = "guest",
5050
password = "guest",
5151
name?: string,
52-
frameMax = 8192,
52+
frameMax = MIN_FRAME_SIZE,
5353
heartbeat = 0,
5454
logger?: Logger | null,
5555
) {

0 commit comments

Comments
 (0)