├── .gitignore ├── Program.cs ├── Properties └── launchSettings.json ├── README.md ├── Startup.cs ├── appsettings.Development.json ├── hubs └── SignalRtc.cs ├── models └── UserInfo.cs └── signalRtc.csproj /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.*~ 3 | project.lock.json 4 | .DS_Store 5 | *.pyc 6 | nupkg/ 7 | 8 | # Visual Studio Code 9 | .vscode 10 | 11 | # Rider 12 | .idea 13 | 14 | # User-specific files 15 | *.suo 16 | *.user 17 | *.userosscache 18 | *.sln.docstates 19 | 20 | # Build results 21 | [Dd]ebug/ 22 | [Dd]ebugPublic/ 23 | [Rr]elease/ 24 | [Rr]eleases/ 25 | x64/ 26 | x86/ 27 | build/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Oo]ut/ 32 | msbuild.log 33 | msbuild.err 34 | msbuild.wrn 35 | ./obj 36 | appsettings.json 37 | localhost.pfx 38 | obj/Debug/netcoreapp2.2/basic-todo.csproj.CoreCompileInputs.cache 39 | obj/Debug/netcoreapp2.2/basic-todo.csprojAssemblyReference.cache 40 | -------------------------------------------------------------------------------- /Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace signalRtc 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateWebHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IWebHostBuilder CreateWebHostBuilder(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:2511", 7 | "sslPort": 44327 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "signalRtc": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SignalRtc 2 | 3 | This project is the backend part of the Angular and webRTC tutorial [LINK](https://dev.to/sebalr/video-call-with-webrtc-angular-and-asp-net-core-39hg) 4 | 5 | ## Frontend 6 | 7 | This is the Angular fronted [LINK](https://github.com/sebalr/signalrtc-frontend) 8 | -------------------------------------------------------------------------------- /Startup.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Builder; 2 | using Microsoft.AspNetCore.Hosting; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.Extensions.DependencyInjection; 5 | using Microsoft.Extensions.Hosting; 6 | using signalRtc.hubs; 7 | 8 | namespace signalRtc 9 | { 10 | public class Startup 11 | { 12 | // This method gets called by the runtime. Use this method to add services to the container. 13 | // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 14 | public void ConfigureServices(IServiceCollection services) 15 | { 16 | services.AddCors(options => 17 | { 18 | options.AddPolicy(MyAllowSpecificOrigins, 19 | builder => builder.WithOrigins("http://localhost:4200", "https://localhost:4200") 20 | .AllowAnyMethod() 21 | .AllowAnyHeader() 22 | .AllowCredentials()); 23 | }); 24 | 25 | services.AddSignalR(); 26 | } 27 | 28 | readonly string MyAllowSpecificOrigins = "AllowOrigins"; 29 | 30 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 31 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 32 | { 33 | if (env.IsDevelopment()) 34 | { 35 | app.UseDeveloperExceptionPage(); 36 | } 37 | 38 | app.UseRouting(); 39 | app.UseCors(MyAllowSpecificOrigins); 40 | app.UseEndpoints(endpoints => 41 | { 42 | endpoints.MapHub("/signalrtc"); 43 | }); 44 | 45 | app.Run(async(context) => 46 | { 47 | await context.Response.WriteAsync("Hello World!"); 48 | }); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | }, 9 | "Kestrel": { 10 | "Certificates": { 11 | "Default": { 12 | "Path": "localhost.pfx", 13 | "Password": "ff2019" 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /hubs/SignalRtc.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json; 2 | using System.Threading.Tasks; 3 | using Microsoft.AspNetCore.SignalR; 4 | using signalRtc.models; 5 | 6 | namespace signalRtc.hubs 7 | { 8 | public class SignalRtcHub : Hub 9 | { 10 | 11 | public async Task NewUser(string username) 12 | { 13 | var userInfo = new UserInfo() { userName = username, connectionId = Context.ConnectionId }; 14 | await Clients.Others.SendAsync("NewUserArrived", JsonSerializer.Serialize(userInfo)); 15 | } 16 | 17 | public async Task HelloUser(string userName, string user) 18 | { 19 | var userInfo = new UserInfo() { userName = userName, connectionId = Context.ConnectionId }; 20 | await Clients.Client(user).SendAsync("UserSaidHello", JsonSerializer.Serialize(userInfo)); 21 | } 22 | 23 | public async Task SendSignal(string signal, string user) 24 | { 25 | await Clients.Client(user).SendAsync("SendSignal", Context.ConnectionId, signal); 26 | } 27 | 28 | public override async Task OnDisconnectedAsync(System.Exception exception) 29 | { 30 | await Clients.All.SendAsync("UserDisconnect", Context.ConnectionId); 31 | await base.OnDisconnectedAsync(exception); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /models/UserInfo.cs: -------------------------------------------------------------------------------- 1 | namespace signalRtc.models 2 | { 3 | public class UserInfo 4 | { 5 | public string userName { get; set; } 6 | public string connectionId { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /signalRtc.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netcoreapp3.1 4 | SignalRtc 5 | Exe 6 | 7 | 8 | 9 | 10 | 11 | 12 | --------------------------------------------------------------------------------