public UWPSocketBase(Irc parent) { ConnCheck = new Connection(); ConnCheck.ConnectionChanged += async(connected) => await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => ConnectionChanged(connected) ); this.parent = parent; }
private void Closed(IWebSocket sender, WebSocketClosedEventArgs args) { var autoReconnect = Config.GetBoolean(Config.AutoReconnect); var msg = autoReconnect ? "Attempting to reconnect..." : "Please try again later."; var error = Irc.CreateBasicToast("Websocket closed", msg); ToastNotificationManager.CreateToastNotifier().Show(error); DisconnectAsync(attemptReconnect: autoReconnect); }
public IrcSocket(Irc irc) : base(irc) { }
public override async void Connect() { if (server == null) { return; } IsAuthed = false; ReadOrWriteFailed = false; if (!ConnCheck.HasInternetAccess) { var autoReconnect = Config.GetBoolean(Config.AutoReconnect); var msg = autoReconnect ? "We'll try to connect once a connection is available." : "Please try again once your connection is restored"; var error = Irc.CreateBasicToast("No connection detected.", msg); error.ExpirationTime = DateTime.Now.AddDays(2); ToastNotificationManager.CreateToastNotifier().Show(error); if (!autoReconnect) { DisconnectAsync(attemptReconnect: autoReconnect); } return; } streamSocket = new StreamSocket(); streamSocket.Control.KeepAlive = true; if (Config.GetBoolean(Config.IgnoreSSL)) { streamSocket.Control.IgnorableServerCertificateErrors.Add(ChainValidationResult.Untrusted); streamSocket.Control.IgnorableServerCertificateErrors.Add(ChainValidationResult.Expired); } dataStreamLineReader = new SafeLineReader(); try { var protectionLevel = server.ssl ? SocketProtectionLevel.Tls12 : SocketProtectionLevel.PlainSocket; Debug.WriteLine("Attempting to connect..."); await streamSocket.ConnectAsync(new Windows.Networking.HostName(server.hostname), server.port.ToString(), protectionLevel); Debug.WriteLine("Connected!"); reader = new DataReader(streamSocket.InputStream); writer = new DataWriter(streamSocket.OutputStream); IsConnected = true; IsReconnecting = false; ConnectionHandler(); } catch (Exception e) { var autoReconnect = Config.GetBoolean(Config.AutoReconnect, true); var msg = autoReconnect ? "Attempting to reconnect..." : "Please try again later."; AddError("Error whilst connecting: " + e.Message + "\n" + msg); AddError(e.StackTrace); AddError("If this error keeps occuring, ensure your connection settings are correct."); DisconnectAsync(attemptReconnect: autoReconnect); Debug.WriteLine(e.Message); Debug.WriteLine(e.StackTrace); } }