Implement determineEndpoint function to simplify js sockets API

resolves #171