/// <summary> /// Initializes a new instance of the <see cref="App"/> class. /// </summary> /// <param name="realtimeClient">Ably client.</param> /// <param name="loggerSink">Instance of the AppLoggerSink so we can display and analyze logs inside the app.</param> /// <param name="receiver">Receives push notifications from Android or iOS.</param> public App(IRealtimeClient realtimeClient, AppLoggerSink loggerSink, PushNotificationReceiver receiver) { InitializeComponent(); DependencyService.RegisterSingleton(realtimeClient); DependencyService.RegisterSingleton(loggerSink); DependencyService.RegisterSingleton(receiver); MainPage = new AppShell(); }
internal static Task WaitForState(this IRealtimeClient realtime, ConnectionState awaitedState = ConnectionState.Connected, TimeSpan?waitSpan = null) { var connectionAwaiter = new ConnectionAwaiter(realtime.Connection, awaitedState); if (waitSpan.HasValue) { return(connectionAwaiter.Wait(waitSpan.Value)); } return(connectionAwaiter.Wait()); }
internal static void BlockActionFromReceiving(this IRealtimeClient client, ProtocolMessage.MessageAction action) { var transport = (TestTransportWrapper)((AblyRealtime)client).ConnectionManager.Transport; if (transport is null) { throw new Exception("Client is not using test transport so you can't add BlockedActions"); } transport.BlockReceiveActions.Add(action); }
private void InitialiseAbly() { _loggerSink = new AppLoggerSink(); var savedClientId = Preferences.Get("ABLY_CLIENT_ID", string.Empty); var callbacks = new PushCallbacks { ActivatedCallback = error => LogCallback("Activated", error), DeactivatedCallback = error => LogCallback("Deactivated", error), SyncRegistrationFailedCallback = error => LogCallback("SyncRegistrationFailed", error), }; _realtime = AppleMobileDevice.Initialise(GetAblyOptions(savedClientId), callbacks); _realtime.Connect(); }
private ClientOptions GetAblyOptions(string savedClientId) { var options = new ClientOptions { // https://ably.com/docs/best-practice-guide#auth // recommended for security reasons. Please, review Ably's best practice guide on Authentication // Please provide a way for AblyRealtime to connect to the services. Having API keys on mobile devices is not recommended. Key = "<key>", LogHandler = (ILoggerSink)_loggerSink, LogLevel = LogLevel.Debug, ClientId = string.IsNullOrWhiteSpace(savedClientId) ? Guid.NewGuid().ToString("D") : savedClientId, }; _realtime = new AblyRealtime(options); _realtime.Connect(); return options; }
/// <summary> /// This method yields the current thread and waits until the whole command queue is processed. /// </summary> /// <returns></returns> public static async Task ProcessCommands(this IRealtimeClient client) { var realtime = (AblyRealtime)client; var taskAwaiter = new TaskCompletionAwaiter(); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed _ = Task.Run(async() => { while (true) { await Task.Delay(50); if (realtime.Workflow.IsProcessingCommands() == false) { taskAwaiter.SetCompleted(); } } }); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed await taskAwaiter.Task; }
internal static async Task ProcessMessage(this IRealtimeClient client, ProtocolMessage message) { ((AblyRealtime)client).Workflow.QueueCommand(ProcessMessageCommand.Create(message)); await client.ProcessCommands(); }
internal static void ExecuteCommand(this IRealtimeClient client, RealtimeCommand command) { ((AblyRealtime)client).Workflow.QueueCommand(command); }
internal static TestTransportWrapper GetTestTransport(this IRealtimeClient client) { return(((AblyRealtime)client).ConnectionManager.Transport as TestTransportWrapper); }
internal static void SetOnTransportCreated(this IRealtimeClient client, Action <TestTransportWrapper> onCreated) { var factory = ((AblyRealtime)client).Options.TransportFactory as TestTransportFactory; factory.OnTransportCreated = onCreated; }
public static Task WaitForState(this IRealtimeClient realtime, ConnectionState awaitedState = ConnectionState.Connected) { var connectionAwaiter = new ConnectionAwaiter(realtime.Connection, awaitedState); return(connectionAwaiter.Wait()); }