private void Connection_OnApplicationDidLaunch(object sender, streamdeck_client_csharp.StreamDeckEventReceivedEventArgs <streamdeck_client_csharp.Events.ApplicationDidLaunchEvent> e) { OnApplicationDidLaunch?.Invoke(this, new SDEventReceivedEventArgs <ApplicationDidLaunch>(new ApplicationDidLaunch(new Payloads.ApplicationPayload(e.Event.Payload.Application)))); }
private async Task <WebSocketCloseStatus> ReceiveAsync() { byte[] buffer = new byte[BufferSize]; ArraySegment <byte> arrayBuffer = new ArraySegment <byte>(buffer); StringBuilder textBuffer = new StringBuilder(BufferSize); try { while (!m_CancelSource.IsCancellationRequested && m_WebSocket != null) { WebSocketReceiveResult result = await m_WebSocket.ReceiveAsync(arrayBuffer, m_CancelSource.Token); if (result != null) { if (result.MessageType == WebSocketMessageType.Close || (result.CloseStatus != null && result.CloseStatus.HasValue && result.CloseStatus.Value != WebSocketCloseStatus.Empty)) { return(result.CloseStatus.GetValueOrDefault()); } else if (result.MessageType == WebSocketMessageType.Text) { textBuffer.Append(Encoding.UTF8.GetString(buffer, 0, result.Count)); if (result.EndOfMessage) { BaseEvent evt = BaseEvent.Parse(textBuffer.ToString()); if (evt != null) { switch (evt.Event) { case EventTypes.KeyDown: OnKeyDown?.Invoke(this, new StreamDeckEventReceivedEventArgs <KeyDownEvent>(evt as KeyDownEvent)); break; case EventTypes.KeyUp: OnKeyUp?.Invoke(this, new StreamDeckEventReceivedEventArgs <KeyUpEvent>(evt as KeyUpEvent)); break; case EventTypes.WillAppear: OnWillAppear?.Invoke(this, new StreamDeckEventReceivedEventArgs <WillAppearEvent>(evt as WillAppearEvent)); break; case EventTypes.WillDisappear: OnWillDisappear?.Invoke(this, new StreamDeckEventReceivedEventArgs <WillDisappearEvent>(evt as WillDisappearEvent)); break; case EventTypes.TitleParametersDidChange: OnTitleParametersDidChange?.Invoke(this, new StreamDeckEventReceivedEventArgs <TitleParametersDidChangeEvent>(evt as TitleParametersDidChangeEvent)); break; case EventTypes.DeviceDidConnect: OnDeviceDidConnect?.Invoke(this, new StreamDeckEventReceivedEventArgs <DeviceDidConnectEvent>(evt as DeviceDidConnectEvent)); break; case EventTypes.DeviceDidDisconnect: OnDeviceDidDisconnect?.Invoke(this, new StreamDeckEventReceivedEventArgs <DeviceDidDisconnectEvent>(evt as DeviceDidDisconnectEvent)); break; case EventTypes.ApplicationDidLaunch: OnApplicationDidLaunch?.Invoke(this, new StreamDeckEventReceivedEventArgs <ApplicationDidLaunchEvent>(evt as ApplicationDidLaunchEvent)); break; case EventTypes.ApplicationDidTerminate: OnApplicationDidTerminate?.Invoke(this, new StreamDeckEventReceivedEventArgs <ApplicationDidTerminateEvent>(evt as ApplicationDidTerminateEvent)); break; case EventTypes.SendToPlugin: OnSendToPlugin?.Invoke(this, new StreamDeckEventReceivedEventArgs <SendToPluginEvent>(evt as SendToPluginEvent)); break; case EventTypes.DidReceiveSettings: OnDidReceiveSettings?.Invoke(this, new StreamDeckEventReceivedEventArgs <DidReceiveSettingsEvent>(evt as DidReceiveSettingsEvent)); break; case EventTypes.DidReceiveGlobalSettings: OnDidReceiveGlobalSettings?.Invoke(this, new StreamDeckEventReceivedEventArgs <DidReceiveGlobalSettingsEvent>(evt as DidReceiveGlobalSettingsEvent)); break; case EventTypes.PropertyInspectorDidAppear: OnPropertyInspectorDidAppear?.Invoke(this, new StreamDeckEventReceivedEventArgs <PropertyInspectorDidAppearEvent>(evt as PropertyInspectorDidAppearEvent)); break; case EventTypes.PropertyInspectorDidDisappear: OnPropertyInspectorDidDisappear?.Invoke(this, new StreamDeckEventReceivedEventArgs <PropertyInspectorDidDisappearEvent>(evt as PropertyInspectorDidDisappearEvent)); break; } } else { // Consider logging or throwing an error here } textBuffer.Clear(); } } } } } catch { } return(WebSocketCloseStatus.NormalClosure); }