Dynamically connecting to http or https now for the WebSocket connection (thanks bymerej).