Last active
January 30, 2018 22:56
-
-
Save sbrl/07c8c554d4f8bae4dd011b29070c8a72 to your computer and use it in GitHub Desktop.
[WebSocketStates] An ES6 module mapping the various WebSocket state constants onto their meanings. Could easily be refactored out to a regular javascript file. #es6 #module #microlibrary #websockets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
/** | |
* Constants for the different readyStates that a WebSocket can be in. | |
* @type {Object} | |
*/ | |
const WebSocketStates = { | |
/** | |
* Indicates that the WebSocket is connecting to the remote server. | |
* @type {Number} | |
*/ | |
connecting: 0, | |
/** | |
* Indicates that the WebSocket is connected to the remote server and ready to send / receive data. | |
* @type {Number} | |
*/ | |
ready: 1, | |
/** | |
* Indicates that the WebSocket is in the process of closing the connection to the remote server. | |
* @type {Number} | |
*/ | |
closing: 2, | |
/** | |
* Indicates that hte WebSocket is not connected to the remote server (either because the connection was closed, or dropped by the remote server). | |
* @type {Number} | |
*/ | |
closed: 3 | |
}; | |
const ReverseWebsocketStates = { | |
// The WebSocket is in the process of connecting. | |
0: "connecting", | |
// The WebSocket is connected and ready to exchange data with the remote server. | |
1: "ready", | |
// The WebSocket is in the process of closing. | |
2: "closing", | |
// The WebSocket is closed. | |
3: "closed" | |
} | |
export default WebSocketStates; | |
export const WebsocketStates = WebsocketStates; | |
export const ReverseWebsocketStates = ReverseWebsocketStates; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment