Files
notesnook-sync-server_custo…/Streetwriters.Common/Extensions/WampRealmExtensions.cs
2022-12-28 16:20:25 +05:00

23 lines
788 B
C#

using System;
using Microsoft.AspNetCore.Builder;
using Streetwriters.Common.Interfaces;
using WampSharp.AspNetCore.WebSockets.Server;
using WampSharp.Binding;
using WampSharp.V2;
using WampSharp.V2.Realm;
namespace Streetwriters.Common.Extensions
{
public static class WampRealmExtensions
{
public static IDisposable Subscribe<T>(this IWampHostedRealm realm, string topicName, Action<T> onNext)
{
return realm.Services.GetSubject<T>(topicName).Subscribe<T>(onNext);
}
public static IDisposable Subscribe<T>(this IWampHostedRealm realm, string topicName, IMessageHandler<T> handler)
{
return realm.Services.GetSubject<T>(topicName).Subscribe<T>(async (message) => await handler.Process(message));
}
}
}