/// <inheritdoc /> /// <summary> /// Routes the specified signal from an extension to another extension. /// </summary> /// <param name="signal">The signal.</param> /// <returns></returns> /// <exception cref="T:Loki.SignalServer.Interfaces.Exceptions.DependencyNotInitException">SignalRouter</exception> public ISignal RouteExtension(ISignal signal) { if (!_isInitialized) { throw new DependencyNotInitException(nameof(SignalRouter)); } IExtension extension = GetExtension(signal); if (extension == null) { throw new InvalidExtensionException($"Attempted to route an to an invalid extension. Route: {signal.Route}"); } _logger.Debug(signal.Format("Cross Request")); ISignal response = extension.ExecuteCrossExtensionAction(signal.Action, signal); if (response == null) { return(null); } _logger.Debug(signal.Format("Cross Response")); return(response); }
/// <summary> /// Handles the request. /// </summary> /// <param name="sender">The sender.</param> /// <param name="signal">The signal.</param> /// <exception cref="InvalidExtensionException"></exception> private void HandleDequeuedRequest(object sender, ISignal signal) { IWebSocketConnection[] connections = _connectionManager.GetConnectionsByClientIdentifier(signal.Sender); if (!connections.Any()) { return; } IExtension extension = GetExtension(signal); if (extension == null) { throw new InvalidExtensionException($"Attempted to route an to an invalid extension. Route: {signal.Route}"); } _logger.Debug(signal.Format("Request")); ISignal response = extension.ExecuteAction(signal.Action, signal); if (response == null) { return; } _routerExchangeGenerator.Publish(_responseExchangeId, response); }
/// <inheritdoc /> /// <summary> /// Broadcasts the signal. /// </summary> /// <param name="entityId">The entity identifier.</param> /// <param name="signal">The signal.</param> /// <exception cref="T:Loki.SignalServer.Interfaces.Exceptions.DependencyNotInitException">SignalRouter</exception> public void BroadcastSignal(string entityId, ISignal signal) { if (!_isInitialized) { throw new DependencyNotInitException(nameof(SignalRouter)); } _logger.Debug(signal.Format("Direct Response")); signal.Sender = "server"; //If on server, send signal IWebSocketConnection[] connections = _connectionManager.GetConnectionsByClientIdentifier(entityId); if (connections == null || connections.Length == 0) { return; } signal.Recipient = connections[0].ClientIdentifier; foreach (IWebSocketConnection connection in connections) { connection?.SendText(signal); } }
/// <summary> /// Handles the response. /// </summary> /// <param name="sender">The sender.</param> /// <param name="signal">The signal.</param> private void HandleDequeuedResponse(object sender, ISignal signal) { IWebSocketConnection[] connections = _connectionManager.GetConnectionsByClientIdentifier(signal.Recipient); if (!connections.Any()) { return; } _logger.Debug(signal.Format("Response")); foreach (IWebSocketConnection connection in connections) { connection.SendText(signal); } }