public Envelope(SenderFunction func, object args, Task taskObj) { EnvelopeGUID = Guid.NewGuid().ToString(); sendFunc = func; Contents = args; task = taskObj; }
public static SenderFunction <T> GetTyped <T>(this SenderFunction method) where T : MessageBase { return((T message) => { return method(message); }); }
private async Task HandleWebSocketContextAsync(WebSocket ws, HttpContext httpContext, IWebSocketHandler handler, CancellationToken cancellationToken) { CloseFunction closeFunction = () => ws.CloseAsync(WebSocketCloseStatus.NormalClosure, "Done", CancellationToken.None); SenderFunction sendFunction = (message) => WriteStringAsync(ws, messageWriter.GetString(message), cancellationToken); IMessageHandler messageHandler; try { messageHandler = handler.CreateHandler(httpContext, closeFunction, sendFunction); } catch (Exception e) { logger.Error(e, "Error occured while creating handlers for {0}", httpContext.Request.Path); httpContext.Response.StatusCode = 500; return; } while (ws.State == WebSocketState.Open && !cancellationToken.IsCancellationRequested) { string requestMessage = await webSocketHelper.ReadStringAsync(ws, Encoding.UTF8, cancellationToken); if (requestMessage == null) { continue; } ProcessMessage(requestMessage, messageHandler); } if (ws.State == WebSocketState.Open) { await closeFunction(); } messageHandler.Close(); }
public XboxInputRequestHandler(CloseFunction closeFunction, SenderFunction senderFunction, XboxDevice device, EmulatedControllersService emulatedControllersService, DeviceDisconnectedEventHandler disconnectedEventHandler) : base(closeFunction, senderFunction) { this.device = device; this.emulatedControllersService = emulatedControllersService; this.disconnectedEventHandler = disconnectedEventHandler; device.FeedbackEvent += FeedbackEvent; }
public InputValuesMessageHandler(IInputDevice device, SenderFunction <InputValuesMessage> senderFunction) { this.device = device; this.senderFunction = senderFunction; device.InputChanged += InputChanged; threadContext = ThreadCreator.CreateLoop($"Websocket input value writer {device.DisplayName}", ResponseLoop, 33).Start(); }
public PingMessageHandler(CloseFunction closeFunction, SenderFunction <PingMessage> senderFunction) { this.closeFunction = closeFunction; this.senderFunction = senderFunction; timer = new Timer(5000); timer.Elapsed += TimerElapsed; timer.Start(); }
public List <IMessageHandler> CreateHandlers(HttpListenerContext context, SenderFunction sendFunction) { string emulatorName = context.Request.Url.LocalPath.Replace($"/{DeviceType}/", ""); var emulator = emulatorService.FindEmulator <IXboxEmulator>(DeviceTypes.MicrosoftXbox360, emulatorName); var device = emulator.CreateDevice(); return(new List <IMessageHandler> { new DebugMessageHandler(), new XboxFeedbackMessageHandler(device, sendFunction.GetTyped <XboxFeedbackMessage>()), new XboxInputMessageHandler(device), }); }
public SourceValuesMessageHandler(InputDeviceHolder device, SenderFunction <InputValuesMessage> senderFunction) { this.device = device; this.senderFunction = senderFunction; var devices = device.GetInputDevices(); device.Connected += InputConnected; device.Disconnected += InputDisconnected; foreach (var inputDevice in devices) { inputDevice.InputChanged += InputChanged; } threadContext = ThreadCreator.CreateLoop($"Websocket input value writer {device.DisplayName}", ResponseLoop, 33).Start(); }
protected MessageHandler(CloseFunction closeFunction, SenderFunction senderFunction) { this.closeFunction = closeFunction; this.senderFunction = senderFunction; pingThreadContext = ThreadCreator.CreateLoop("Ping loop", () => { try { var r = new PingRequest { Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), }; senderFunction(new PingRequest { Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), }); } catch (Exception ex) { logger.Warn(ex, "Ping failed, closing connection"); closeFunction(); } }, 5000).Start(); }
public List <IMessageHandler> CreateHandlers(HttpContext context, CloseFunction closeFunction, SenderFunction sendFunction) { string emulatorName = context.Request.Path.Value.Replace($"/ws/{DeviceType}/", ""); var emulator = emulatorService.FindEmulator <IDs4Emulator>(XOutput.Emulation.DeviceTypes.SonyDualShock4, emulatorName); var device = emulator.CreateDs4Device(); DeviceDisconnectedEvent disconnectedEvent = (sender, args) => closeFunction(); device.Closed += disconnectedEvent; var ip = context.Request.HttpContext.Connection.RemoteIpAddress?.ToString(); deviceInfoService.Add(new NetworkDeviceInfo { Device = device, IPAddress = ip, DeviceType = XOutput.Emulation.DeviceTypes.SonyDualShock4, Emulator = emulator.Name, }); return(new List <IMessageHandler> { new DebugMessageHandler(), new Ds4FeedbackMessageHandler(device, sendFunction.GetTyped <Ds4FeedbackMessage>()), new Ds4InputMessageHandler(device, disconnectedEvent), }); }
public List <IMessageHandler> CreateHandlers(HttpContext context, CloseFunction closeFunction, SenderFunction sendFunction) { return(new List <IMessageHandler> { new DebugMessageHandler(), new MappableDeviceMessageHandler(mappableDevices, sendFunction.GetTyped <MappableDeviceFeedbackMessage>()), }); }
public InputDeviceMessageHandler(CloseFunction closeFunction, SenderFunction senderFunction, InputDevices inputDevices) : base(closeFunction, senderFunction) { this.inputDevices = inputDevices; }
public InputDeviceFeedbackHandler(CloseFunction closeFunction, SenderFunction senderFunction, InputDevice inputDevice) : base(closeFunction, senderFunction) { this.device = inputDevice; threadContext = ThreadCreator.CreateLoop($"{device.Id} input device report thread", SendFeedback, 20); threadContext.Start(); }
public XboxFeedbackMessageHandler(XboxDevice device, SenderFunction <XboxFeedbackMessage> senderFunction) { this.device = device; this.senderFunction = senderFunction; device.FeedbackEvent += FeedbackEvent; }
public EmulatedControllerFeedbackHandler(CloseFunction closeFunction, SenderFunction senderFunction, IMappedController emulatedController) : base(closeFunction, senderFunction) { this.emulatedController = emulatedController; threadContext = ThreadCreator.CreateLoop($"{emulatedController.Id} input device report thread", SendFeedback, 20); }
public Ds4FeedbackMessageHandler(Ds4Device device, SenderFunction <Ds4FeedbackMessage> senderFunction) { this.device = device; this.senderFunction = senderFunction; device.FeedbackEvent += FeedbackEvent; }
public IMessageHandler CreateHandler(HttpContext context, CloseFunction closeFunction, SenderFunction sendFunction) { string emulatorName = PathRegex.Match(context.Request.Path.Value).Groups[1].Value; Emulators emulatorType = Enum.Parse <Emulators>(emulatorName); var emulator = emulatorService.FindEmulator <IDs4Emulator>(DeviceTypes.SonyDualShock4, emulatorType); var device = emulator.CreateDs4Device(); DeviceDisconnectedEventHandler disconnectedEvent = (sender, args) => closeFunction(); device.Closed += disconnectedEvent; var ip = context.Request.HttpContext.Connection.RemoteIpAddress?.ToString(); emulatedControllersService.Add(new NetworkDeviceInfo { Device = device, IPAddress = ip, DeviceType = DeviceTypes.SonyDualShock4, Emulator = emulator.Emulator, }); return(new Ds4InputRequestHandler(closeFunction, sendFunction, device, emulatedControllersService, disconnectedEvent)); }
public MappableDeviceMessageHandler(MappableDevices mappableDevices, SenderFunction <MappableDeviceFeedbackMessage> senderFunction) { this.mappableDevices = mappableDevices; this.senderFunction = senderFunction; }
public IMessageHandler CreateHandler(HttpContext context, CloseFunction closeFunction, SenderFunction sendFunction) { return(new InputDeviceMessageHandler(closeFunction, sendFunction, inputDevices)); }
public IMessageHandler CreateHandler(HttpContext context, CloseFunction closeFunction, SenderFunction sendFunction) { string id = PathRegex.Match(context.Request.Path.Value).Groups[1].Value; var device = inputDevices.Find(id); return(new InputDeviceFeedbackHandler(closeFunction, sendFunction, device)); }
public List <IMessageHandler> CreateHandlers(HttpContext context, CloseFunction closeFunction, SenderFunction sendFunction) { string deviceId = context.Request.Path.Value.Replace($"/ws/input/", ""); var device = inputDeviceManager.FindInputDevice(deviceId); if (device == null) { throw new ArgumentException(); } return(new List <IMessageHandler> { new DebugMessageHandler(), new SourceValuesMessageHandler(device, sendFunction.GetTyped <InputValuesMessage>()), }); }
public IMessageHandler CreateHandler(HttpContext context, CloseFunction closeFunction, SenderFunction sendFunction) { string id = PathRegex.Match(context.Request.Path.Value).Groups[1].Value; var emulatedController = emulatedControllers.Find(id); return(new EmulatedControllerFeedbackHandler(closeFunction, sendFunction, emulatedController)); }