Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use default codes for close event (#287) #338

Merged
merged 1 commit into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/event/factory.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Event from './event';
import MessageEvent from './message';
import CloseEvent from './close';
import { CLOSE_CODES } from '../constants';

/*
* Creates an Event object and extends it to allow full modification of
Expand Down Expand Up @@ -54,7 +55,7 @@ function createCloseEvent(config) {
let { wasClean } = config;

if (!wasClean) {
wasClean = code === 1000;
wasClean = code === CLOSE_CODES.CLOSE_NORMAL || code === CLOSE_CODES.CLOSE_NO_STATUS;
}

const closeEvent = new CloseEvent(type, {
Expand Down
4 changes: 2 additions & 2 deletions src/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ class WebSocket extends EventTarget {
}

if (this.readyState === WebSocket.CONNECTING) {
failWebSocketConnection(this, code, reason);
failWebSocketConnection(this, code || CLOSE_CODES.CLOSE_ABNORMAL, reason);
} else {
closeWebSocketConnection(this, code, reason);
closeWebSocketConnection(this, code || CLOSE_CODES.CLOSE_NO_STATUS, reason);
}
}
}
Expand Down