public StreamDeckClient(IStreamDeckLogger logger, IStreamDeckEventHandlerFactory eventHandlerFactory, int port, string pluginUUID, string registerEvent, StreamDeckInfo info) { this.logger = logger; this.eventHandlerFactory = eventHandlerFactory; this.port = port; this.pluginUUID = pluginUUID; this.registerEvent = registerEvent; this.info = info; RegisterActionEvent <StreamDeckKeyDownEventMessage>(ESDSDKEventType.keyDown, (action, message) => action.KeyDown(message)); RegisterActionEvent <StreamDeckKeyUpEventMessage>(ESDSDKEventType.keyUp, (action, message) => action.KeyUp(message)); RegisterActionEvent <StreamDeckWillAppearEventEventMessage>(ESDSDKEventType.willAppear, (action, message) => action.WillAppear(message)); RegisterActionEvent <StreamDeckWillDisappearEventEventMessage>(ESDSDKEventType.willDisappear, async(action, message) => { await action.WillDisappear(message); RemoveActionInstance(message.Action, message.Context); }); RegisterActionEvent <StreamDeckTitleParametersDidChangeEventMessage>(ESDSDKEventType.titleParametersDidChange, (action, message) => action.TitleParametersDidChange(message)); RegisterActionEvent <StreamDeckDidReceiveSettingsEventMessage>(ESDSDKEventType.didReceiveSettings, (action, message) => action.DidReceiveSettings(message)); RegisterActionEvent <StreamDeckPropertyInspectorDidAppearEventMessage>(ESDSDKEventType.propertyInspectorDidAppear, (action, message) => action.PropertyInspectorDidAppear(message)); RegisterActionEvent <StreamDeckPropertyInspectorDidDisappearEventMessage>(ESDSDKEventType.propertyInspectorDidDisappear, (action, message) => action.PropertyInspectorDidDisappear(message)); RegisterActionEvent <StreamDeckSendToPluginEventMessage>(ESDSDKEventType.sendToPlugin, (action, message) => action.SendToPlugin(message)); RegisterGlobalEvent <StreamDeckDeviceDidConnectEventMessage>(ESDSDKEventType.deviceDidConnect, (globalEvent, message) => globalEvent.DeviceDidConnect(message)); RegisterGlobalEvent <StreamDeckDeviceDidDisconnectEventMessage>(ESDSDKEventType.deviceDidDisconnect, (globalEvent, message) => globalEvent.DeviceDidDisconnect(message)); RegisterGlobalEvent <StreamDeckApplicationDidLaunchEventMessage>(ESDSDKEventType.applicationDidLaunch, (globalEvent, message) => globalEvent.ApplicationDidLaunch(message)); RegisterGlobalEvent <StreamDeckApplicationDidTerminateEventMessage>(ESDSDKEventType.applicationDidTerminate, (globalEvent, message) => globalEvent.ApplicationDidTerminate(message)); RegisterGlobalEvent <StreamDeckSystemDidWakeUpEventMessage>(ESDSDKEventType.systemDidWakeUp, (globalEvent, message) => globalEvent.SystemDidWakeUp(message)); RegisterGlobalEvent <StreamDeckDidReceiveGlobalSettingsEventMessage>(ESDSDKEventType.didReceiveGlobalSettings, (globalEvent, message) => globalEvent.DidReceiveGlobalSettings(message)); }
/// <summary> /// Wrapper for the Stream Deck SDK. /// </summary> /// <param name="port">The port that should be used to create the WebSocket.</param> /// <param name="pluginUuid">The unique identifier string that should be used to register the plugin once the WebSocket is opened.</param> /// <param name="registerEvent">The event payload that should be used to register the plugin once the WebSocket is opened.</param> /// <param name="info">A stringified json containing the Stream Deck application information and devices information.</param> public StreamDeckClient(string port, string pluginUuid, string registerEvent, string info) { _serialiserSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; SocketHandler = new StreamDeckSocketHandler(new Uri($"ws://localhost:{port}"), registerEvent, pluginUuid); SocketHandler.EventOccurredAsync += InvokeSpecificEventHandlers; SocketHandler.EventOccurredAsync += InvokeGenericEventHandler; Info = JsonConvert.DeserializeObject <StreamDeckInfo>(info, _serialiserSettings); _cancellationTokenSource = new CancellationTokenSource(); _eventHandlers = BuildEventHandlerDictionary(); }