public override Task Close() { CancelPreviousLogin(); Rooms.Clear(); LogRooms.Clear(); _xmppConnection.OnRosterItem -= OnClientRosterItem; _xmppConnection.OnLogin -= OnLogin; _xmppConnection.OnError -= OnError; _xmppConnection.OnMessage -= OnMessage; _xmppConnection.Close(); _xmppConnection = null; return(Task.FromResult(1)); }
private async Task ConnectSocket() { for (var i = 0; i < 10 && _socket == null; i++) { var start = _api.RtmStart(); if (!start.Ok) { Logger.WarnFormat("Unable to start connection with Slack Adapter ({0}). Retrying", start.Error); await Task.Delay(TimeSpan.FromSeconds(1)); continue; } // URL only valid for 30sec _socket = new WebSocket(start.Url); _botUserId = start.Self.Id; _users = start.Users.ToList(); _rooms = start.Channels.ToList(); _ims = start.Ims.ToList(); Rooms.Clear(); Rooms.AddAll(start.Channels.Select(c => c.Name)); LogRooms.Clear(); LogRooms.AddAll(Rooms.Intersect(_logRooms, StringComparer.InvariantCultureIgnoreCase)); } if (_socket == null) { Logger.Error("Unable to create socket for Slack Adapter"); return; } _socket.Closed += SocketOnClose; _socket.Error += SocketOnError; _socket.MessageReceived += SocketOnMessage; _socket.Open(); Logger.Info("Slack socket connected"); }