public async Task ReceiveAsync(int bufferSize = 1024 * 4) { OnConnect?.Invoke(this, ws.State == WebSocketState.Open); try { while (true) { var buffer = new byte[bufferSize]; var result = await ws.ReceiveAsync(new ArraySegment <byte>(buffer), CancellationToken.None); if (result.MessageType == WebSocketMessageType.Close || !result.CloseStatus.HasValue) { break; } OnMessageReceive?.Invoke(this, new Message { Client = this, MessageType = result.MessageType, Data = buffer }); } } catch { } Close(); }
public void MessageReceiveHandler(MessageModel model) { OnMessageReceive?.Invoke(model); switch (model.MessageType) { case MessageType.CreatePlayList: break; case MessageType.UploadPlayList: break; case MessageType.UploadFile: break; case MessageType.PlayRandomVideo: break; case MessageType.Query: break; case MessageType.MiddlewareCommand: break; case MessageType.ServerList: var d = model.Data as ServerListModel; Servers = d.ClientIPs; break; default: break; } }
public async Task ReceiveAsync(int bufferSize = 1024 * 4) { OnConnect?.Invoke(this, ws.State == WebSocketState.Open); var buffer = new byte[bufferSize]; try { while (true) { var array = new ArraySegment <byte>(buffer); var result = await ws.ReceiveAsync(array, CancellationToken.None); // FIXME result.CloseStatus or !result.CloseStatus // if (result.MessageType == WebSocketMessageType.Close || !result.CloseStatus.HasValue) if (result.MessageType == WebSocketMessageType.Close || result.CloseStatus.HasValue) { break; } var data = array.Slice(0, result.Count).ToArray(); OnMessageReceive?.Invoke(this, new Message { Client = this, MessageType = result.MessageType, Data = data }); } } catch (Exception e) { Console.WriteLine(e); } Close(); }
public override async Task StartAsync() { Connection = await Client.Connect(_key); Connection.OnMessageReceived += async message => { await OnMessageReceive.Invoke(new SlackMessageObject(message)); }; await base.StartAsync(); }
public DiscordBotClient(DiscordProviderConfigurations config) { client.MessageReceived += async(msg) => { await OnMessageReceive.Invoke(new DiscordMessageObject(msg)); }; client.MessageUpdated += async(msgCached, newMsg, channel) => { await OnMessageEdit.Invoke(new DiscordMessageObject(newMsg), new DiscordChannelObject(channel)); }; }
public DiscordBotProvider(DiscordProviderConfigurations config) { this.config = config; client = new DiscordShardedClient( new DiscordSocketConfig { TotalShards = config.ShardCount }); client.MessageReceived += async message => { await OnMessageReceive.Invoke(new DiscordMessageObject(message)); }; }
public void AddProvider(IBotProvider provider) { provider.OnMessageReceive += async(m) => { await OnMessageReceive.Invoke(m); }; provider.OnMessageEdit += async(m) => { await OnMessageEdit.Invoke(m); }; provider.OnMessageDelete += async(m) => { await OnMessageDelete.Invoke(m); }; providers.Add(provider); }
protected void OnMessageReceiveEvent(string message) { OnMessageReceive?.Invoke(this, new MessageEventArgs(message)); }
public static void MessageReceived(IMessage message) => OnMessageReceive?.Invoke(message);
public void Message(string message) { Messages.Add(message); OnMessageReceive.Invoke(); }
/*================================*\ |* Protected Member Functions *| \*================================*/ /*===============*\ |* Overrides *| \*===============*/ protected override void ReceiveMessage(RosPose2D message) { CustomRosConverter.Pose2DToPose2D(pose2D, message); OnMessageReceive.Invoke(); }
private void Process_ErrorDataReceived(object sender, DataReceivedEventArgs e) { errorMessage.Add(e.Data); OnMessageReceive?.Invoke(e.Data); }
private void Process_OutputDataReceived(object sender, DataReceivedEventArgs e) { this.message.Add(e.Data); OnMessageReceive?.Invoke(e.Data); }
private static void MessageReceive(string name, string message) { OnMessageReceive?.Invoke(name, message); }
virtual protected void WshOnMessageReceive(object sender, Message message) { OnMessageReceive?.Invoke(this, message); }
internal static void MessageReceive(int id, IMessage message) => OnMessageReceive?.Invoke(message, id);