Move this to the top of the file as a private function that takes in a connection.

So

```C#
function isConnectedOrReconnecting(connection) {
...
}
```