mirror of
https://github.com/bitwarden/mobile
synced 2025-12-16 08:13:20 +00:00
mobile broadcaster service
This commit is contained in:
29
src/App/Services/MobileBroadcasterService.cs
Normal file
29
src/App/Services/MobileBroadcasterService.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
using Bit.Core.Abstractions;
|
||||||
|
using System;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
|
namespace Bit.App.Services
|
||||||
|
{
|
||||||
|
public class MobileBroadcasterService : IBroadcasterService
|
||||||
|
{
|
||||||
|
public void Send<T>(T message, string id = null)
|
||||||
|
{
|
||||||
|
if(string.IsNullOrWhiteSpace(id))
|
||||||
|
{
|
||||||
|
throw new NotSupportedException("Cannot send a message to all subscribers.");
|
||||||
|
}
|
||||||
|
MessagingCenter.Send(Application.Current, id, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Subscribe<T>(string id, Action<T> messageCallback)
|
||||||
|
{
|
||||||
|
MessagingCenter.Subscribe<Application, T>(Application.Current, id,
|
||||||
|
(sender, message) => messageCallback(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Unsubscribe(string id)
|
||||||
|
{
|
||||||
|
MessagingCenter.Unsubscribe<Application, object>(Application.Current, id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
src/Core/Abstractions/IBroadcasterService.cs
Normal file
11
src/Core/Abstractions/IBroadcasterService.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Bit.Core.Abstractions
|
||||||
|
{
|
||||||
|
public interface IBroadcasterService
|
||||||
|
{
|
||||||
|
void Send<T>(T message, string id = null);
|
||||||
|
void Subscribe<T>(string id, Action<T> messageCallback);
|
||||||
|
void Unsubscribe(string id);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user