1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-27 12:26:31 +01:00

mobile broadcaster service

This commit is contained in:
Kyle Spearrin 2019-04-18 12:53:05 -04:00
parent 1dd5f9fc27
commit da73a2f5d2
2 changed files with 40 additions and 0 deletions

View 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);
}
}
}

View 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);
}
}