I am in the progress of migrating (upgrading to be precise) from Azure Mobile Services to Azure Mobile Apps. My azure backend (.net) used to offer hybrid chat implementation in both SignalR and notification hubs.
The following snippet is working in Azure Mobile Services environment
[HubName("chatHub")]
public class ChatHub : Hub
{
public ApiServices Services { get; set; }
public IServiceTokenHandler handler { get; set; }
protected async Task NotifyParticipants(IPushMessage message, String tag)
{
await Services.Push.SendAsync(message, tag);
}
}
but since ApiServices is no longer available in Azure Mobile Apps environment, how should I refactor the implementation ?
I am using the following snippet in my API controllers that send notifications but I can't use the same in chatHub above because I'm not able to get HttpConfiguration needed to retrieve my notification hub settings.
[MobileAppController]
public class SomeController : ApiController
{
protected NotificationHubClient hubClient { get; set; }
protected override void Initialize(HttpControllerContext controllerContext)
{
base.Initialize(controllerContext);
// Get the settings for the server project.
HttpConfiguration config = this.Configuration;
MobileAppSettingsDictionary settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings();
// Get the Notification Hubs credentials for the Mobile App.
string notificationHubName = settings.NotificationHubName;
string notificationHubConnection = settings.Connections[MobileAppSettingsKeys.NotificationHubConnectionString].ConnectionString;
// Create a new Notification Hub client.
hubClient = NotificationHubClient.CreateClientFromConnectionString(notificationHubConnection, notificationHubName);
}
protected async Task NotifyParticipants(IPushMessage message, String tag)
{
await hubClient.SendGcmNativeNotificationAsync(message.ToString(), tag);
}
}