jamiewest / signalr_core

ASP.NET Core SignalR Dart Client
https://pub.dev/packages/signalr_core
MIT License
90 stars 62 forks source link

Azure Signalr #24

Closed JohnnyOpcode closed 4 years ago

JohnnyOpcode commented 4 years ago

I'm a bit (pun) unclear of the URL form when making a Flutter Client connection to an Azure Signalr Hub.

Examples are far and few to come by on the internet and everything I try returns a 404 or 400 error.

Has this been tested with Azure?

Johnny

laimonas commented 4 years ago

I can confirm that it is working. I have my test project. Some code samples.

final connection = HubConnectionBuilder()
      .withUrl(
      // web
          'http://localhost:5000/scrum-poker',
      // Android emulator
           'https://10.0.2.2:5000/scrum-poker',
      // Azure
          'https://xxxxx.azurewebsites.net/scrum-poker',
          HttpConnectionOptions(
            client: IOClient(HttpClient()..badCertificateCallback = (x, y, z) => true),
            transport: HttpTransportType.webSockets,
            logging: (level, message) => print(message),
          ))
      .withAutomaticReconnect()
      .build();

// NET.Core
public void ConfigureServices(IServiceCollection services)
        {
            services.AddSignalR(o => o.EnableDetailedErrors = true);
            services.AddCors(options => options.AddPolicy("AllowAll", builder =>
            {
                builder
                    .AllowAnyMethod()
                    .AllowAnyHeader()
                    .AllowAnyOrigin();
            }));
        }

Also don't forget to enable websockets in Azure.

JohnnyOpcode commented 4 years ago

Excellent. That filled in the missing bits (pun again).

Thank-you