Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((_resolve, _reject) => {
if (ws.readyState !== WS.OPEN) {
//we may have closed whilst waiting for the token.
//always retry.
emit({
name: 'ws:close-before-send',
data: null,
});
return connectionClosedBeforeSend;
}
ref();
let called = false;
const callback = (err, data) => {
if (called) {
return;
self.on('finish', function() {
if (self.socket && self.socket.readyState === W3CWebSocket.OPEN) {
self.socket.send(JSON.stringify(closingMessage));
} else {
self.once('connect', function() {
self.socket.send(JSON.stringify(closingMessage));
});
}
});
self.on('finish', function() {
if (self.socket && self.socket.readyState === W3CWebSocket.OPEN) {
self.socket.send(JSON.stringify(closingMessage));
} else {
self.once('connect', function() {
self.socket.send(JSON.stringify(closingMessage));
});
}
});