Use window.location.protocol to choose between ws:// and wss:// shcheme.