Skip to content

Commit

Permalink
fix(WebSocket): do not call public "server.send()" in message forwarding
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Oct 1, 2024
1 parent 39b4198 commit 8027386
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/interceptors/WebSocket/WebSocketServerConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {

const kEmitter = Symbol('kEmitter')
const kBoundListener = Symbol('kBoundListener')
const kSend = Symbol('kSend')

interface WebSocketServerEventMap {
open: Event
Expand Down Expand Up @@ -63,7 +64,7 @@ export class WebSocketServerConnection {
// so execute the logic on the next tick.
queueMicrotask(() => {
if (!event.defaultPrevented) {
this.send(event.data)
this[kSend](event.data)
}
})
})
Expand Down Expand Up @@ -203,6 +204,10 @@ export class WebSocketServerConnection {
* server.send(new TextEncoder().encode('hello'))
*/
public send(data: WebSocketData): void {
this[kSend](data)
}

private [kSend](data: WebSocketData): void {
const { realWebSocket } = this

invariant(
Expand Down

0 comments on commit 8027386

Please sign in to comment.