/// <summary> /// Starts the web server with the provided arguments, IP and port /// </summary> /// <param name="args">The arguments to pass to the builder</param> /// <returns>A Task that ends when the web server stops</returns> public static async Task <Task> StartWebInterface(string[] args) { ConLog.Log("WebMedia Link", "Starting web interface", LogType.Info); Task webTask = Task.Run(async() => await Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup <Startup>(); webBuilder.UseUrls("http://" + WebServerIp + ":" + WebServerPort + "/"); }).Build().RunAsync()); ConLog.Log("WebMedia Link", "Starting SignalR", LogType.Info); //Start SignalR SignalRConnection = new HubConnectionBuilder() .WithAutomaticReconnect() .WithUrl("http://" + WebServerIp + ":" + WebServerPort + "/serverlistHub") .Build(); //Create event handlers HubConnectionExtensions.On <string>(SignalRConnection, "ClientConnected", SignalRClientConnected); await SignalRConnection.StartAsync(); ConLog.Log("WebMedia Link", "Web interface started", LogType.Ok); return(webTask); }
public IObservable <PeerStatus> AwakeAsObservable() { m_HubConnection = new HubConnectionBuilder() .WithUrl(m_Url + HubConnectionExtensions.Path()) .Build(); m_HubConnection.On(nameof(ReceiveReplicationOp), new Action <string, KSEQOperation <Record> >(ReceiveReplicationOp)); m_HubConnection.On(nameof(ReceiveReplica), new Action <string, List <Atom <Record> > >(ReceiveReplica)); return(m_HubConnection .StartAsync() .ToObservable() .Take(1) .Do(ignored => { peerId = m_HubConnection.GetConnectionId(); }) .Select(ignored => new PeerStatus() { isConnected = m_HubConnection.State == HubConnectionState.Connected })); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseSignalR(routes => { routes.MapHub <THub>(HubConnectionExtensions.Path()); }); }
/// <summary> /// Updates all SignalR clients with new information /// </summary> /// <returns>A Task representing the operation</returns> private static async Task UpdateAllSignalRClients() { string responseContent = GetServerlistJson(); await HubConnectionExtensions.InvokeAsync(SignalRConnection, "SendUpdateAll", responseContent); }
/// <summary> /// Sends a specific SignalR client updated information /// </summary> /// <param name="clientId">The client that connected</param> /// <returns>A Task representing the operation</returns> private static async Task SignalRClientConnected(string clientId) { string responseContent = GetServerlistJson(); await HubConnectionExtensions.InvokeAsync(SignalRConnection, "SendUpdateSpecific", responseContent, clientId); }