Implement determineEndpoint function to simplify js sockets API