diff --git a/Sources/com.morphclue.wakatime.sdPlugin/main.js b/Sources/com.morphclue.wakatime.sdPlugin/main.js index 42663e8..2b784cf 100644 --- a/Sources/com.morphclue.wakatime.sdPlugin/main.js +++ b/Sources/com.morphclue.wakatime.sdPlugin/main.js @@ -133,40 +133,21 @@ function calculateRemainingMinutes(durations, minutesToReach) { } function getWebsocketReason(event) { - let reason; - if (event.code === 1000) { - reason = 'Normal Closure. The purpose for which the connection was established has been fulfilled.'; - } else if (event.code === 1001) { - reason = 'Going Away. An endpoint is "going away", ' + - 'such as a server going down or a browser having navigated away from a page.'; - } else if (event.code === 1002) { - reason = 'Protocol error. An endpoint is terminating the connection due to a protocol error'; - } else if (event.code === 1003) { - reason = "Unsupported Data. An endpoint received a type of data it doesn't support."; - } else if (event.code === 1004) { - reason = '--Reserved--. The specific meaning might be defined in the future.'; - } else if (event.code === 1005) { - reason = 'No Status. No status code was actually present.'; - } else if (event.code === 1006) { - reason = 'Abnormal Closure. ' + - 'The connection was closed abnormally, e.g., without sending or receiving a Close control frame'; - } else if (event.code === 1007) { - reason = 'Invalid frame payload data. ' + - 'The connection was closed, because the received data was not consistent with the type of the message.'; - } else if (event.code === 1008) { - reason = 'Policy Violation. The connection was closed, because current message data "violates its policy". '; - } else if (event.code === 1009) { - reason = 'Message Too Big. Connection closed because the message is too big for it to process.'; - } else if (event.code === 1010) { - reason = 'Mandatory Ext. Connection is terminated the connection because the server didn\'t ' + - 'negotiate one or more extensions in the WebSocket handshake.' + event.reason; - } else if (event.code === 1011) { - reason = 'Internal Server Error. Connection closed because it encountered an unexpected ' + - 'condition that prevented it from fulfilling the request.'; - } else if (event.code === 1015) { - reason = 'TLS Handshake. The connection was closed due to a failure to perform a TLS handshake'; - } else { - reason = 'Unknown reason'; - } - return reason; + const reasons = { + 1000: 'Normal Closure. The purpose for which the connection was established has been fulfilled.', + 1001: 'Going Away. An endpoint is "going away", such as a server going down or a browser having navigated away from a page.', + 1002: 'Protocol error. An endpoint is terminating the connection due to a protocol error', + 1003: "Unsupported Data. An endpoint received a type of data it doesn't support.", + 1004: '--Reserved--. The specific meaning might be defined in the future.', + 1005: 'No Status. No status code was actually present.', + 1006: 'Abnormal Closure. The connection was closed abnormally, e.g., without sending or receiving a Close control frame', + 1007: 'Invalid frame payload data. The connection was closed, because the received data was not consistent with the type of the message.', + 1008: 'Policy Violation. The connection was closed, because current message data "violates its policy". ', + 1009: 'Message Too Big. Connection closed because the message is too big for it to process.', + 1010: 'Mandatory Ext. Connection is terminated the connection because the server didn\'t negotiate one or more extensions in the WebSocket handshake.' + event.reason, + 1011: 'Internal Server Error. Connection closed because it encountered an unexpected condition that prevented it from fulfilling the request.', + 1015: 'TLS Handshake. The connection was closed due to a failure to perform a TLS handshake', + }; + + return reasons[event.code] || 'Unknown reason'; }