Skip to content

Commit

Permalink
2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed Feb 24, 2021
1 parent d808957 commit 7eecfee
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "defer-to-connect",
"version": "2.0.0",
"version": "2.0.1",
"description": "The safe way to handle the `connect` socket event",
"main": "dist/source",
"files": [
Expand Down
6 changes: 5 additions & 1 deletion source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ interface Listeners {
close?: (hadError: boolean) => void;
}

function isTLSSocket(socket: any): socket is TLSSocket {
return socket.encrypted;
}

const deferToConnect = (socket: Socket | TLSSocket, fn: Listeners | (() => void)): void => {
let listeners: Listeners;

Expand All @@ -26,7 +30,7 @@ const deferToConnect = (socket: Socket | TLSSocket, fn: Listeners | (() => void)
listeners.connect!();
}

if (socket.encrypted && hasSecureConnectListener) {
if (isTLSSocket(socket) && hasSecureConnectListener) {
if (socket.authorized) {
listeners.secureConnect!();
} else if (!socket.authorizationError) {
Expand Down

0 comments on commit 7eecfee

Please sign in to comment.