Skip to content

Commit

Permalink
rename sendHints.string to sendHints.text
Browse files Browse the repository at this point in the history
  • Loading branch information
tsctx committed Jul 7, 2024
1 parent d58078c commit 8fb8f0f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/web/websocket/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const parserStates = {
const emptyBuffer = Buffer.allocUnsafe(0)

const sendHints = {
string: 1,
text: 1,
typedArray: 2,
arrayBuffer: 3,
blob: 4
Expand Down
9 changes: 4 additions & 5 deletions lib/web/websocket/sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,17 @@ class SendQueue {
}

function createFrame (data, hint) {
return new WebsocketFrameSend(toBuffer(data, hint)).createFrame(hint === sendHints.string ? opcodes.TEXT : opcodes.BINARY)
return new WebsocketFrameSend(toBuffer(data, hint)).createFrame(hint === sendHints.text ? opcodes.TEXT : opcodes.BINARY)
}

function toBuffer (data, hint) {
switch (hint) {
case sendHints.string:
return typeof data === 'string' ? Buffer.from(data) : data
case sendHints.text:
case sendHints.typedArray:
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength)
case sendHints.arrayBuffer:
case sendHints.blob:
return new Uint8Array(data)
case sendHints.typedArray:
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength)
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/web/websocket/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class WebSocket extends EventTarget {
this.#bufferedAmount += buffer.byteLength
this.#sendQueue.add(buffer, () => {
this.#bufferedAmount -= buffer.byteLength
}, sendHints.string)
}, sendHints.text)
} else if (types.isArrayBuffer(data)) {
// If the WebSocket connection is established, and the WebSocket
// closing handshake has not yet started, then the user agent must
Expand Down

0 comments on commit 8fb8f0f

Please sign in to comment.