private async void InitializeInBackground(int id, string url, MessageWebSocket webSocket, JObject options) { try { var parsedOptions = new WebSocketOptions(options); if (!string.IsNullOrEmpty(parsedOptions.ProxyAddress)) { webSocket.Control.ProxyCredential = new Windows.Security.Credentials.PasswordCredential { Resource = parsedOptions.ProxyAddress, UserName = parsedOptions.UserName, Password = parsedOptions.Password }; } if (!string.IsNullOrEmpty(parsedOptions.Origin)) { webSocket.SetRequestHeader("Origin", parsedOptions.Origin); } await webSocket.ConnectAsync(new Uri(url)).AsTask().ConfigureAwait(false); _webSocketConnections.Add(id, webSocket); var dataWriter = new DataWriter(webSocket.OutputStream) { UnicodeEncoding = UnicodeEncoding.Utf8, }; _dataWriters.Add(id, dataWriter); SendEvent("websocketOpen", new JObject { { "id", id }, }); } catch (Exception ex) { OnError(id, ex); } }
private void InitializeInBackground(string url, WebSocketSharp.WebSocket webSocket, JObject options) { var parsedOptions = new WebSocketOptions(options); ProxyHelper proxy = null; if (parsedOptions.UseDefaultProxy) { proxy = new ProxyHelper(new Uri(url)); } else { proxy = new ProxyHelper(parsedOptions); } if (proxy != null && !proxy.IsBypassed) { webSocket.SetProxy(proxy.ProxyAddress, proxy.UserName, proxy.Password); } webSocket.Origin = parsedOptions.Origin; webSocket.Connect(); }