public void Initialize(BackgroundTaskDeferral deferral) { if (_connection == null & _protoService == null) { VoIPCallTask.Log("Mediator initialized", "Creating proto service"); var protoService = new MTProtoService(0); //protoService.Initialized += (s, args) => //{ // VoIPCallTask.Log("ProtoService initialized", "waiting for updates"); //}; //protoService.Initialize(); //_protoService = protoService; //_transportService = transportService; } else { VoIPCallTask.Log("Mediator initialized", "_connection is null: " + (_connection == null)); } _deferral = deferral; _initialized = true; ProcessUpdates(); }
public async void Initialize(AppServiceConnection connection) { if (connection != null) { VoIPCallTask.Log("Mediator initialized", "Connecting app service"); _connection = connection; _connection.RequestReceived -= OnRequestReceived; _connection.RequestReceived += OnRequestReceived; } else { VoIPCallTask.Log("Mediator initialized", "Disconnetting app service"); if (_connection != null) { _connection.RequestReceived -= OnRequestReceived; _connection = null; } } if (_protoService != null && _connection != null) { VoIPCallTask.Log("Mediator initialized", "Disposing proto service"); _protoService.Dispose(); _transportService.Close(); } if (_phoneCall != null && _connection != null) { await UpdateCallAsync(); } }
//public void Handle(TLUpdatePhoneCall update) //{ // Debug.WriteLine("[{0:HH:mm:ss.fff}] Processing VoIP update: " + update.PhoneCall, DateTime.Now); // _queue.Enqueue(update); // if (_initialized) // { // ProcessUpdates(); // //await UpdateCallAsync(string.Empty); // } //} public void Dispose() { VoIPCallTask.Log("Releasing background task", "Disposing mediator"); if (_protoService != null) { //_transportService.Close(); } }
public void Run(IBackgroundTaskInstance taskInstance) { _deferral = taskInstance.GetDeferral(); _current = this; VoIPCallTask.Log("VoIPCallTask started", "VoIPCallTask started"); Mediator.Initialize(_deferral); taskInstance.Canceled += OnCanceled; }
private async Task UpdateCallAsync() { if (_connection != null) { VoIPCallTask.Log("Mediator initialized", "Informing foreground about current call"); var data = TLTuple.Create((int)_state, _phoneCall, _user, _emojis != null ? string.Join(" ", _emojis) : string.Empty); await _connection.SendMessageAsync(new ValueSet { { "caption", "voip.callInfo" }, { "request", TLSerializationService.Current.Serialize(data) } }); } }
public async void OnSignalBarsChanged(int count) { if (_connection != null) { VoIPCallTask.Log("Mediator initialized", "Informing foreground about signal bars"); var data = TLTuple.Create(count); await _connection.SendMessageAsync(new ValueSet { { "caption", "voip.signalBars" }, { "request", TLSerializationService.Current.Serialize(data) } }); } }
private void Close() { VoIPCallTask.Log("Releasing background task", "Releasing VoIPCallTask"); VoIPCallTask.Mediator.Initialize(null as AppServiceConnection); _current = null; _connection = null; _deferral?.Complete(); }
public void Initialize(BackgroundTaskDeferral deferral) { if (_connection == null & _protoService == null) { VoIPCallTask.Log("Mediator initialized", "Creating proto service"); var deviceInfoService = new DeviceInfoService(); var eventAggregator = new TelegramEventAggregator(); var cacheService = new InMemoryCacheService(eventAggregator); var updatesService = new UpdatesService(cacheService, eventAggregator); var transportService = new TransportService(); var connectionService = new ConnectionService(deviceInfoService); var statsService = new StatsService(); var protoService = new MTProtoService(deviceInfoService, updatesService, cacheService, transportService, connectionService, statsService); protoService.Initialized += (s, args) => { VoIPCallTask.Log("ProtoService initialized", "waiting for updates"); updatesService.LoadStateAndUpdate(() => { VoIPCallTask.Log("Difference processed", "Difference processed"); if (_phoneCall == null) { VoIPCallTask.Log("Difference processed", "No call found in difference"); if (_systemCall != null) { _systemCall.NotifyCallEnded(); } } }); }; eventAggregator.Subscribe(this); protoService.Initialize(); _protoService = protoService; _transportService = transportService; } else { VoIPCallTask.Log("Mediator initialized", "_connection is null: " + (_connection == null)); } _deferral = deferral; _initialized = true; ProcessUpdates(); }
private void OnCanceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason) { _mediator?.Dispose(); _mediator = null; _current = null; if (VoIPServiceTask.Connection != null) { var mediator = Mediator; } VoIPCallTask.Log("Releasing background task", "Releasing VoIPCallTask"); _deferral.Complete(); }
private async Task <MTProtoResponse <T> > SendRequestAsync <T>(string caption, TLObject request) { if (_protoService != null) { VoIPCallTask.Log("Sending request", "Via MTProtoService"); if (caption.Equals("voip.getUser")) { return(new MTProtoResponse <T>(InMemoryCacheService.Current.GetUser(((TLPeerUser)request).UserId))); } return(await _protoService.SendRequestAsync <T>(caption, request)); } else { VoIPCallTask.Log("Sending request", "Via AppServiceConnection"); if (_connection == null) { _connection = VoIPServiceTask.Connection; _connection.RequestReceived += OnRequestReceived; } var response = await _connection.SendMessageAsync(new ValueSet { { nameof(caption), caption }, { nameof(request), TLSerializationService.Current.Serialize(request) } }); if (response.Status == AppServiceResponseStatus.Success) { if (response.Message.ContainsKey("result")) { return(new MTProtoResponse <T>(TLSerializationService.Current.Deserialize(response.Message["result"] as string))); } else if (response.Message.ContainsKey("error")) { return(new MTProtoResponse <T>(TLSerializationService.Current.Deserialize <TLRPCError>(response.Message["error"] as string))); } } VoIPCallTask.Log("Request failed", "Via AppServiceConnection"); return(new MTProtoResponse <T>(new TLRPCError { ErrorMessage = "UNKNOWN", ErrorCode = (int)response.Status })); } }
public void Run(IBackgroundTaskInstance taskInstance) { try { _deferral = taskInstance.GetDeferral(); VoIPCallTask.Log("VoIPServiceTask started", "VoIPServiceTask started"); var details = taskInstance.TriggerDetails as AppServiceTriggerDetails; _connection = details.AppServiceConnection; _current = this; VoIPCallTask.Mediator.Initialize(details.AppServiceConnection); taskInstance.Canceled += (s, e) => Close(); details.AppServiceConnection.ServiceClosed += (s, e) => Close(); } catch (Exception e) { _deferral?.Complete(); } }
public VoIPCallMediator() { VoIPCallTask.Log("Mediator constructed", "Mediator constructed"); }
public VoIPCallMediator() { var user = new TLUser(); VoIPCallTask.Log("Mediator constructed", "Mediator constructed"); }