/// <summary> /// Queues an event for sending over the Websocket /// </summary> /// <param name="message"></param> public virtual void Queue <TPayload>( GatewayEvent <TPayload> gatewayEvent, Newtonsoft.Json.JsonSerializerSettings settings = null ) { Socket.Send(gatewayEvent.Serialize(settings)); }
private void OnReady(GatewayEvent gatewayEvent) { var ready = gatewayEvent.GetData <Ready>(); lastReady = ready; FireEventOnDelegate(gatewayEvent, Ready); }
private async Task SendHeartbeatAsync() { var heartbeatEvent = new GatewayEvent { Operation = OperationCode.Heartbeat.ToInt(), Data = lastGatewayEvent?.SequenceNumber ?? 0 }; await _webMessageSocket.SendJsonObjectAsync(heartbeatEvent); }
private int GetEventId(GatewayEvent gatewayEvent) { int val = -1; if (gatewayEvent != null) { int.TryParse(gatewayEvent.Id, out val); } return(val); }
private async void IdentifySelfToGateway() { var identifyEvent = new GatewayEvent { Type = EventNames.IDENTIFY, Operation = OperationCode.Identify.ToInt(), Data = await GetIdentityAsync() }; await _webMessageSocket.SendJsonObjectAsync(identifyEvent); }
private void OnChannelDeleted(GatewayEvent gatewayEvent) { if (IsChannelAGuildChannel(gatewayEvent)) { FireEventOnDelegate(gatewayEvent, GuildChannelDeleted); } else { FireEventOnDelegate(gatewayEvent, DirectMessageChannelDeleted); } }
internal async Task GatewayEvents_InvalidSession(string rawJson, GatewayEvent <object> ev) { //"Clients are limited to 1 identify every 5 seconds; if they exceed this limit, the gateway will respond with an Opcode 9 Invalid Session." //"It's also possible that your client cannot reconnect in time to resume, in which case the client will receive a Opcode 9 Invalid Session // and is expected to wait a random amount of time—between 1 and 5 seconds—then send a fresh Opcode 2 Identify" //Wait 5 seconds before re-connecting await Task.Delay(5000); //Invalidate session then reidentify _session = null; Configuration.LastSession = null; Configuration.LastSequence = null; Identify(); }
private static GatewayEvent CreateGatewayEvent(GatewayEvent connectionEvent) { if (connectionEvent != null) { GatewayEvent gatewayEvent = new GatewayEvent(); gatewayEvent.Data = connectionEvent.Data; gatewayEvent.Id = connectionEvent.Id; gatewayEvent.Message = connectionEvent.Message; gatewayEvent.Timestamp = connectionEvent.Timestamp; return(gatewayEvent); } else { return(null); } }
private Task SendResumeAsync() { var Content = new ResumePayload() { SessionId = this._sessionId, Token = this.Token }; var pldata = new GatewayEvent() { Code = OPCode.Resume, EventPayload = Content }; var payload = JsonConvert.SerializeObject(Content); WebSocketClient.Send(payload); return(Task.CompletedTask); }
private Task SendIdentifyAsync() { var Content = new IdentifyPayload() { Token = $"{this.TokenType} {this.Token}", Properties = new Properties(), Compress = false, LargeThreashold = this.LargeThreashold, Shard = new[] { 0, 1 } }; var pldata = new GatewayEvent() { Code = OPCode.Identify, EventPayload = Content }; var payload = JsonConvert.SerializeObject(pldata); WebSocketClient.Send(payload); return(Task.CompletedTask); }
private void FireEventOnDelegate <TEventData>(GatewayEvent gatewayEvent, EventHandler <GatewayEventArgs <TEventData> > eventHandler) { var eventArgs = new GatewayEventArgs <TEventData>(gatewayEvent.GetData <TEventData>()); eventHandler?.Invoke(this, eventArgs); }
private void OnGuildDeleted(GatewayEvent gatewayEvent) { FireEventOnDelegate(gatewayEvent, GuildDeleted); }
private bool IsChannelAGuildChannel(GatewayEvent gatewayEvent) { var dataAsJObject = gatewayEvent.Data as JObject; return(dataAsJObject["guild_id"] != null); }
private void OnChannelUpdated(GatewayEvent gatewayEvent) { FireEventOnDelegate(gatewayEvent, GuildChannelUpdated); }
private void OnMessageDeleted(GatewayEvent gatewayEvent) { FireEventOnDelegate(gatewayEvent, MessageDeleted); }
private void OnResumeReceived(GatewayEvent gatewayEvent) { FireEventOnDelegate(gatewayEvent, Resumed); }
private void OnHelloReceived(GatewayEvent gatewayEvent) { IdentifySelfToGateway(); BeginHeartbeatAsync(gatewayEvent.GetData <Hello>().HeartbeatInterval); }
/// <inheritdoc /> /// <summary> /// Creates a new DispatchEventArgs instance /// </summary> /// <param name="shardId">Shard where the Dispatch occured.</param> /// <param name="data">Data of the Dispatch.</param> /// <param name="event">The Event of this Dispatch.</param> public DispatchEventArgs(int shardId, object data, GatewayEvent @event) { ShardId = shardId; Data = data; Event = @event; }